Skip to content

Understanding the game state

Though you are completely free to implement your bot's logic as you see fit, the provided scaffolds come with a basic structure for the game loop.

In pseudocode, the game loop looks like:

  1. Get fresh state from the game
  2. Decide on and perform actions based on the current game state
  3. Loop every X milliseconds

In code, it looks like:

python
@controller.on_loop
async def game_loop(controller: Controller):
    while True:
        # 1. Get fresh state from the game
        state = await controller.get_fresh_state()

        # 2. Decide on and perform actions based on the current game state
        # ...

        # 3. Loop every X milliseconds
        await asyncio.sleep(X / 1000)
java
private static void gameLoop(@NotNull Controller controller) {
    while (true) {
        // 1. Get fresh state from the game
        SimplifiedGame state = controller.getFreshState();

        // 2. Decide on and perform actions based on the current game state
        // ...

        // 3. Loop every X milliseconds
        Thread.sleep(GAME_LOOP_INTERVAL_MS);
    }
}

The game state is a snapshot of players, allies, neighbors, ongoing attacks, and more, at a given moment in the game. For a complete reference of what information the game state contains, see the SimplifiedGame reference.

The most basic things to look for in the game state are probably:

  • state.me.neighbors: other players who share a border with you

    A player is your neighbor if two of your respective tiles are adjacent (i.e. share a border). You can only attack your neighbors.

    Note that empty land is also considered a neighbor and will appear as None/null in the neighbors list.

  • state.me.idleTroops, state.me.maxTroops, state.me.attackingTroops: respectively the number of troops you have that are not currently attacking, the maximum number of troops you can have, and the number of troops you currently have that are attacking and thus not available right away for new attacks.

    This corresponds to the numbers you can see in the game interface as a human:

There are plenty of other information in the game state that you can use to make decisions.

You have access, for example, to the same state information about other players (neighbors, troop counts, allies, etc.) that you have about yourself.

Have a look at the SimplifiedGame reference and the SimplifiedPlayer reference to see all the information you can use to make decisions for your bot.

Next, we will use this state for some simple decision making and make our bot perform some actions in the game.