Byte-snake-engine/maps
Rob O'Dwyer e6e36ce46f
DEV-1703: Avoid spawning food on hazards for islands and bridges map (#112)
* move PlaceFoodFixed and PlaceSnakesInQuadrants to maps package

* don't spawn food on hazards in islands/rivers and bridges maps
2022-09-22 16:09:01 -07:00
..
arcade_maze.go map now respects 0% food spawn chance (#110) 2022-09-06 15:20:07 -07:00
arcade_maze_test.go DEV 1283: Arcade maze map (#77) 2022-05-31 07:29:34 -07:00
castle_wall.go DEV 1676: Add maps helper functions (#111) 2022-09-13 13:11:43 -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 Add wrapped_constrictor game mode and support for map tags (#102) 2022-08-17 13:03:09 -07:00
empty_test.go change map support for large #'s of snakes (#92) 2022-07-07 11:14:30 -07:00
game_map.go DEV 1676: Add maps helper functions (#111) 2022-09-13 13:11:43 -07:00
game_map_test.go DEV 1676: Add maps helper functions (#111) 2022-09-13 13:11:43 -07:00
hazard_pits.go DEV 1676: Add maps helper functions (#111) 2022-09-13 13:11:43 -07:00
hazard_pits_test.go Hazard Pits Map (#108) 2022-08-26 10:26:48 -07:00
hazards.go Rivers and Bridges map refactor (#103) 2022-08-19 10:09:04 -07:00
hazards_test.go Rivers and Bridges map refactor (#103) 2022-08-19 10:09:04 -07:00
healing_pools.go Add wrapped_constrictor game mode and support for map tags (#102) 2022-08-17 13:03:09 -07:00
healing_pools_test.go Add decay logic to healing pools (#97) 2022-08-08 14:57:34 -07:00
helpers.go DEV-1703: Avoid spawning food on hazards for islands and bridges map (#112) 2022-09-22 16:09:01 -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-1703: Avoid spawning food on hazards for islands and bridges map (#112) 2022-09-22 16:09:01 -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 1676: Add maps helper functions (#111) 2022-09-13 13:11:43 -07:00
rivers_and_bridges.go DEV-1703: Avoid spawning food on hazards for islands and bridges map (#112) 2022-09-22 16:09:01 -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 Add wrapped_constrictor game mode and support for map tags (#102) 2022-08-17 13:03:09 -07:00
sinkholes.go Add wrapped_constrictor game mode and support for map tags (#102) 2022-08-17 13:03:09 -07:00
sinkholes_test.go DEV-1556-sinkholes-map (#96) 2022-07-28 11:07:16 -07:00
snail_mode.go Snail mode (#98) 2022-08-19 10:23:33 -07:00
solo_maze.go Add wrapped_constrictor game mode and support for map tags (#102) 2022-08-17 13:03:09 -07:00
standard.go Rivers and Bridges map refactor (#103) 2022-08-19 10:09:04 -07:00
standard_test.go change map support for large #'s of snakes (#92) 2022-07-07 11:14:30 -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