Byte-snake-engine/maps
Rob O'Dwyer 82e1999126
DEV-1761: New rules API (#118)
* DEV-1761: Clean up Ruleset interface (#115)

* remove legacy ruleset types and simplify ruleset interface

* remove unnecessary settings argument from Ruleset interface

* decouple rules.Settings from client API and store settings as strings

* DEV 1761: Add new BoardState and Point fields (#117)

* add Point.TTL, Point.Value, GameState and PointState to BoardState

* allow maps to access BoardState.GameState,PointState

* add PreUpdateBoard and refactor snail_mode with it

* fix bug where an extra turn was printed to the console

* fix formatting

* fix lint errors

Co-authored-by: JonathanArns <jonathan.arns@googlemail.com>
2022-10-28 16:49:49 -07:00
..
arcade_maze.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
arcade_maze_test.go DEV 1283: Arcade maze map (#77) 2022-05-31 07:29:34 -07:00
castle_wall.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
castle_wall_internal_test.go Castle Wall Hazard Map (#101) 2022-08-26 09:11:19 -07:00
castle_wall_test.go DEV 1676: Add maps helper functions (#111) 2022-09-13 13:11:43 -07:00
empty.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
empty_test.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
game_map.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
game_map_test.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
hazard_pits.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
hazard_pits_test.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
hazards.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
hazards_test.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
healing_pools.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
healing_pools_test.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
helpers.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
helpers_internal_test.go DEV-1313: Add additional map types (#76) 2022-06-01 11:39:31 -07:00
helpers_test.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
README.md DEV 1283: Arcade maze map (#77) 2022-05-31 07:29:34 -07:00
registry.go add tags to map info cli output (#105) 2022-08-25 16:15:58 -07:00
registry_test.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
rivers_and_bridges.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
rivers_and_bridges_internal_test.go Rivers and Bridges map refactor (#103) 2022-08-19 10:09:04 -07:00
rivers_and_bridges_test.go DEV-1703: Avoid spawning food on hazards for islands and bridges map (#112) 2022-09-22 16:09:01 -07:00
royale.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
sinkholes.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
sinkholes_test.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
snail_mode.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
solo_maze.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
standard.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00
standard_test.go DEV-1761: New rules API (#118) 2022-10-28 16:49:49 -07:00

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

  • SetupBoard is called before any turns are run and before the game rules are applied. UpdateBoard is 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 GetRand method 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