Skip to content

How to use AI World Cup simulation program

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

AI World Cup simulation runs on Webots Robot Simulator in Linux operating system (tested with Ubuntu 16.04). Below explains how to use AI World Cup simulation world for AI development.

0. (Python users only) Install required packages

  • In C++ programs, the required libraries are packaged in our repository that C++ users can skip this section.

Two Python packages are required for running Python scripts in examples directory.

  1. autobahn (tested with 19.8.1)
  2. msgpack-python (tested with 0.5.6) - If "ImportError: cannot import name MsgPackSerializer" happens even with msgpack-python installed, install u-msgpack-python instead (tested with 2.5.1)
  3. twisted (tested with 19.7.0)

1. Install Webots Robot Simulator

Please refer to Webots official website's installation procedure. AI World Cup 2019 uses Webots R2019b.

  • By default configuration, Webots simulator is set to run the simulation as soon as the world is loaded. Since the configuration file ('config.json') is only read at the beginning of the simulation, it is advised to set the default start mode as 'Pause'. Go to Tools->Preferences->General and set 'Startup mode' to 'Pause'.

2. Run AI World Cup simulation in Webots

Open 'aiwc.wbt' in 'worlds' directory of AI World Cup simulation. When you 'run' (Ctrl + 2) the simulation, the Referee program begins a game by calling two AI Soccer sample programs as the team AIs.

  • In the release versions, prebuilt binaries for simulation are provided by default. If the prebuilt binaries do not work, please open the Webots text editor (Ctrl + E), open each source code for binaries ('controllers/soccer_robot/soccer_robot.cpp', 'controllers/supervisor/supervisor.cpp', and 'plugins/physics/collision_detector/collision_detector.cpp'), and build each binary by pressing Build (F7).
  • For a faster simulation, you can lower the quality of the main view. Go to Tools->Preferences->OpenGL and set 'Main 3D view anti-aliasing' to 'off' and check 'Disable shadows' and 'Disable shaders' boxes.

3. Modify configuration file 'config.json'

'config.json' file in the root directory of 'test_world' simulation sets some game options and set players. "executable" and "datapath" paths are the relative paths from the root directory of 'test_world' simulation.

Fields in "rule" specify the game options (in the official matches, default values will be used):

  1. "game_time": the game duration in seconds (default: 300).
  2. "deadlock": if set to false, 'Deadlock' rules in Game Rules are ignored (default: true).

Fields in "team_a" and "team_b" specify the AI Soccer players' information:

  1. "name": the team's name
  2. "executable": the team AI executable path (this must be specified correctly on both teams to run the simulation)
  3. "datapath": the path where AI can output some files

Fields in "commentator" specify the AI Commentator program's information:

  1. "name": the team's name
  2. "executable": the team AI executable path (this must be specified correctly on both teams to run the simulation)
  3. "datapath": the path where AI can output some files

Fields in "reporter" specify the AI Reporter program's information:

  1. "name": the team's name
  2. "executable": the team AI executable path (this must be specified correctly on both teams to run the simulation)
  3. "datapath": the path where AI can output some files

Fields in "tool" specify the extra settings:

  1. "repeat": if set to true, the same game with same opponent is repeated after a game ends. When set to true, 'EPISODE_END' is sent instead of 'GAME_END' as the 'reset_reason' (default: false).
  2. "record": if set to true, the game is recorded and saved at "record_path" when the game ends. This setting cannot be used with "repeat" option. If "repeat" is set to true, "record" will internally be forced to be false (default: false). After the game is finished, recording takes several minutes to save the video. You need to wait until 'INFO: Video creation finished.' is shown in the Webots Console (Ctrl + L).
  3. "record_path": the path in the PC where the recorded video will be stored (default: ""). This is the path where the video is to be saved and not the filename of the video. The filename of the video is automatically set as '[{timestamp}]{team_a_name}_{team_b_name}.mp4'. With the default empty string, the simulator will attempt to save the video in the root directory '/'. You must specify an adequate path for the video to be stored.

4. (Optional) Setting the simulation system and the learning system separately in two computers

If you wish to run the WCG AI Masters simulation in one computer and the player program in another computer, you can download the relay scripts and follow the steps below.

  1. Install Python required packages

  2. Download simulator_relay.py to a computer where the Webots simulator will run and player_relay.py to another computer where the player program will run.

  3. In config.json, change the path of one team's executable to simulator_relay.py.

  4. In simulator_relay.py, modify 'simulator_ip' to the IP of the computer where Webots will run and 'player_ip' to the IP of the computer where the player program will run.

  5. In player_relay.py, modify the 'executable' path to the player program and the 'datapath' to where your custom data written to 'datapath' in the player program will be saved.

  6. Execute player_relay.py

  7. Launch Webots and run the simulation.