Byte-snake-engine/maps
Josh LaFayette fbbec6a7f5
Snail mode (#98)
* Add snail-mode map

* snail-mode: cap max hazards to 7

- Ensure that no more than 7 hazards are added to a square. This
  fixes a bug where some squares were getting way too many hazards
  applied to them.  There must be some other bug at work here as
  well.
- Change author names to be github usernames instead of first names

* snail-mode: fix bug with eliminated snakes

- Ensure that hazard snail-trail is not added for eliminated snakes

* Update from Stream July 31

Added comments to most functions and important bits of code

Also changed the map so that instead of a fixed number of 7 hazards,
we add hazards equal to the length of the snake.

* snail-mode: add TAG_EXPERIMENTAL and TAG_HAZARD_PLACEMENT

* snail-mode: use Point as map key

Co-authored-by: Corey Alexander <coreyja@gmail.com>
2022-08-19 10:23:33 -07:00
..
arcade_maze.go Add wrapped_constrictor game mode and support for map tags (#102) 2022-08-17 13:03:09 -07:00
arcade_maze_test.go DEV 1283: Arcade maze map (#77) 2022-05-31 07:29:34 -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 Rivers and Bridges map refactor (#103) 2022-08-19 10:09:04 -07:00
game_map_test.go Add player and board size meta data to all game maps (#84) 2022-06-19 20:09:17 -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-1313: Add additional map types (#76) 2022-06-01 11:39:31 -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-1313: Add additional map types (#76) 2022-06-01 11:39:31 -07:00
README.md DEV 1283: Arcade maze map (#77) 2022-05-31 07:29:34 -07:00
registry.go add 'map' cli command to provide map information (#100) 2022-08-09 15:06:28 -07:00
registry_test.go Rivers and Bridges map refactor (#103) 2022-08-19 10:09:04 -07:00
rivers_and_bridges.go Rivers and Bridges map refactor (#103) 2022-08-19 10:09:04 -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 Rivers and Bridges map refactor (#103) 2022-08-19 10:09:04 -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