MCPcopy Index your code
hub / github.com/BattlesnakeOfficial/rules

github.com/BattlesnakeOfficial/rules @v1.2.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2.3 ↗ · + Follow
607 symbols 2,128 edges 70 files 147 documented · 24%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

BattlesnakeOfficial/rules

codecov

Battlesnake rules and game logic, implemented as a Go module. This code is used in production at play.battlesnake.com. Issues and contributions welcome!

CLI for Running Battlesnake Games Locally

This repo provides a simple CLI tool to run games locally against your dev environment.

Installation

Download precompiled binaries here:

https://github.com/BattlesnakeOfficial/rules/releases

Install as a Go package. Requires Go 1.18 or higher. [Download]

go install github.com/BattlesnakeOfficial/rules/cli/battlesnake@latest

Compile from source. Also requires Go 1.18 or higher.

git clone git@github.com:BattlesnakeOfficial/rules.git
cd rules
go build -o battlesnake ./cli/battlesnake/main.go

Usage

Example command to run a game locally:

battlesnake play -W 11 -H 11 --name <SNAKE_NAME> --url <SNAKE_URL> -g solo -v

For more details, see the CLI README.

FAQ

Can I run games locally?

Yes! See the included CLI.

How is this different from the old Battlesnake engine?

The old game engine was re-written in early 2020 to handle a higher volume of concurrent games. As part of that rebuild we moved the game logic into a separate Go module that gets compiled into the production engine.

This provides two benefits: it makes it much simpler/easier to build new game modes, and it allows the community to get more involved in game development (without the maintenance overhead of the entire game engine).

Feedback

  • Do you have an issue or suggestions for this repository? Head over to our Feedback Repository today and let us know!

Extension points exported contracts — how you extend this code

GameMap (Interface)
(no doc) [26 implementers]
maps/game_map.go
Pipeline (Interface)
Pipeline is an ordered sequences of game stages which are executed to produce the next game state. If a stage produces [2 …
pipeline.go
Rand (Interface)
(no doc) [4 implementers]
rand.go
Ruleset (Interface)
(no doc) [2 implementers]
ruleset.go
TimedHttpClient (Interface)
(no doc) [2 implementers]
cli/commands/http.go
Editor (Interface)
Editor is used by GameMap implementations to modify the board state. [1 implementers]
maps/game_map.go
StageFunc (FuncType)
StageFunc represents a single stage of an ordered pipeline and applies custom logic to the board state each turn. It is
pipeline.go

Core symbols most depended-on inside this repo

NewBoardState
called by 96
board.go
NewBoardStateEditor
called by 38
maps/game_map.go
Intn
called by 36
rand.go
AddHazard
called by 31
maps/game_map.go
Run
called by 31
cli/commands/play.go
Execute
called by 30
ruleset.go
Settings
called by 29
ruleset.go
RegisterMap
called by 26
maps/registry.go

Shape

Method 268
Function 255
Struct 72
Interface 6
TypeAlias 5
FuncType 1

Languages

Go100%

Modules by API surface

maps/game_map.go52 symbols
maps/hazards.go49 symbols
maps/rivers_and_bridges.go33 symbols
board.go32 symbols
standard_test.go29 symbols
maps/solo_maze.go26 symbols
rand.go21 symbols
maps/castle_wall.go21 symbols
cli/commands/play.go20 symbols
ruleset.go19 symbols
cli/commands/play_test.go18 symbols
board_test.go18 symbols

For agents

$ claude mcp add rules \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact