Watch my snake in action (its name is Oliver King).
My Battlesnake AI is written in Python. It currently uses A* and other logic to determine the best path to gather food and follow its tail.
Visit https://github.com/battlesnakeio/community/blob/master/starter-snakes.md for API documentation and instructions for running the AI.
This AI client uses the bottle web framework to serve requests and the gunicorn web server for running bottle on Heroku. Dependencies are listed in requirements.txt.
- Create a Variables object with all the relevant information
- Populate a board with given information (size, your location, opposing snake locations, food)
- Populate the board with special symbols for bigger snake's possible moves
- Populate the board with special symbols for dead ends
- Determine move
- Decide if we need to eat
- Check if it is safe to eat
- Use A* to navigate to closest food
- Otherwise, chase our tail or move toward free space
- If we don't need to eat we chase our tail or move toward free space
- Decide if we need to eat
- Better predict path of larger snakes
- Avoid edges of the board / try to chase tail in free space
- Check if I am closer to food
- Factor if tail will be there in flood flow
- Zone off snakes
- Change snake tactic depending on amount of snakes left and how long the game has been going
- Keep track of wins/losses
- a working Python 3.7 development environment
- pip to install Python dependencies
-
Clone repo to your development environment:
git clone [email protected]:<your github username>/Battlesnake.git
- Install dependencies using pip:
pip install -r requirements.txt
- Run local server:
python app/main.py
- Test your snake by sending a curl to the running snake
curl -XPOST -H 'Content-Type: application/json' -d '{ "hello": "world"}' http://localhost:8080/start
- Create a new Heroku app:
heroku create [APP_NAME]
- Deploy code to Heroku servers:
git push heroku master
- Open Heroku app in browser:
heroku open
or visit http://APP_NAME.herokuapp.com.
- View server logs with the
heroku logs
command:
heroku logs --tail