Commit graph

175 commits

Author SHA1 Message Date
Rob O'Dwyer
3094a3041f update CLI README to reflect flag updates 2022-09-29 15:48:47 -07:00
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
Rob O'Dwyer
35e5a53005 remove codecov action on pull request 2022-09-13 13:41:50 -07:00
Rob O'Dwyer
c4247945ca
DEV 1676: Add maps helper functions (#111)
* add utility methods to Editor and BoardStateEditor

* add Meta.Validate

* allow setting Meta.MinPlayers to zero

* remove uints in map sizes

* use Meta.Validate in HazardPitsMap
2022-09-13 13:11:43 -07:00
Chris Hoefgen
c5810d8604
map now respects 0% food spawn chance (#110) 2022-09-06 15:20:07 -07:00
Rob O'Dwyer
09aea9c49d
DEV 1666: Fix /end requests and clean up logging (#109)
* ensure /end request is always called, and refactor win/draw logic

* clean up logging and error handling during initialization

* automatically generate friendly snake names

* title-case snake names

* print out list of alive snake names instead of count

* log snake names, IDs, and URLs at startup

* print out state for turn zero
2022-09-02 14:35:55 -07:00
Chris Hoefgen
006f394355
New Island and Bridges variations (#107)
* Adding two new variations with hazards along the edges

* Implementing code review feedback
2022-08-26 13:37:30 -07:00
Chris Hoefgen
0061425c7e
Hazard Pits Map (#108)
* added the new hazard map with custom start locations

* tweaked comments/logic

* cleaning up functionality

* unit test plus bug fixes

* fixing unnecessary error
2022-08-26 10:26:48 -07:00
Chris Hoefgen
7fa55be26c
only spawn centre food on setup when settings.MinimumFood is > 0 (#106) 2022-08-26 09:26:48 -07:00
Blayne Campbell
ba3b882e1b
Castle Wall Hazard Map (#101)
* castle_wall map

Wall of hazards around the board with dangerous bridges.

- add support for all standard board sizes
- hazard placement for all board sizes

* passage food placement for all board sizes

* 4 snake starting positions for all maps

* only one food can spawn on a bridge

* support 8 snakes for all board sizes

support 12 snakes on XLarge and XXLarge board sizes

* max 2 food sm/med/lg and max 4 food on xlg/xxlg

no food in the first 10 turns

* sort generated hazard positions

* remove 'uninteresting' castle wall map board sizes

* refactor castle wall map to align with #103

* align map castle wall meta Name with ID

* set MinPlayers to 1 for castle wall map

* pass max snake/food and startPosition to priv func

* fix castle wall food placement and refactor tests

* avoid food spawn by snake heads on castle wall map

- fixes forced food spawning infront of snake issue on large & xlarge maps with double walls
2022-08-26 09:11:19 -07:00
Blayne Campbell
2668788683
add tags to map info cli output (#105)
* add tags to map info cli output

* simplify map list range expression
2022-08-25 16:15:58 -07:00
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
Chris Hoefgen
f82cfe5309
Rivers and Bridges map refactor (#103)
* Separated out rivers and bridges into its own file with three map variants

* fixing tags

* removed extra 4 starting positions from the medium map since it only supports 8 players

* update GetUnoccupiedPoints to consider hazards with a flag

* use new utility method to fine unoccupied points and enforce map sizes

* changed up casting to make IsAllowable() more usable
2022-08-19 10:09:04 -07:00
Rob O'Dwyer
7d769b01b6
new cause of death by hazard (#104) 2022-08-18 16:20:50 -07:00
Rob O'Dwyer
b1ddd2f4ca
Add wrapped_constrictor game mode and support for map tags (#102)
* add support for wrapped_constrictor game mode

* add tags to map metadata
2022-08-17 13:03:09 -07:00
Blayne Campbell
ffeb401377
add 'map' cli command to provide map information (#100)
* add 'map' cli command

- provides the following map information functions:
  - list all available maps in the global registry
  - display map metadata

- update docs with map command examples

* add list and info subcommands to map cli command

* rename map command list and info factory functions

* add --all flag to map info subcommand

* handle cmd.Help error
2022-08-09 15:06:28 -07:00
Chris Hoefgen
91106aec09
Add decay logic to healing pools (#97)
* adding logic to remove healing pools periodically to prevent extended length games

* Fix for the case where ShrinkEveryNTurns is not set
2022-08-08 14:57:34 -07:00
Chris Hoefgen
215a0ea998
DEV-1558-healing-pools-map (#94)
* Adding a basic map that adds a few hazards based on fixed coordinates to the map.

* Used wrong board size definitions
2022-07-28 11:07:27 -07:00
Chris Hoefgen
7d9a9fb1ab
DEV-1556-sinkholes-map (#96)
* initial map implementation

* added support for larger/smaller boards

* basic unit test
2022-07-28 11:07:16 -07:00
Josh LaFayette
f953f879bf
CLI support for handling invalid responses (#95)
Previously the CLI would exit immediately with an error if a snake
returned a response with invalid JSON.

Now the CLI continues running the game and a snake with an invalid
response continues in the direction of it's last move.

Also logs a warning with details about the invalid response. Where
possible, the log includes the response body in case it contains helpful
info.
2022-07-26 20:35:01 -07:00
Torben
e1289af5fb
DEV-1479 ensure snake elimination turn is set (#93)
* ensure snake elimination turn is set

- centralise elimination update logic to a single place to ensure consistency

* doc the method

* testing
2022-07-21 14:26:56 -07:00
Torben
663c377cc4
change map support for large #'s of snakes (#92)
* change map support for large #'s of snakes

* test square board fn

* format comment

* add whitespace

* better support large #'s of snakes on small boards

* include an intermediate xlarge size
2022-07-07 11:14:30 -07:00
Corey Alexander
08cb7ae61d
[Custom Map] Single Player Maze (#81)
* 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>
2022-07-04 10:25:28 -07:00
Rob O'Dwyer
1c728faeca
prevent negative hazard damage from healing past max health (#91) 2022-06-30 12:10:30 -07:00
Torben
61aeee31d6
allow placement of up to 16 snakes on xlarge board (#90) 2022-06-29 14:26:18 -07:00
Rob O'Dwyer
04a34dd8c7 update example output from battlesnake play --help 2022-06-28 16:54:46 -07:00
Rob O'Dwyer
a451cda9c4
DEV 1404: Support streaming CLI games to the browser board (#88)
* add minimal support for serving a game to the board UI

* refactor into new board package

* support reporting errors and author names to board

* support passing an alternate board URL

* avoid using IPv6 for local URL

* use rules.Point instead of a custom Point type for board package

* use zero for generic communication error code in cli

* rename createGameEvent to buildFrameEvent

* tests for conversion from boardState/snakeState to game frame
2022-06-28 16:17:44 -07:00
Chris Hoefgen
f6c3ed0791
speeding up how fast the expanding box grows from every 15 to every 12 turns (#89) 2022-06-28 14:46:21 -07:00
Torben
9d6b1147cd
fix for rivers and bridges snake start positions (#85)
* fix for rivers and bridges snake start positions

* update max player count, add unit test

* set player count to 12 (max for smallest size)

* fix: one of the 19x19 spawn points

* randomize snake placement at start positions

* randomly choose starts in quadrants

* fix: check that start positions are valid

* modify food placement to avoid hazards
2022-06-28 14:41:01 -07:00
Torben
f58df66e69
allow initial food placement for 8 snakes on 7x7 board (#87)
* allow initial food placement for 8 snakes on 7x7

* fix logic to be for small board

* fix inverted logic

* logic should be actually <= 4 snakes, not 7
2022-06-22 16:14:15 -07:00
mattcurts
5ecc285dcd
fix for readme, install as go package. go get is no longer supported (#86) 2022-06-22 14:55:32 -07:00
Torben
3180429688
Add player and board size meta data to all game maps (#84)
* WIP: initial data model for new meta props
* WIP: implemented new props
* test and bug fix:
- add coverage of players and sizes
- fix unlimited map size bug
* FIX: update supported players for arcade to 6
* fix: test should be min -> max, not max->max
* Change some naming and the FixedSizes function
* update comment to reflect API changes
* improve comment clarity
* rename field for improved clarity
* change some more "map" -> "board" wording
2022-06-19 20:09:17 -07:00
bvanvugt
cb014e7b37 Add food and snake spawn locations to Arcade Maze. 2022-06-16 17:26:09 +00:00
Torben
e8e20c53ad
Add a "Version" field to GameMap Meta (#83)
* initial concept for versioning
* simple uint version implementation
* tidy up dependencies
2022-06-15 15:51:42 -07:00
Brad Van Vugt
0f15f34bdf
Add two more food spawns to Arcade Maze map. 2022-06-15 10:42:41 -07:00
Rob O'Dwyer
25dc404493
DEV 1364: Allow solo games with all rulesets through the CLI (#80)
* add support for automatic solo through RulesetBuilder

* allow solo games with all modes in CLI
2022-06-08 15:45:20 -07:00
Rob O'Dwyer
426da8ac5e
reorder built-in ruleset stages so game over is checked first (#79) 2022-06-01 15:21:27 -07:00
Torben
f0dc0bcb38
DEV-1313: Add additional map types (#76)
* add helper to draw a ring of hazards

* refactor tests to not be internal tests

* add "hz_inner_wall" map

* add "hz_rings" map

* fix map registry

* fix: edge case bugs in drawRing

* remove println

* add "hz_columns"

* add "hz_rivers_bridges" map

* WIP: implementing spiral hazards map

* finish basic testing of 'hz_spiral'

* include first turn

* add "hz_hazards" map

* remove incorrect author

* add "hz_grow_box" map

* add "hz_expand_box" map

* add "hz_expand_scatter" map

* remove debug

* document the new "Range" method

* - use rules.RulesetError instead of generic error
- use a rules.Point for map rivers and bridgets map key

* use rules.RulesetError instead of errors.New

* provide more detail about boundar conditions

* fix documentation (max can be == min)

* add unit tests
2022-06-01 11:39:31 -07:00
Rob O'Dwyer
aa38bcd0eb
DEV 1283: Arcade maze map (#77)
* add "namcap" map

* adjust hazards and starting food positions

* add food randomly, not on top of hazards

* add exits on the top and bottom

* rename to arcade_maze

* add maps README

* test for ArcadeMazeMap

* adjustments to hazards in arcade_maze
2022-05-31 07:29:34 -07:00
Max Thomson
fff551599a
Json output isDraw correctly (#78) 2022-05-30 15:16:06 -07:00
Rob O'Dwyer
1adbc79168
DEV 953: Add basic maps support to CLI (#74)
* remove squad support and switch to using pipelines only in RulesBuilder

* remove spawn_food.standard from legacy ruleset definitions

* bugfix: Royale map generates Standard food

* add maps support to CLI

* add automated tests for all registered GameMap implementations

* update README
2022-05-25 11:24:27 -07:00
Torben
3bd1e47bb4
change all "int32" types to "int" (#75) 2022-05-25 11:17:41 -07:00
Rob O'Dwyer
2d8342018e
add map to snake request body (#73) 2022-05-19 12:43:03 -07:00
Rob O'Dwyer
e94d758a9b
DEV 1303: Add empty and royale maps and update game map interface (#72)
* move random generator into Settings

* add empty and royale maps

* place snakes on either cardinal or corner positions first
2022-05-17 15:45:56 -07:00
Rob O'Dwyer
6fa2da2f01 tests for SetupBoard and UpdateBoard and a bugfix 2022-05-11 16:30:08 -07:00
Rob O'Dwyer
1dcc1352cc add RegisterMap for testing convenience 2022-05-11 08:28:50 -07:00
Rob O'Dwyer
dab9178a55
DEV 1247: Add a new map generator interface (#71)
* reorganize code

* first draft of map generator interfaces

* add explicit random interface to board helpers

* implement standard map

* rename Generator to GameMap

* allow initializing snakes separately from placing them

* add random number generator to Settings

* updates to GameMap interface

* add helpers for creating and updating BoardState with maps
2022-05-11 08:26:28 -07:00
Rob O'Dwyer
1c3f434841
DEV 1253: Upgrade to Go 1.18.1 (#70)
* fix dependency that breaks on go 1.18.1

* upgrade to go 1.18.1

* upgrade golangci-lint to a version that works with go 1.18
2022-05-02 13:57:07 -07:00
Torben
d378759d58
DEV-1096 - add a new "pipeline" concept (#67)
* add a new "pipeline" concept

- added new Pipeline type which is a series of stages
- added a global registry to facilitate plugin architecture
- 100% test coverage

* Refactor rulesets to provide and use Pipeline

* fix copypasta comments

* fix lint for unused method

* include game over stages in ruleset pipelines

* clean up unused private standard methods

* remove unused private methods in squad ruleset

* remove unused private methods in royale ruleset

* refactor: pipeline clone + return next board state

* YAGNI: remove unused Append

* refactor: improve stage names

* add no-op behavior to stages for initial state

* refactor: no-op decision within stage functions

* remove misleading comment that isn't true

* dont bother checking for init in gameover stages

* remove redundant test

* refactor: provide a combined ruleset/pipeline type

* fix: movement no-op for GameOver check

IsGameOver needs to run pipeline, move snakes needs to no-op for that

* add test coverage

* refactor: improve stage names and use constants

* add Error method

Support error checking before calling Execute()

* update naming to be American style

* panic when overwriting stages in global registry

* rename "Error" method and improve docs

* use testify lib for panic assertion

* remove redundant food stage

* use ruleset-specific logic for game over checks

* re-work Pipeline errors

* rework errors again

* add defensive check for zero length snake

* use old logic which checks current state, not next

* add warning about how PipelineRuleset checks for game over
2022-04-19 15:52:57 -07:00
Josh LaFayette
86ef6ad068
Update CLI documentation (#69)
- Update usage section in the README with the latest flags.
- Update default sample output (BoardState fields have changed,
  OutOfBounds has been removed).
- Add section describing options for getting JSON output with the
  `--output` and `--debug-requests` flag.
2022-04-11 09:13:22 -07:00