Script for dispatching information between a gameengine and players, via stdin and stdout
The command line should be :
python3 GameDispatcher.py config.cfg
config.cfg is a config file containing on the first line the command for game engine execution, then on each other lines, the command for player AI execution.
Example, in bombernman.cfg :
python3 BombermanGE.py
python3 BombermanPlayer.py
python3 BombermanPlayer.py
python3 BombermanPlayer.py
python3 BombermanPlayer.py
It mean that we use python3 BombermanGE.py
as game engine, then 4 instances of python3 BombermanPlayer.py
as players AI.
Communication between game engine and AI is done using standard input and output.
Messages have always the same structure :
- they start with a line
START
<label>
- they contain as many lines as necessary
- they end with a line
STOP
<label>
<label>
represents the label/type of message to send.
A game has always the same flow of messages :
At start :
- dispatcher send the number of players to the game engine
- dispatcher send to each AI its player number (starting at 1)
- game engine send its settings to dispatcher
- dispatcher send the settings to each AI
Then, until the end, at each turn (numbered starting at 1), and for each AI :
- game engine send the game states infos for the AI to the dispacher
- dispatcher send the game states infos to the AI
- AI send its instructions to the dispatcher
- dispatcher send the instructions to the game engine
From the game engine's point of view, communication is :
- read a message
<players>
containing the number of players - send a message
<settings>
containing all the information for the comprehension of the game - for each turn, for each player, until the end of the game :
- send a message <turn #turn #player>
- read a message <action #turn #player>
From the AI's point of view, communication is :
- read a message
<player>
containing the id of the player - read a message
<settings>
containing all the information for the comprehension of the game - for each turn, until the end of the game :
- read a message
- send a message