This is my snake for the AI competition Battlesnake and pretty successful. It reached rank 39 and in the Global Arena versus ~550 opponents on Saturday 2/19/2022.
Battlesnake is an autonomous survival game. Each Battlesnake is controlled autonomously by a live web server and moves independently attempting to find food, avoid other Battlesnakes, and stay alive as long as possible.
from Battlesnake docs
- Docker and docker-compose
- NodeJS and npm
-
Clone the repo
git clone https://github.com/noveb/battlesnake.git
-
Install development dependencies
Most things can be done in/with Docker but it is still useful to install the dependencies and needed for the git hooks.
npm install
-
Build Docker image for development
docker-compose build
-
Run the Docker container for development
docker-compose up
There are various options and docker-compose files to run this for different purposes:
-
TDD with live games
The default d-c file
docker-compose.yml
starts the server and restarts on file changes. Use this to make changes and verify in live games.docker-compose up [--build]
-
TDD with unit / integration tests
The d-c file
docker-compose.test.yml
does not start the server but runsjest --watch
for test driven development. Useful when writing algorithms and strategies.docker-compose --file docker-compose.test.yml up [--build]
-
Production & beta
The d-c file
docker-compose.production.yml
anddocker-compose.beta-test.yml
are almost equal but use different ports. The image and container are optimized for production (no dev dependencies & tools, proper tsc build, ...). Beta can be used to test updates and verify that they are better or experiment with new game modes without risk for the ranking of your main snake.docker-compose --file docker-compose.production.yml up [--build] docker-compose --file docker-compose.production.yml up [--build]
In the d-c stack is MongoDB and mongo-express included. The API will save every game and game step for later debugging. A game step can be replayed with Postman or curl. The database is not needed to play games.
Special thanks to Xueqiao (Joe) Xu and his PathFinding.js package. It is used to find shortest paths to food and other targets.