Commit graph

57 commits

Author SHA1 Message Date
e7a4362a66 add http handler into play.go
this allows for http game creation
2025-08-18 21:31:31 -07:00
38368ba151 add db package
db package allows for writing games to postgres db
2025-08-18 21:29:05 -07:00
7426ddaf74 fix spacing
this totally was not an ai commit
2025-08-16 20:33:22 -07:00
4de6ada927 add frames array and comments for db insertion
Some checks failed
Test / Format (gofmt) (push) Has been cancelled
Test / Lint (golangci-lint) (push) Has been cancelled
Test / Test (go test) (push) Has been cancelled
Test / Build CLI (go install) (push) Has been cancelled
2025-08-15 12:27:45 -07:00
8d35f26ac2 add ability capture frames for later serving
Some checks are pending
Test / Format (gofmt) (push) Waiting to run
Test / Lint (golangci-lint) (push) Waiting to run
Test / Test (go test) (push) Blocked by required conditions
Test / Build CLI (go install) (push) Blocked by required conditions
2025-08-15 12:18:20 -07:00
bvanvugt
0b1fbb5423 Gofmt. 2023-02-19 17:17:59 +00:00
Aman Gupta
932f5418df
README.md modified (#120) 2022-12-15 09:47:32 -08:00
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
Rob O'Dwyer
639362ef46
DEV 1916: Fix output issues in CLI (#114)
* adding testing of output file and write line for /end

* fix regression in latency rounding for board
2022-10-20 13:16:52 -07:00
Rob O'Dwyer
5f60ccbba8
DEV 1793: Track latency, status codes, and errors from CLI games (#113)
* track latency and status code from CLI games

* actually track errors from snake responses
2022-10-04 15:53:29 -07:00
Rob O'Dwyer
3094a3041f update CLI README to reflect flag updates 2022-09-29 15:48:47 -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
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
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
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
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
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
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
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
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
BelowAverageDeveloper
762c94caf9
added TurnDuration option to cli (#62) 2022-03-28 10:22:51 -07:00
Rob O'Dwyer
447cbba8c0 add tests for convertRulesSnakes 2022-03-22 12:00:45 -07:00
Demin Dmitriy
d7d888e326 fix invalid request to /end when game ended in a draw
In `board.snakes` there would be `null` instead of `[]`.
2022-03-21 02:37:56 +03:00
Torben
397d925110
DEV-765 pipeline refactor (#64)
Refactor rulesets into smaller composable operations

In order to mix up the functionality from different rulesets like Solo, Royale, etc. the code in these classes needs to be broken up into small functions that can be composed in a pipeline to make a custom game mode.
2022-03-16 16:58:05 -07:00
Rob O'Dwyer
9cf20bb8ab
Add hazardMap and hazardMapAuthor to RulesetSettings (#63)
* add HazardMap and HazardMapAuthor to RulesetSettings

* test for format of hazard map properties
2022-03-03 12:21:09 -08:00
bvanvugt
e1ab986486 Bump to Go 1.17 2022-01-10 22:25:46 +00:00
Ebbe Steenhoudt
ba855a8ab1
Colored board (#59)
* New flag -c to use colors in the cli board view

* Error handeling

* Fix formatting

* Extracted ANSI escape codes into a different file

* Fixed formatting
2021-12-08 10:43:40 -08:00
Simon Agius Muscat
142a5a6ecf
Add export to file (#58)
* Initial addition of a game exporter

* Fix snake state bug, remove test logs, fix final output line being empty

* Ignore test JSONL file

* Added explanation for design decision on the you key in SnakeResponse

* Adjust gitignore to be more generic

* Retain consistency in usage of pointer

* Re-word explanation to refer to requests instead of responses

* Remove unnecessary nil check

* Check error returned by WriteString

* Change file permissions for output file

* Initialise gameexporter regardless of whether output is requested

* Print error and exit if export to file fails

* Added another comment explaining reasoning around export checks

* Fixed broken test due to changed return type
2021-12-02 09:59:20 -08:00
Rob O'Dwyer
4a9dbbcaef
DEV 559: Refactor CLI and add customizations (#57)
* move snake API structs into a new client package

* add customizations to snake objects

* refactor and add support for passing snake customizations in games
2021-11-25 14:07:56 -08:00
Rob O'Dwyer
31faba642c
Add missing ruleset params to request body and --debug-requests option (#55)
* fix sending of new params

* add royale and squad settings to requests

* add --debug-requests option

* update test for request body and add helper

Co-authored-by: Penelope Phippen <penelope@hey.com>
2021-09-07 14:58:10 -07:00
Rob O'Dwyer
2d57653d46
add CLI flags for ruleset settings and update hazardDamagePerTurn (#53) 2021-09-02 15:32:46 -07:00
Rob O'Dwyer
e9f408cdbb
add turn to BoardState and remove it from RoyaleRuleset (#52) 2021-08-27 13:28:12 -07:00
John Oram
17556e15c1
wrapped ruleset (#30)
* wrapped ruleset

* resurrect like brad suggested

* introduce mode to binary

* go fmt

* address edge crossing collision and eating bugs

* Update board_state.go

* removed binary

* rename variable
2021-08-24 12:11:36 -07:00
Rob O'Dwyer
015b681f14
DEV-280: Extract board generation out of rules.Ruleset (#51)
* extract board generation out of rules.Ruleset

* update comment and remove redundant interface check

* clone boardState in constrictor to respect the ModifyBoardState interface
2021-08-23 17:13:58 -07:00
Rob O'Dwyer
e416384007
Refactor RoyaleRuleset and move hazard damage into StandardRuleset (#50)
* move hazard damage into StandardRuleset

* OutOfBounds -> Hazards

* remove "out of bounds" in comment

* add cases for eating food to hazard damage test
2021-08-17 16:47:06 -07:00
Nettogrof
dabbe7dfb5
Remove Eliminated Snake from the send payload (#49) 2021-07-17 13:18:43 -07:00
Luke Mitchell
97fbcb3376
Add new arg "delay" to delay board updates by x milliseconds (#48)
Co-authored-by: Brad Van Vugt <1531419+bvanvugt@users.noreply.github.com>
2021-07-04 13:48:56 -07:00
bvanvugt
d42f5f46cc CLI: Persist hazards in royale games. 2021-07-04 13:41:44 -07:00
Jiri Novotny
0331ea65f8
fixed panic when printing snake out of bounds (#46)
Co-authored-by: Jiri Novotny <hello@jiricodes.com>
2021-07-02 20:42:16 -07:00
bvanvugt
f65f6d65d7 CLI: No longer send /move requests to eliminated snakes. 2021-07-02 20:36:37 -07:00
bvanvugt
bae7a5083c CLI - Send /end request to all Battlesnakes. 2021-07-02 20:12:39 -07:00
bvanvugt
72a74a9628 Remove ruleset versions for GitHub release version (future). 2021-07-02 20:09:55 -07:00
bvanvugt
9dba91619a Fix latency string in unit test. 2021-07-02 20:08:58 -07:00
John Oram
f31bdff4b8
add ruleset data to the calls made by the cli (name and version) (#32)
* add ruleset data to the cli (name and version)
* remove double ruleset tracking with royale mode
2021-07-02 20:00:19 -07:00
Hunter Freyer
d750b08317
Change SnakeResponse.Latency to be a string. (#45)
Convert CLI Latency value from int to string, to match what the current game engine does.
2021-06-21 14:25:31 -07:00