Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Battlesnake Python Flask Bot

A lightweight Battlesnake implementation built with Flask that follows the official rules: it respects board boundaries, searches for food when hungry, and pressures smaller opponents when safe to do so. The project is geared toward local development and testing so you can iterate on custom strategies quickly.

Features

  • Boundary awareness: get_safe_moves ensures that the snake never walks off the board or into occupied tiles.
  • Hunger management: When health drops, the scoring heuristics prioritize nearby food to stay alive.
  • Controlled aggression: The bot attacks shorter snakes by closing the distance when it has a size advantage and otherwise gives space to larger threats.
  • Flask API: Implements the standard Battlesnake routes (/, /start, /move, /end).

Running locally

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
export FLASK_APP=battlesnake.app
flask run --host 0.0.0.0 --port 8000

Alternatively, run the module directly:

python -m battlesnake.app

The snake is now ready to respond to the Battlesnake game server on http://localhost:8000.

Battlesnake API

  • GET / — returns metadata (apiversion, color, head, tail, etc.).
  • POST /start — receives the starting game state (logged for debugging).
  • POST /move — calculates the safest, most purposeful move and replies with a short shout rationale.
  • POST /end — receives the final game snapshot.

Testing

pytest

The test suite exercises key decision-making heuristics: boundary avoidance, food prioritization when health is low, and choosing to attack shorter snakes with a length advantage.

Development notes

  • Modify battlesnake/logic.py to experiment with new heuristics or to plug in more advanced search strategies.
  • Update the tests/ directory whenever you add logic so that the scoring system stays predictable.
  • Keep dependencies limited to Flask and pytest for fast iteration cycles.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages