-
Notifications
You must be signed in to change notification settings - Fork 0
AIWC Development Guide Cpp P1
Previous Page - Section 3 - Development Guide
In AI World Cup, the data provided by the simulation program are pre-modified in a way that you do not need to consider whether you are Team A or Team B. All coordinates and images are rotated by π and the robot marker colors are swapped to make your team Red and located on the left side of the field. You can always assume that your team is Red and located on the left side whether you are Team A or Team B, or whether it is first half or second half. In case of AI Commentator and AI Reporter, the data sent are identical to the data sent to Team A.
In AI World Cup simulation, the program simulating the AI Soccer game and applying rules is separated from participant programs. The simulator program sends the game information such as game status, scores, coordinates to the participant programs. The AI Soccer programs send the robot control signal to the simulator program that will apply the request to the robots in the simulator. The AI Commentator program sends the generated commentaries to the simulator program that will display the comments on screen. The AI Reporter program submits the generated report to the simulator program that will save the report as a text file. To do this, a communication module using WAMP protocol is set and implemented. On the participant program’s side, the ‘examples/common/ai_base’ scripts are the implementation of the communication module and used throughout all the examples provided. Thus, the participant program developers need not to know details of the communication module and start from the implementation of virtual methods called by the module throughout a game. As you can see in any of CmakeList.txt file stored in C++ example directories, the example programs follow C++14 standard. The communication module may not work in other standards that if you wish to use another standard, you may need to revise the communication module.
There are three virtual methods that are called throughout a game. The developer should implement these methods to make a participant program that manages a team in case of AI Soccer, generates a comment in case of AI Commentator, and submits a report in case of AI Reporter. player_skeleton.cpp, commentator_skeleton.cpp, and reporter_skeleton.cpp provide skeleton implementations of the virtual methods. The explanations provided below are based on the example skeleton programs.
2-1. Virtual Method ‘init()’
The virtual method ‘init()’ is called only once right after the communication module succeeds in connecting to the simulation program. Here, the program can initialize some parameters, load necessary data from other files, etc. Note that you need to define variables outside of this method to be accessible in other virtual methods. This method should be used for initialization of variables only. Since the skeleton program has nothing to initialize, this method is empty in player_skeleton.cpp, commentator_skeleton.cpp, and reporter_skeleton.cpp. You can check how variable initializations are done in other examples such as general_frame-skip.cpp and general_image-fetch.cpp.
2-2. Virtual Method ‘update()’
The virtual method ‘update()’ is called whenever the simulation program sends a new frame data to the participant program. The new frame data is contained in the input data structure ‘f’ of this method. The contents of the frame data will be explained later in 3) Data Provided by the Simulation Program. Here, the program can check the new frame data received, decide what control signal to generate, and send the control signal back to the simulator.
AI Soccer: The method to send the robot control signal will be explained later in 4) Robot Control Signal. The skeleton program simply makes all robots move forward at the maximum velocity available. For more complex controls, you can check player_rulebased-A.cpp or player_rulebased-B.cpp examples to see how the robots can be controlled.
AI Commentator: The method to send the comments will be explained later in 5) Commentate. The skeleton program makes comments on simple situations such as game begin/end and goals.
AI Reporter: The method to send the report will be explained later in 6) Report. The skeleton program makes a simple report summarizing the scores at the end.
Since the control period is set to 50 ms in AI World Cup, the simulation program will send a new data in each 50 ms as well and thus this method is called in every 50 ms. However, if your ‘update()’ method consumes more than 50 ms, the successive calls of this method will be delayed. As a result, the frame data facing in each ‘update()’ call will not be the most recent frame that your program may end up providing delayed control signals to the simulator. To avoid this, you should implement a frame-skipping technique such as the one provided in general_frame-skip.cpp in case when your program consumes more than 50 ms in handling each frame.
2-3. Virtual Method ‘finish()’
The virtual method ‘finish()’ is called only once after the game is over before the participant program ends. Here, the program can save any data recorded throughout the game. The skeleton program simply makes a text file with a dummy content.