Skip to content

AIWC Development Guide Cpp P2

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

Previous Page - Section 3 - Development Guide (C++) (1/3)


Section 3 - Player Program Development Guide (C++)

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.

3) Data Provided by the Simulation Program

In AI World Cup, two different data structures are sent from the simulation program to provide information of the game. These two data structures are defined in common/ai_base.hpp. You can check general_check-variables.cpp and general_image-fetch.cpp to see how these data are accessible in the player program.

3-1. Basic Information Data Structure ‘game_info’

The first structure is ‘game_info’ structure that contains basic information about the game. The information held in this structure are the values that don’t change throughout the game such as field dimensions and robot specifications. This structure is accessible through variable ‘info’ by the player program from when the virtual method ‘init()’ is called (i.e. ‘info.game_time’ contains the game duration). Note that the information contained in this structure will be identical to those shown in Section 1 – SPECIFICATIONS in this document.

Information Stored in Data Structure 'game_info'
Member Variable Data Type Description
field std::array<double, 2> Soccer field dimensions [x, y] in m
goal std::array<double, 2> Goal dimensions [x, y] in m
penalty_area std::array<double, 2> Penalty area dimensions [x, y] in m
goal_area std::array<double, 2> Goal area dimensions [x, y] in m
※ Note that none of rules is rulated to this region.
ball_radius double Soccer ball radius in m
ball_mass double Soccer ball mass in kg
robot_size std::array<double, 5> Robot sizes of [GK, D1, D2, F1, F2] in m
robot_height std::array<double, 5> Robot heights of [GK, D1, D2, F1, F2] in m
axle_length std::array<double, 5> Axle lengths of [GK, D1, D2, F1, F2] in m
robot_body_mass std::array<double, 5> Robot body masses of [GK, D1, D2, F1, F2] in kg
wheel_radius std::array<double, 5> Wheel radii of [GK, D1, D2, F1, F2] in m
wheel_mass std::array<double, 5> Wheel masses of [GK, D1, D2, F1, F2] in kg
max_linear_velocity std::array<double, 5> Maximum linear velocity available on each wheel of [GK, D1, D2, F1, F2] in m/s
max_torque std::array<double, 5> Maximum torque available on each wheel of [GK, D1, D2, F1, F2] in N*m
resolution std::array<std::size_t, 2> Image size [width, height] in pixel dimensions
number_of_robots std::size_t Number of robots
codewords std::vector<std::size_t, 5> The hamming codes in decimal values attached as the robot identifier in the image sent to the players. The order is [GK, D1, D2, F1, F2].
※ Details are explained in 3-3. Image Data.
game_time double Game duration in s

3-2. Frame Data Structure ‘frame’

The second structure is ‘frame’ structure that contains each game frame’s information. The information held in this structure are the values that change throughout the game such as the robot and ball coordinates. Therefore, new ‘frame’ is introduced as the input data structure whenever ‘update()’ is called (i.e. f.opt_coordinates->robots[0][0].x contains your team’s GK robot’s x-position).

Information Stored in Data Structure 'frame'
Member Variable Data Type Description
time double Current game time in s
score std::array<std::size_t, 2> Current scores of [your team, opponent's team]
reset_reason std::size_t (enumeration) Reason for the game pause before current frame
The value can be one of following enumerations:
0. NONE – No pause happened.
1. GAME_START – Game just began and the game is going into a kick-off.
2. SCORE_MYTEAM – Your team scored and the game is going into a kick-off.
3. SCORE_OPPONENT – Opponent’s team scored and the game is going into a kick-off.
4. GAME_END – Game just ended.
5. DEADLOCK – A ball relocation happened.
6. GOALKICK – Game is going into a goal kick.
7. CORNERKICK – Game is going into a corner kick.
8. PENALTYKICK – Game is going into a penalty kick.
9. HALFTIME – Second half just began and game is going into a kick-off.
10. EPISODE_END – Game just ended (replaces GAME_END when ‘repeat’ is true).
※ About ‘repeat’, please refer to the online system documentation.
game_state std::size_t (enumeration) Current game state
The value can be one of following enumerations:
0. STATE_DEFAULT – Default state
1. STATE_KICKOFF – Kick-off state
2. STATE_GOALKICK – Goal kick state
3. STATE_CORNERKICK – Corner kick state
4. STATE_PENALTYKICK – Penalty kick state
ball_ownership bool Indicator for whether your team owns the ball (true) or not (false) in special states such as kick-off, corner kick, penalty kick, and goal kick
※ This value does not mean anything in default state.
half_passed bool Indicator for whether the game is currently in first half (false) or in second half (true).
subimages std::vector<subimage> Image fragments need to be merged with previous image frame to obtain the new frame.
※ Details are explained in 3-3. Image Data.
opt-coordinates boost::optional<coordinates>
coordinates is a nested structure
Current robots and ball states
※ Although it says optional, coordinates will always be provided in this competition.
※ Details are explained in Table Information Stored in Data Structure ‘coordinates’
Information Stored in Data Structure 'coordinates'
Member Variable Data Type Description
robots std::array<std::vector<robot_coordinate, 5>, 2> Array containing robot coordinate nested structures for [your team, opponent’s team]
ball struct ball_coordinate Nested structure
Information Stored in Data Structure 'robot_coordinate'
Member Variable Data Type Description
x double x-position of the robot in m
y double y-position of the robot in m
th double Orientation of the robot in rad
※ The value is not necessarily in range [-π, π]. Check the actual value and convert it to the range you wish to use.
active bool Indicator for whether the robot can currently move or not. Some robots cannot move in special states such as kick-off, corner kick, penalty kick, and goal kick. Also, a robot cannot move when it is sent out from the field.
touch bool Indicator for whether the robot touched the soccer ball within last time frame. This value is provided since it is hard to find whether the ball and the robot are in contact through coordinates or image.
Information Stored in Data Structure 'ball_coordinate'
Member Variable Data Type Description
x double x-position of the soccer ball in m
y double y-position of the soccer ball in m

3-3. Image Data

In AI World Cup, the images sent to the players are not the raw images but a modified image containing same field status. The image size is 640 x 480.


AI World Cup with Player Views Shown

In the figure above, the modified images sent to the player programs are shown with a game frame. The green field is replaced with a black field, the soccer ball is replaced with an orange ball, and the robot role markers are replaced with special markers. The image on upper-left corner is sent to Team A and the image on upper-right corner is sent to Team B. Note that Team B’s image is rotated by π and the team colors are swapped.

Your Team Opponent's Team
Team Marker
GK D1 D2 F1 F2
Role Marker
Hamming Code 000000000 000011111 011100011 101101100 110110101
Decimal Value 0 31 227 364 437


Marker Construction

As can be seen in the table above, the player view marker is an additive color mixture of a red-colored or blue-colored team marker and a green-colored role marker. Thus, by putting a mask on each of RGB channels, the player view marker can be separated back to a team marker and a role marker.

From the ∏–shaped team marker, you can determine whether the robot is your robot (red) or opponent’s robot (blue). Also, you can determine the robot’s position and orientation by how the shape is positioned and oriented in the frame image.

From the green-colored role marker, you can identify which robot it is. 9-bit Hamming code schema was used to generate the five distinguishable patterns. For example, the binary Hamming code for F2 robot is ‘110110101’. The square role marker is sliced into 9 small squares. From the highest bit to the lowest bit, the bits are assigned to the small squares located on upper row’s left to right, middle row’s left to right, and lower row’s left to right. Each small square is colored green if the corresponding bit is 1 and colored black if the corresponding bit is 0.

In AI World Cup, image frames are sent in fragments in order to save the communication bandwidth. To use images, please check ‘update()’ implementation in general_image-fetch.cpp example to adopt the recombination method.


Next Page - Section 3 - Development Guide (C++) (3/3)