I strongly recommend reading the docs in https://fdocr.github.io/CrystalSnake/. You'll find detailed information on classes and methods there :)
I wrote a few blog posts about this project. Check out the first one here.
You'll need Crystal, Postgres & Redis locally. The app uses sam.cr for ease of development.
# Install dependencies shards install # Create DB & run migrations make sam db:setup # Start development server in port 8080 with live reload make sam dev # Run tests make sam test
The app can be configured copying the
.env.sample file as
.env in the directory root.
For local development I use the BattleSnake CLI with the local server running. A basic example looks like this:
# Solo game with ChaseClosestFood strategy battlesnake play -W 11 -H 11 --name dev --url http://localhost:8080/chase_closest_food -g solo -v # Play RandomValid vs CautiousCarol strategies battlesnake play -W 11 -H 11 --name RandomValid --url http://localhost:8080/random_valid --name CautiousCarol --url http://localhost:8080/cautious_carol -v
The server is built on the
src/app.cr file and you can choose to use any of the available strategies.
To start hacking a new one create a new strategy (in the
src/strategy folder) that inherits from
Stategy::Base. They're all initialized with a
BattleSnake::Context and the server calls the
#move method on it to respond with. You can re-use strategies within each other, i.e.
Strategy::ChaseClosestFood uses the
Strategy::RandomValid strategy when it can't reach any food on the board.
In order to start using a new strategy:
- Add new entry in case clause to
- Must return the new strategy object
- The string in the case clause will determine its path
I'm currently using DigitalOcean App Platform. The Dockerfile is detected and deployed on their cheapest tier. It "should work" in lots of other platforms with this setup, but open an issue if you need help troubleshooting or to discuss other solutions.
ENV variables are used to customize your snake
Make sure to test your changes. First copy
.env.test so you can run the test suite with
make sam test.
- Fork it (https://github.com/fdocr/CrystalSnake/fork)
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request
- Fernando Valverde - creator and maintainer