* adding logic to remove healing pools periodically to prevent extended length games * Fix for the case where ShrinkEveryNTurns is not set |
||
|---|---|---|
| .. | ||
| arcade_maze.go | ||
| arcade_maze_test.go | ||
| empty.go | ||
| empty_test.go | ||
| game_map.go | ||
| game_map_test.go | ||
| hazards.go | ||
| hazards_internal_test.go | ||
| hazards_test.go | ||
| healing_pools.go | ||
| healing_pools_test.go | ||
| helpers.go | ||
| helpers_internal_test.go | ||
| helpers_test.go | ||
| README.md | ||
| registry.go | ||
| registry_test.go | ||
| royale.go | ||
| sinkholes.go | ||
| sinkholes_test.go | ||
| solo_maze.go | ||
| standard.go | ||
| standard_test.go | ||
Game Maps
Game maps are a way to customize the game board independently of the pipeline of game rules, including snake positions, food and hazard spawning. More advanced mechanics, such as snake bots generated by the map, may be available in the future.
Anyone can write a new game map and submit a PR! Currently there are a few additional changes needed behind the scenes for it to appear in the production Battlesnake engine and on play.battlesnake.com, but you'll be able to use your own map right away with the battlesnake CLI.
How to write a map
You'll need to create a new Go type that implements maps.GameMap, and register it under a unique identifier. The methods your game map will need to implement are:
ID
Returns the unique ID this game map will be registered under. This method exists mostly to guard against typos while registering maps.
Meta
Returns some optional metadata about the map, currently name, author, and description. At some point we hope to expose this through the UI to give credit to community map authors.
SetupBoard
Called to generate a new board. The map is responsible for placing all snakes, food, and hazards.
An initial rules.BoardState is passed in that will be initialized with the width, height, and snakes with IDs but no bodies. SetupBoard should not modify this BoardState, but instead call methods on the maps.Editor to place snakes and optionally food/hazards.
UpdateBoard
Called to update an existing board every turn. For a map that doesn't spawn food or hazards after initial creation, this method can be a no-op! For maps that just do standard random food spawning, delegating to one of the existing maps is a good way to handle that.
Registering your map
Your map will need to be registered with its own ID using maps.RegisterMap. There are a few automated tests that will be run automatically on any registered map to ensure it appears to work correctly. You can run those tests yourself with:
go test ./maps
Things to watch out for
SetupBoardis called before any turns are run and before the game rules are applied.UpdateBoardis called at the end of each turn, after snakes have moved, been eliminated, etc.- There's no protection against placing duplicate food/hazards on the same location on the board. Maps need to account for this, especially when generating random food/hazard spawns.
- All maps that make use of random behaviour should use the
GetRandmethod on the settings object passed in to get a random number generator seeded with the game's seed and current turn. This will ensure the map generates in a reliable way, and will allow reproducing games based on the seed at some point in the near future.
How to test your map
- You can trigger a game locally using the new map with:
battlesnake play --width 11 --height 11 --name mysnake --url http://example.com/snake --name othersnake --url http://example.com/snake --map MAP_ID --viewmap