game

package
v0.0.0-...-4fb7718 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Left  Move = "left"
	Right      = "right"
	Up         = "up"
	Down       = "down"
)
View Source
const DOUBLE_STACK_PART uint8 = 0x02
View Source
const EMPTY uint8 = 0x05
View Source
const FOOD uint8 = 0x04
View Source
const IS_HAZARD uint8 = 0x10
View Source
const KIND_MASK uint8 = 0x07
View Source
const MeId = SnakeId(1)
View Source
const SNAKE_BODY_PART uint8 = 0x01
View Source
const SNAKE_HEAD uint8 = 0x06
View Source
const TRIPLE_STACK_PART uint8 = 0x03

Variables

This section is empty.

Functions

func CartesianProduct

func CartesianProduct(movesA [][]SnakeMove, movesB []SnakeMove) [][]SnakeMove

func GetCartesianProductOfMoves

func GetCartesianProductOfMoves(board FastBoard) [][]SnakeMove

func IndexInDirection

func IndexInDirection(m Move, cur uint16, width, height uint16, isWrapped bool) uint16

func Voronoi

func Voronoi(game *FastBoard, player SnakeId) voronoiResult

Types

type Battlesnake

type Battlesnake struct {
	ID             string         `json:"id"`
	Name           string         `json:"name"`
	Health         int32          `json:"health"`
	Body           []Coord        `json:"body"`
	Head           Coord          `json:"head"`
	Length         int32          `json:"length"`
	Latency        string         `json:"latency"`
	Customizations Customizations `json:"customizations"`

	// Used in non-standard game modes
	Shout string `json:"shout"`
	Squad string `json:"squad"`
}

type BattlesnakeInfoResponse

type BattlesnakeInfoResponse struct {
	APIVersion string `json:"apiversion"`
	Author     string `json:"author"`
	Color      string `json:"color"`
	Head       string `json:"head"`
	Tail       string `json:"tail"`
}

type BattlesnakeMoveResponse

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

type Board

type Board struct {
	Height int           `json:"height"`
	Width  int           `json:"width"`
	Food   []Coord       `json:"food"`
	Snakes []Battlesnake `json:"snakes"`

	// Used in non-standard game modes
	Hazards []Coord `json:"hazards"`
}

type Coord

type Coord struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type Customizations

type Customizations struct {
	Color string `json:"color"`
	Head  string `json:"head"`
	Tail  string `json:"tail"`
}

type FastBoard

type FastBoard struct {
	List []Tile

	Heads   headsMap
	Lengths lengthsMap
	Healths healthsMap
	Width   uint16
	Height  uint16
	// contains filtered or unexported fields
}

func BuildBoard

func BuildBoard(state GameState) FastBoard

func (*FastBoard) AdvanceBoard

func (b *FastBoard) AdvanceBoard(moves map[SnakeId]Move)

func (*FastBoard) AdvanceBoardTB

func (b *FastBoard) AdvanceBoardTB(move SnakeMove)

Advances the board, for use with a turn based board

func (*FastBoard) Clone

func (b *FastBoard) Clone() FastBoard

func (*FastBoard) GetMovesForSnake

func (b *FastBoard) GetMovesForSnake(id SnakeId) []SnakeMove

func (*FastBoard) GetMovesForSnakeNoDefault

func (b *FastBoard) GetMovesForSnakeNoDefault(id SnakeId) []SnakeMove

func (*FastBoard) GetMovesForSnakeTB

func (b *FastBoard) GetMovesForSnakeTB(id SnakeId) []SnakeMove

Gets moves for a particular snake, for use with a turn based board Will return an empty array if there are no possible moves

func (*FastBoard) GetNeighbors

func (b *FastBoard) GetNeighbors(index uint16) []Move

func (*FastBoard) GetNeighborsTB

func (b *FastBoard) GetNeighborsTB(index uint16) []Move

Gets neighboring tiles, for use with a turn based board Does not return tiles that are off the board, insta kill hazards, and snake bodies

func (*FastBoard) IsGameOver

func (b *FastBoard) IsGameOver() bool

func (*FastBoard) IsSnakeAlive

func (b *FastBoard) IsSnakeAlive(id SnakeId) bool

func (*FastBoard) IsTileFood

func (b *FastBoard) IsTileFood(index uint16) bool

func (*FastBoard) Print

func (b *FastBoard) Print()

func (*FastBoard) RandomRollout

func (b *FastBoard) RandomRollout()

func (*FastBoard) RandomRolloutTB

func (b *FastBoard) RandomRolloutTB()

Runs a random game till completion, for use with a turn based board

type Game

type Game struct {
	ID      string  `json:"id"`
	Ruleset Ruleset `json:"ruleset"`
	Timeout int32   `json:"timeout"`
	Map     string  `json:"map"`
	Source  string  `json:"source"`
}

type GameState

type GameState struct {
	Game  Game        `json:"game"`
	Turn  int         `json:"turn"`
	Board Board       `json:"board"`
	You   Battlesnake `json:"you"`
}

type Move

type Move string

type Point

type Point struct {
	X int8
	Y int8
}

type Royale

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

type Ruleset

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

type Settings

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

type SnakeId

type SnakeId uint16

type SnakeMove

type SnakeMove struct {
	Id  SnakeId
	Dir Move
}

type Squad

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

type Tile

type Tile struct {
	// contains filtered or unexported fields
}

func CreateBodyTile

func CreateBodyTile(id SnakeId, nextIdx uint16) Tile

func CreateDoubleStackTile

func CreateDoubleStackTile(id SnakeId, nextIdx uint16) Tile

func CreateEmptyTile

func CreateEmptyTile() Tile

func CreateHeadTile

func CreateHeadTile(id SnakeId, tailIdx uint16) Tile

func CreateTripleStackTile

func CreateTripleStackTile(id SnakeId) Tile

func (*Tile) Clear

func (t *Tile) Clear()

func (*Tile) ClearHazard

func (t *Tile) ClearHazard()

func (*Tile) GetIdx

func (t *Tile) GetIdx() uint16

func (*Tile) GetSnakeId

func (t *Tile) GetSnakeId() (SnakeId, bool)

func (*Tile) IsDoubleStack

func (t *Tile) IsDoubleStack() bool

func (*Tile) IsEmpty

func (t *Tile) IsEmpty() bool

func (*Tile) IsFood

func (t *Tile) IsFood() bool

func (*Tile) IsHazard

func (t *Tile) IsHazard() bool

func (*Tile) IsHeadTail

func (t *Tile) IsHeadTail() bool

func (*Tile) IsNonHeadSegment

func (t *Tile) IsNonHeadSegment() bool

func (*Tile) IsSnakeBody

func (t *Tile) IsSnakeBody() bool

func (*Tile) IsSnakeBodyPart

func (t *Tile) IsSnakeBodyPart() bool

func (*Tile) IsSnakeHead

func (t *Tile) IsSnakeHead() bool

SNAKE RELATED

func (*Tile) IsSnakeSegment

func (t *Tile) IsSnakeSegment() bool

func (*Tile) IsStacked

func (t *Tile) IsStacked() bool

func (*Tile) IsTripleStack

func (t *Tile) IsTripleStack() bool

func (*Tile) SetBodyPart

func (t *Tile) SetBodyPart(id SnakeId, nextIdx uint16)

func (*Tile) SetBodyTail

func (t *Tile) SetBodyTail(bodyId SnakeId, bodyTail uint16, tailId SnakeId, bodyNext uint16)

func (*Tile) SetDoubleStack

func (t *Tile) SetDoubleStack(id SnakeId, nextIdx uint16)

func (*Tile) SetFood

func (t *Tile) SetFood()

func (*Tile) SetHazard

func (t *Tile) SetHazard()

func (*Tile) SetHead

func (t *Tile) SetHead(id SnakeId, tailIdx uint16)

func (*Tile) SetHeadTail

func (t *Tile) SetHeadTail(headSnakeId SnakeId, headSnakeTail uint16, tailSnakeId SnakeId, tailSnakeNext uint16)

func (*Tile) SetTripleStack

func (t *Tile) SetTripleStack(id SnakeId)

Jump to

Keyboard shortcuts

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