Understanding game logic

The game logic is code running on the backend that dictates how the game will run. Understanding the game logic is not strictly necessary for building bots, but it can be helpful for users who want to understand the nuances of how the game works when it is not adequetly described in the game description.

Game logic consists of these components

  • game initialization

  • what happens when an action is performed?

  • when does the game end and who is the winner?

Game initialization

The init_game(game_settings) method is called at the beginning of a game and returns a newly initialized game state. It determines who makes the first move, by specifying the player_turn_idx. Some games support different settings, such as board size or player count, and the initialization can take those settings into account.

Performing the action

Bots return an action object on their turns. The action object is the input for these game logic methods. Given the current game state, the game logic calculates what the new game state is when the action is performed.

Games with multiple actions need to implement a method for each action.

Example

Tictactoe has a single action: placing a piece at some index. The Tic-Tac-Toe game logic has a method place_piece(state, index) that returns a new state after the piece has been places in that index.

Determining the winner

After each action, the game logic checks if the game has finished given the new game state. For multi-player games, the supported game results are

  • Someone has won

  • Game ended with a draw

  • Game is on-going

Single player game results also include things like the score of the game.

Last updated