Skip to content

OliverMKing/Battlesnake

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Battlesnake

Watch my snake in action (its name is Oliver King).

Video of snake

Info

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.

Basic Logic

  1. Create a Variables object with all the relevant information
  2. Populate a board with given information (size, your location, opposing snake locations, food)
  3. Populate the board with special symbols for bigger snake's possible moves
  4. Populate the board with special symbols for dead ends
  5. Determine move
    1. Decide if we need to eat
      1. Check if it is safe to eat
      2. Use A* to navigate to closest food
      3. Otherwise, chase our tail or move toward free space
    2. If we don't need to eat we chase our tail or move toward free space

Todo

  • 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

Running the Snake Locally

You will need...

  • a working Python 3.7 development environment
  • pip to install Python dependencies
  1. Fork this repo.

  2. Clone repo to your development environment:

git clone [email protected]:<your github username>/Battlesnake.git
  1. Install dependencies using pip:
pip install -r requirements.txt
  1. Run local server:
python app/main.py
  1. 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

Deploying to Heroku

  1. Create a new Heroku app:
heroku create [APP_NAME]
  1. Deploy code to Heroku servers:
git push heroku master
  1. Open Heroku app in browser:
heroku open

or visit http://APP_NAME.herokuapp.com.

  1. View server logs with the heroku logs command:
heroku logs --tail

About

My Battlesnake AI programmed in Python3.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.7%
  • Procfile 0.3%