Skip to content

AIWC Development Guide Python P1

Chansol Hong edited this page Aug 7, 2019 · 2 revisions

Previous Page - Section 3 - Development Guide


Section 3 - Player Program Development Guide (Python)

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.

1) Communication Module

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 player programs and the player programs send the robot control signal to the simulator program that will apply the request to the robots in the simulator. To do this, a communication module using WAMP protocol is set and implemented. On player program’s side, the communication module is already implemented in the examples provided. Thus, the player program developers need not to know details of the communication module and start from the implementation of virtual methods in the skeleton sample program player_skeleton.py.

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 communication module is already implemented in the examples provided. Thus, the player program developers need not to know details of the communication module and start from the implementation of virtual methods in the skeleton sample programs player_skeleton.py, commentator_skeleton.py, and reporter_skeleton.py.

2) Virtual Methods

There are two 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.py, commentator_skeleton.py, and reporter_skeleton.py provide skeleton implementations of the virtual methods. The explanations provided below are based on the example skeleton programs.

2-1. Virtual Method ‘init_variables()’

The virtual method ‘init_variables()’ is called only once right after the communication module succeeds in connecting to the simulation program in the callback method ‘onJoin()’. 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 as class variables (i.e. ‘self.game_time’) to be accessible in other virtual method. This method should be used for initialization of variables only. The sample skeleton program initializes several variables such as ‘self.number_of_robots’ and ‘self.max_linear_velocity’ from the dictionary ‘info’ provided (Table 18 Dictionary ‘info’). You can check more variable initializations done in other examples such as general_frame-skip.py and general_image-fetch.py.

2-2. Virtual Callback Method ‘on_event()’

The virtual callback method ‘on_event()’ is called whenever the simulation program sends a new frame data to the player program. The new frame data is contained in the input dictionary ‘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.py or player_rulebased-B.py 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 ‘on_event()’ method consumes more than 50 ms, the successive calls of this method will be delayed. As a result, the frame data facing in each ‘on_event()’ 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.

Also, when the game is ended, the value for ‘f[‘reset_reason’]’ is set to ‘GAME_END’ (Table 19 Dictionary ‘f’). When ‘GAME_END’ is met, the program can save any data recorded throughout the game. The skeleton program simply makes an empty text file.


Next Page - Section 3 - Development Guide (Python) (2/3)