What a bot is

A bot is a program that plays the game with a controller, as a person would, but reads the game's state instead of the screen.

The tick

The game steps its simulation sixty times a second. After each step, the framework (ibf) publishes a snapshot of everything on the board, and your bot answers with the buttons to hold until the next one.

the gametick 1200your boton_tick(state)0.8 of 16.7 ms
The game steps its simulation: ships move, shots fly.

In Python, a bot is a class with an on_tick method. It takes the State and returns an Action: where to move, and where to shoot. Holding a shoot direction across ticks charges the shot; the framework's self.input.tap(...) makes a quick one.

from ibf import Action, Bot, Dir, State, run


class MyBot(Bot):
    name = "mybot"

    def on_tick(self, state: State) -> Action:
        me = state.me                  # your ship, or None between rounds
        foe = state.nearest_enemy()
        if me is None or foe is None:
            return Action.idle()       # no buttons
        if foe.tile[0] > me.tile[0]:
            return Action(move=Dir.RIGHT)
        return Action(move=Dir.LEFT, shoot=Dir.UP)


if __name__ == "__main__":
    run(MyBot, pad=0)

What the state holds

Everything a player could see, as numbers: every ship with its position, colour, shots held and whether it is charging; the shots in flight; the pickups; and the board, tile by tile. A few of the fields:

state.tick                   # the game's step: 60 a second
state.me                     # your ship: pos, tile, color, alive, ammo, charging...
state.ships                  # every ship; state.nearest_enemy() the closest foe
state.projectiles            # shots in flight: pos, dir, owner
state.pickups                # pickups on the board
state.board.walkable(tile, me.color)     # can your ship step there?
state.board.clear_lane(me.tile, foe.tile)  # a straight shot between them, or None

Fair by design: lockstep

On this site every match runs in lockstep: each tick, the game waits for both bots to answer, for at most 17 milliseconds, before it steps. A fast computer gives no edge, and nothing a bot does can slow the game for the other.

tick 1tick 2tick 3tick 4tick 5tick 6tick 7tick 8bot Abot B
Each bar is a bot thinking about a tick. The game waits for both answers, at most 17 ms, then steps. Bot B took 31 ms on the fifth tick: that tick it played its fourth tick's buttons again, and from the sixth it was back. Being slow costs a slow bot ticks; it never slows the other bot down.

Each bot runs in a container of its own, with no network except to the game, and a fixed share of CPU and memory. It sees the same state at the same moment as its opponent: about four milliseconds after the game publishes it.

Next: write one, five small steps at a time.