This is the CHISEL group's engineered snake for the BattleSnake programming competition. We chose to write it in Go.
The game server API documentation can be found at https://stembolthq.github.io/battle_snake/.
Omar Elazhary
Meagan Russell
Alexey Zagalsky
-
Clone repo to your development environment:
git clone [email protected]:USERNAME/battlesnake-go.git $GOPATH/github.com/USERNAME/battlesnake-go
cd $GOPATH/github.com/USERNAME/battlesnake-go
- Compile the battlesnake-go server.
go build
This will create a battlesnake-go
executable.
- Run the server.
./battlesnake-go
- Test the client in your browser: http://127.0.0.1:9000. I recommend using Insomnia or Postman for testing.
Example start game request:
{
"width": 20,
"height": 20,
"game_id": "b1dadee8-a112-4e0e-afa2-2845cd1f21aa"
}
:ok
Example move request:
{
"you": "2c4d4d70-8cca-48e0-ac9d-03ecafca0c98",
"width": 2,
"turn": 0,
"snakes": [
{
"taunt": "git gud",
"name": "my-snake",
"id": "2c4d4d70-8cca-48e0-ac9d-03ecafca0c98",
"health_points": 93,
"coords": [
[
0,
0
],
[
0,
0
],
[
0,
0
]
]
},
{
"taunt": "gotta go fast",
"name": "other-snake",
"id": "c35dcf26-7f48-492c-b7b5-94ae78fbc713",
"health_points": 50,
"coords": [
[
1,
0
],
[
1,
0
],
[
1,
0
]
]
}
],
"height": 2,
"game_id": "a2facef2-b031-44ba-a36c-0859c389ef96",
"food": [
[
1,
1
]
],
"dead_snakes": [
{
"taunt": "gotta go fast",
"name": "other-snake",
"id": "83fdf2b9-c8d0-44f4-acb2-0c506139079e",
"health_points": 50,
"coords": [
[
5,
0
],
[
5,
0
],
[
5,
0
]
]
}
]
}
:ok
- Create a new Go Heroku app using Go buildpack.
heroku create [APP_NAME]
- Add a buildpack for Go.
heroku buildpacks:set heroku/go
- Push code to Heroku servers. Make sure you have a
vendor/vendor.json
, otherwise Heroku will fail building.
git push heroku master
- Open Heroku app in browser.
heroku open
Or go directly via http://APP_NAME.herokuapp.com
- View/stream server logs.
heroku logs --tail
-
Install Docker. For Ubuntu follow the instructions described here: https://docs.docker.com/engine/installation/linux/ubuntu/#install-docker/
-
Install the game server (this should also run the game server for you).
docker run -it --rm -p 3000:3000 sendwithus/battlesnake-server
To stop/start the game server container use:
docker start vibrant_kowalevski
docker stop vibrant_kowalevski
Where vibrant_kowalevski
is the name of my local game server container.
- Visit http://localhost:3000
NOTE: Docker runs on a virtual LAN so when you add a snake to the game you cannot use
http://localhost:9000
, use your internal IP instead (also remove trailing/
).
Our code is based on Alexey's naive attempt at the BattleSnake competition in 2017. SendWithUs and Stembolt have put much effort and created an awesome game server for the competition - Thank you!