* Commit from Stream We got the maze working decently well! Started off with exploring the repo a bit and getting used to the Map stuff The Maze is working pretty well except the mazes that are generated aren't actually complete-able yet. They end up creating spaces that are blocked off from the rest of the map The maze generation algo is based off 'Recursive division method' mostly following this Wiki This looked to always create a 'valid' maze, while mine doesn't so need to figure out what my bug is, cause I'm pretty sure there is one! * I think we got maze generation working! Did a lot, should have commited more lol Got map generation working where I can see it go frame by frame, and think we squashed the last few bugs with wall generation and hole cutting Now need it to actually make a new maze when you finish this first one * We can run on a bigger board now, and we place the food randomly on the board after you grab it the first time * Make sure my health is always 100 so don't have to worry about that lol * Fix placing of food on maze to NOT be on an existing hazard and after 3 foods make a new maze * Maze generation works better now and a bit of cleanup * Committing old code * Got state saving as Hazards Bits Working well, I think whats up next is making the map grow each level * Draw maze in the center of the board, the maze grows as you complete levels until it fills the entire board * Ran go fmt * Remove my little debugging script that I added * Revert changes I made initially to the map interface * Move my copy-pasted printMap function to my map specifically * Go fmt * Write some doc comments and fix some weird code artifacts * A few more comments and one last go fmt * Cut less holes, this makes the maze more exciting * Add version to Metadata and go fmt again * Can collapse this down * Random food spawns are more fun for sure * add minimal support for serving a game to the board UI * We did 3 main things here: - Fixed the bug where hazards were getting multi-stacked - Fixed the bug where the food could spawn on top of the snake head - Fixed the lint errors * Games aren't infinite now, they end by not spawning a food when you have reached a certain number of turns at the max board size * Extract some functions to make deciding when the game is over easier * Get evil mode implemented to force the game to end * Fix small bugs about where we spawned the food in evil mode * Have the snake keep growing by adding tail segments to match the current level. We start at two length because 1 lenth snakes look weird on the board since they don't have a neck to orient themselves. Here we also fix a bug where evil mode was trying to place food off the map * Run go fmt * Add the missing meta-data pieces * Support a smaller board without the change of infinite loops and change the name of the maze * Rename the actual struct and fix the tests to not make extra snakes when the map doesn't support it * Revert "add minimal support for serving a game to the board UI" This reverts commit 0ac3592c7669ab1bccd7bd3322adffbef5e911ce. * add minimal support for serving a game to the board UI * Cleanup and extract and function to place food so we don't have basically the same body twice. This also will prevent the initial food spawn from being right next to the snake * Revert "add minimal support for serving a game to the board UI" This reverts commit c1a3b134213dabf44df56e3ca1e6d30ff8aaa516. * Fix lint * 2 length snakes are silly, so lets start with 3 each time * We start out with 3 length snakes, and a fixed set of map sizes Co-authored-by: Rob O'Dwyer <odwyerrob@gmail.com> |
||
|---|---|---|
| .. | ||
| 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 | ||
| helpers.go | ||
| helpers_internal_test.go | ||
| helpers_test.go | ||
| README.md | ||
| registry.go | ||
| registry_test.go | ||
| royale.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