Link to GitHub

Idea

The idea of this library is, to abstract the process of building a BattleSnake to its fundamental parts. Which is declaring functions that get called when a move is requested. But not just that, but also accessible game-data(enemies, coordinates) and a session-wide store(for storing data across different events).

Implementation

As a user, you can just build a new snake like this:

from battlesnake_builder import BattleSnake

my_snake = BattleSnake()

@my_snake.on_move
def move(_data, _store):
    return "up"

my_snake.run()

While behind the scenes, the library just assigns the move function to the on_move callback, which is called when the route /move is accessed. The BattleSnake object also passes two parameters into the callback, which are data and store. The data is just the data that the client sent, parsed into python-objects. The store is just a dictionary, in which you can store whatever you want, across different events in the same session. With the my_snake.run() the lib starts a Flask-server.

Related