daniel156161 51de53d01c
Build and Push Docker Container / build-and-push (push) Failing after 12m18s
add dataset updates with doc updates
2026-04-03 11:40:47 +02:00
2026-04-03 10:29:48 +02:00
2025-05-15 09:56:01 +02:00
2026-04-03 11:40:47 +02:00
2022-01-24 15:30:05 +01:00
2026-04-03 11:40:47 +02:00
2026-01-06 13:36:06 +01:00

Battlesnake Python Starter Project

An official Battlesnake template written in Python. Get started at play.battlesnake.com.

Battlesnake Logo

This project is a great starting point for anyone wanting to program their first Battlesnake in Python. It can be run locally or easily deployed to a cloud provider of your choosing. See the Battlesnake API Docs for more detail.

Technologies Used

This project uses Python 3 and Flask. It also comes with an optional Dockerfile to help with deployment.

Run Your Battlesnake

Install dependencies using pip

pip install -r requirements.txt

Start your Battlesnake

python main.py

You should see the following output once it is running

Running your Battlesnake at http://0.0.0.0:8000
 * Serving Flask app 'My Battlesnake'
 * Debug mode: off

Open localhost:8000 in your browser and you should see

{"apiversion":"1","author":"","color":"#888888","head":"default","tail":"default"}

Play a Game Locally

Install the Battlesnake CLI

Command to run a local game

battlesnake play -W 11 -H 11 --name 'Python Starter Project' --url http://localhost:8000 -g solo --browser

Next Steps

Continue with the Battlesnake Quickstart Guide to customize and improve your Battlesnake's behavior.

Included Competitive Snake

This repo now includes snakes/BestBattleSnake.py, a stronger default snake that combines:

  • collision and head-to-head risk checks
  • flood-fill space evaluation to avoid traps
  • food routing that gets more aggressive as health drops
  • tail access checks for better long-term survival

Run it explicitly with:

SNAKE=BestBattleSnake python main.py

Optional duel tuning (when only 2 snakes are alive):

BATTLE_SNAKE_DUEL_STYLE=balanced python main.py

Allowed values: safe, balanced, aggressive.

Export Training Dataset

Game saves now include a dataset section with labeled move samples.

Export all stored samples to JSONL:

python -m server.DatasetExporter --input data --output data/dataset/good_moves.jsonl

Or with just:

just export-dataset

To store compact dataset-only records (JSONL) and skip full per-game JSON files:

STORE_DATASET_ONLY=true DATASET_JSONL_PATH=data/dataset/good_moves.jsonl python main.py

Optional compact storage tuning:

  • DATASET_ROTATE_DAILY=true creates one JSONL file per day (default: true)
  • DATASET_JSONL_MAX_MB=50 rotates when file reaches max size in MB (default: 50)
  • DATASET_COMPRESS_ROTATED=true gzip-compresses rotated/old JSONL files (default: true)

Note: To play games on play.battlesnake.com you'll need to deploy your Battlesnake to a live web server OR use a port forwarding tool like ngrok to access your server locally.

S
Description
Languages
Python 87%
JavaScript 7.7%
CSS 2.4%
HTML 1.4%
Just 1.2%
Other 0.3%