battlesnakegameformat

package module
v0.0.0-...-5b3514d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 6 Imported by: 0

README

battlesnake-game-format-go

A compressed game format for Battlesnake suitable for DB storage

This is a WIP, please don't use this

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(game *ViewGame, buf *bytes.Buffer) error

Compress contents using zip archive (stored in buf)

Types

type MoveBattlesnake

type MoveBattlesnake struct {
	ID      string      `json:"id"`
	Name    string      `json:"name"`
	Health  int32       `json:"health"`
	Body    []MoveCoord `json:"body"`
	Head    MoveCoord   `json:"head"`
	Length  int32       `json:"length"`
	Latency string      `json:"latency"`
	Shout   string      `json:"shout"`
	Squad   string      `json:"squad"`
}

type MoveBattlesnakeResponse

type MoveBattlesnakeResponse struct {
	Move  string `json:"move"`
	Shout string `json:"shout,omitempty"`
}

type MoveBoard

type MoveBoard struct {
	Height  int32             `json:"height"`
	Width   int32             `json:"width"`
	Food    []MoveCoord       `json:"food"`
	Snakes  []MoveBattlesnake `json:"snakes"`
	Hazards []MoveCoord       `json:"hazards"`
}

type MoveCoord

type MoveCoord struct {
	X int32 `json:"x"`
	Y int32 `json:"y"`
}

type MoveGame

type MoveGame struct {
	ID      string      `json:"id"`
	Ruleset MoveRuleset `json:"ruleset"`
	Timeout int32       `json:"timeout"`
}

type MoveGameState

type MoveGameState struct {
	Game  MoveGame        `json:"game"`
	Turn  int32           `json:"turn"`
	Board MoveBoard       `json:"board"`
	You   MoveBattlesnake `json:"you"`
}

type MoveRoyale

type MoveRoyale struct {
	ShrinkEveryNTurns int32 `json:"shrinkEveryNTurns"`
}

type MoveRuleset

type MoveRuleset struct {
	Name     string       `json:"name"`
	Version  string       `json:"version"`
	Settings MoveSettings `json:"settings"`
}

type MoveSettings

type MoveSettings struct {
	FoodSpawnChance     int32      `json:"foodSpawnChance"`
	MinimumFood         int32      `json:"minimumFood"`
	HazardDamagePerTurn int32      `json:"hazardDamagePerTurn"`
	Royale              MoveRoyale `json:"royale"`
	Squad               MoveSquad  `json:"squad"`
}

type MoveSquad

type MoveSquad struct {
	AllowBodyCollisions bool `json:"allowBodyCollisions"`
	SharedElimination   bool `json:"sharedElimination"`
	SharedHealth        bool `json:"sharedHealth"`
	SharedLength        bool `json:"sharedLength"`
}

type ViewCoord

type ViewCoord struct {
	X int32 `json:"X"`
	Y int32 `json:"Y"`
}

type ViewDeath

type ViewDeath struct {
	Cause        string `json:"Cause"`
	Turn         int32  `json:"Turn"`
	EliminatedBy string `json:"EliminatedBy"`
}

type ViewFrame

type ViewFrame struct {
	Turn    int32       `json:"Turn"`
	Snakes  []ViewSnake `json:"Snakes"`
	Food    []ViewCoord `json:"Food"`
	Hazards []ViewCoord `json:"Hazards"`
}

type ViewGame

type ViewGame struct {
	Game       ViewGameSettings `json:"Game"`
	Frames     []ViewFrame      `json:"Frames"`
	FirstFrame ViewFrame        `json:"FirstFrame"`
	LastTurn   int32            `json:"LastTurn"`
}

func Decode

func Decode(data []byte) (*ViewGame, error)

Uncompress data for a game

func (*ViewGame) ToMove

func (game *ViewGame) ToMove(turn int32, snakeId string) (*MoveGameState, error)

type ViewGameResponse

type ViewGameResponse struct {
	Game ViewGameSettings `json:"Game"`
}

type ViewGameSettings

type ViewGameSettings struct {
	ID      string      `json:"ID"`
	Ruleset ViewRuleset `json:"Ruleset"`
	Timeout int32       `json:"SnakeTimeout"`
	Status  string      `json:"Status"`
	Width   int32       `json:"Width"`
	Height  int32       `json:"Height"`
}

type ViewRuleset

type ViewRuleset struct {
	FoodSpawnChance int32  `json:"foodSpawnChance,string"`
	MinimumFood     int32  `json:"minimumFood,string"`
	Name            string `json:"name"`
	Map             string `json:"map"`
	MapAuthor       string `json:"map_author"`
	DamagePerTurn   int32  `json:"damagePerTurn,string"`
}

type ViewSnake

type ViewSnake struct {
	ID         string      `json:"ID"`
	Name       string      `json:"Name"`
	URL        string      `json:"URL"`
	Body       []ViewCoord `json:"Body"`
	Health     int32       `json:"Health"`
	Color      string      `json:"Color"`
	HeadType   string      `json:"HeadType"`
	TailType   string      `json:"TailType"`
	Latency    string      `json:"Latency"`
	Shout      string      `json:"Shout"`
	Squad      string      `json:"Squad"`
	APIVersion string      `json:"APIVersion"`
	Author     string      `json:"Author"`
	Death      ViewDeath   `json:"Death,omitempty"`
}

type ViewTurn

type ViewTurn struct {
	Frames []ViewFrame `json:"Frames"`
	Count  int32       `json:"Count"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL