GPN19:C++ / Snake Programming Workshop: Unterschied zwischen den Versionen

aus dem Wiki des Entropia e.V., CCC Karlsruhe
(Die Seite wurde neu angelegt: „Ein Vortrag von Timon Stampfli auf der GPN19. C++ / Snake Programming Workshop There will be 2 parts. In the first part we will talk about the C++ specif…“)
 
Keine Bearbeitungszusammenfassung
 
Zeile 12: Zeile 12:


This is not a introduction into programming but learning to use C++ for writing snake bots for creatures already familiar with another programming language.
This is not a introduction into programming but learning to use C++ for writing snake bots for creatures already familiar with another programming language.
== Workshop Pad Content ==
http://pads.ccc.de/cpp-snake
Copy of pad content:
<pre>
CPP-Snake
// server: https://schlangen.bytewerk.org/
#include <bits/stdc++.h>
using namespace std;
void log(string str, Api* api){
    api->log(str.c_str());
}
bool step(Api* api) {
    api->log(string("Hello C-String World"));
    string str="Debug Value1: ";
    str+= 3 + ", some more text";
    log(string("some string") + 5.1);
    log(string()+3);
}
ich mache das:
string logtxt = "bla" + to_string(irgendeine integer variable);
api->log(logtxt.c_str());
int main(){
    vector<int> vec(10,20);
   
    vec.push_back(200);
}
/* C-Arrays: Legacy DO NOT USE */
int main(){
  int some_array[23] = {5,2,3};
    some_array[103];
    *(some_array + 3)
    return 0;
}
void caller(){
    int a = 23;
    call_by_value(a);
    call_by_adress(&a);
    // a is now 24
    call_by_reference(a);
    // a is now 25
}
void call_by_value(int a){
    a++;
   
    }
void call_by_adress(int * a){
    (*a)++;
   
    }
void call_by_reference(int& a){
    a++;
    }
api.functions_name();
(*api).funktions_name();
api->funktions_name();
ist das da in Ordnung?
Ich habe so meine Probleme mit Pointer, vectoren in funktionen...
void add(vector<int> *clc, int pos, int add)
{
    (*clc)[pos] += add;
}
https://schlangen.bytewerk.org/static/docs/doxygen_cpp/html/bot__api_8h_source.html
https://schlangen.bytewerk.org/static/docs/doxygen_cpp/html/ipc__format_8h_source.html
https://de.cppreference.com/w/cpp/container/set
https://de.cppreference.com/w/cpp/container/map
</pre>


{{Navigationsleiste GPN19}}
{{Navigationsleiste GPN19}}

Aktuelle Version vom 14. Juni 2019, 22:13 Uhr

Ein Vortrag von Timon Stampfli auf der GPN19.

C++ / Snake Programming Workshop

There will be 2 parts. In the first part we will talk about the C++ specifics that are useful for writing a snake game bot. Things like - Strings (C-Strings and C++ STL Strings) aka how do I log something - STL Datastructures aka how do I resize my array - Whatever you want to know about C++

In the second part we can discuss some snake bot strategies or algorithms. Your participation, questions is the basis for this part

This is not a introduction into programming but learning to use C++ for writing snake bots for creatures already familiar with another programming language.


Workshop Pad Content

http://pads.ccc.de/cpp-snake

Copy of pad content:

CPP-Snake

// server: https://schlangen.bytewerk.org/

#include <bits/stdc++.h>
using namespace std;

void log(string str, Api* api){
    api->log(str.c_str());
}

bool step(Api* api) {
    api->log(string("Hello C-String World"));
    string str="Debug Value1: ";
    str+= 3 + ", some more text";
    log(string("some string") + 5.1);
    log(string()+3);
}

ich mache das:
string logtxt = "bla" + to_string(irgendeine integer variable);
api->log(logtxt.c_str());


int main(){
    vector<int> vec(10,20);
    
    vec.push_back(200);
}





/* C-Arrays: Legacy DO NOT USE */
int main(){
   int some_array[23] = {5,2,3}; 
    some_array[103];
    *(some_array + 3)
    return 0;
}

void caller(){
    int a = 23;
    call_by_value(a);
    call_by_adress(&a);
    // a is now 24
    call_by_reference(a);
    // a is now 25
}

void call_by_value(int a){
    a++;
    
    }


void call_by_adress(int * a){
    (*a)++;
    
    }


void call_by_reference(int& a){
    a++;
    }





api.functions_name();
(*api).funktions_name();
api->funktions_name();








ist das da in Ordnung?
Ich habe so meine Probleme mit Pointer, vectoren in funktionen...

 void add(vector<int> *clc, int pos, int add)
{
    (*clc)[pos] += add;
}


https://schlangen.bytewerk.org/static/docs/doxygen_cpp/html/bot__api_8h_source.html
https://schlangen.bytewerk.org/static/docs/doxygen_cpp/html/ipc__format_8h_source.html


https://de.cppreference.com/w/cpp/container/set
https://de.cppreference.com/w/cpp/container/map