Get action: game state

On the bot's turn, it receives a game state, which contains all the information the bot needs to understand the state of the game in order to determine the action to take. We use protocol bufferarrow-up-right to document the game state schema.

Whose turn is it?

Each game has a list of participating bots [player0, player1, ..., playerN]. Which bot should make the next move is based on player_turn_idx. When player_turn_idx = 0, then the first player bot will calculate and submit its move, which is all handled automatically by the server. All game states on Botpot will contain a player_turn_idx that the bot can use to deduce which player it is playing.

Examples

The bot needs to know the values of the 9 squares, and whether the bot is playing circles or crosses. If state.player_turn_idx is 0, then the bot is playing circles. Otherwise, it is playing crosses. The protocol buffer schema for the Tic-Tac-Toe game state looks like

message State {
  // Required field to indicate the player who should be making the next move
  // Values = 0 or 1
  int32 player_turn_idx = 1;

  /*
  Array of size 9 initialized to -1, representing an empty 3 by 3 board.
  The values of board can be -1, 0, or 1. 
  Placing a piece in index x will set the value of board[x] to the player's index.
  Array is row major order: index 0 is top left, index 2 is top right, index 6 is 
  bottom left, and index 8 is bottom right.
  */
  repeated int32 board = 2;
}

The Tic-Tac-Toe bot below illustrates how one can use these fields to compute the next action.

In Reversi, the bot needs to know the values of the 64 squares. We can use a similar schema as Tic-Tac-Toe. To make it easier to code the bot, we also pre-computed a list of all the valid moves that a bot can make. The bot can select from one of the valid moves to return as its action.

Different game perspectives

Fig. 1: different bots see a different view of the game.

Some games such as Chess, Tic-Tac-Toe, and Checkers are perfect information, where there is no hidden information so all the bots know everything about the game. On the other hand, Texas Hold'em is an example of an imperfect information game. As shown in Fig. 1, our server stores a game state from the global perspective with no hidden information. This global game state is used to derive what each bot is supposed to see. Bot 1 is only sent its cards, which is a pair of K's. Similarly, Bot 2 is sent its pair of 3's. Both bots can also see the shared cards in the middle.

When a bot makes an action, the server can compute the new global game state and the bots' perspective game states.

Examples

Last updated