API and game logic for Battlesnake.
NOTE: If you just plan on running the engine by itself, it's recommended to skip to the running a release binary section.
export PATH="$PATH:$GOPATH/bin"$GOPATH/src/github.com/battlesnakeio/engine. Note, the docs for GOPATH and project directory layouts can be found here.Build an executable via make install and then run engine server to run a local version of the server.
Better command: make run
Note: if you use the Makefile, you'll want JQ installed, here
Setup a snake-config.json, by default the engine looks in the HOME directory (see make run-game in the Makefile).
Here's an example:
{
"width": 20,
"height": 20,
"food": 10,
"snakes": [
{
"name": "Snake 1",
"url": "http://localhost:8080"
},
{
"name": "Snake 2",
"url": "http://localhost:3001"
}
]
}
Start the engine (refer above)
Start a game with make run-game
Example Output:
$ make run-game
go install github.com/battlesnakeio/engine/cmd/engine
engine-cli run -g "d151fe9d-8c15-4d31-a932-e7b4248d5586"
To replay a game, run: engine replay -g <game id>
NOTE: This section is recommended if you don't want/need to setup a GO environment.
engine release for your architecture to a folder somewhere on your machineengine binary, the LICENSE, and the README available in the unpackaged foldersnake-config.json setup from the previous sectionengine server with ./engine server and keep this tab running for the next few stepsengine binary folder./engine create -c ~/.snake-config.json which will yield a JSON response with `{"ID": "some id here"}./engine run -g <game ID>Protip: Provided you have the board setup and running, and have jq installed, you can create a game then run it in your browser you can run this one-liner:
ENGINE_URL=http://localhost:3005
./engine create -c ~/.snake-config.json \
| jq --raw-output ".ID" \
| xargs -I {} sh -c \
"echo \"Go to this URL in your browser http://localhost:3000/?engine=${ENGINE_URL}&game={}\" && sleep 10; \
./engine run -g {}"
On macOS/OS X, you can tweak the above command and automatically open your browser to the correct game and run it, all in on go:
ENGINE_URL=http://localhost:3005
./engine create -c ~/.snake-config.json \
| jq --raw-output ".ID" \
| xargs -I {} sh -c \
"open -a \"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome\" \
\"http://localhost:3000/?engine=${ENGINE_URL}&game={}\" \
&& ./engine run -g {}'
For more information about the engine:
$ engine --help
> engine helps run games on the battlesnake game engine
Usage:
engine [flags]
engine [command]
Available Commands:
create creates a new game on the battlesnake engine
help Help about any command
load-test run a load test against the engine, using the provided snake config
replay replays an existing game on the battlesnake engine
run runs an existing game on the battlesnake engine
server serve the battlesnake game engine
status gets the status of a game from the battlesnake engine
Flags:
--api-addr string address of the api server (default <http://localhost:3005>)
-h, --help help for engine
--version version for engine
Use "engine [command] --help" for more information about a command.
Dev mode means that the engine will run a simple browser application that you can connect to your snake.
./engine dev
Open a browser and go to http://localhost:3010/
This will give you a web based environment to test the engine & the snake locally before you put it on the Internet.
Storage options:
inmem - This is the default. All game data is erased when the engine restarts.file - Stores one file per game. Games can be resumed or replayed after restart.redis - Stores game data in a redis key. Games can be resumed or replayed after restart.Save games as files in ~/battlesnake/
engine server --backend file --backend-args ~/battlesnake
Save games as keys in redis
engine server --backend redis --backend-args 'redis://localhost:6379'
Refer to the docs repository or website, specifically the snake API.
Content type
Image
Digest
Size
11 MB
Last updated
about 7 years ago
docker pull battlesnakeio/engine