sdk

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Direction_Up    = Direction{0, 1}
	Direction_Down  = Direction{0, -1}
	Direction_Left  = Direction{-1, 0}
	Direction_Right = Direction{1, 0}
)
View Source
var MoveToDirection = map[BattlesnakeMove]Direction{
	BattlesnakeMove_Down:  Direction_Down,
	BattlesnakeMove_Up:    Direction_Up,
	BattlesnakeMove_Left:  Direction_Left,
	BattlesnakeMove_Right: Direction_Right,
}

Functions

func CoordSliceContains

func CoordSliceContains(elem Coord, slice []Coord) bool

CoordSliceContains returns back whether elem is contained in slice

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"`

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

func (Battlesnake) Direction

func (snake Battlesnake) Direction() Direction

func (Battlesnake) Moves

func (snake Battlesnake) Moves(logger log.Logger) []Direction

func (Battlesnake) Next

func (snake Battlesnake) Next(dir Direction, board Board) Battlesnake

Next returns back a new slice of coordinates the represents the new snake body If addOne is `true` then the body has an additional segment

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 BattlesnakeMove

type BattlesnakeMove string
const (
	BattlesnakeMove_Up    BattlesnakeMove = "up"
	BattlesnakeMove_Down  BattlesnakeMove = "down"
	BattlesnakeMove_Left  BattlesnakeMove = "left"
	BattlesnakeMove_Right BattlesnakeMove = "right"
)

type BattlesnakeMoveResponse

type BattlesnakeMoveResponse struct {
	Move  BattlesnakeMove `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"`
	// contains filtered or unexported fields
}

func (Board) Occupied

func (b Board) Occupied(c Coord) bool

Occupied returns back true if regardless of any movement if the coordinate will be occupied by a hazard or a snake body

func (Board) OtherSnakes

func (b Board) OtherSnakes(myID string) []Battlesnake

func (Board) OutOfBounds

func (b Board) OutOfBounds(c Coord) bool

type Coord

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

func (Coord) Add

func (c Coord) Add(other Coord) Coord

Add gets the sum of the individual axis of this coordinate and another: {x1 + x2, y1 + y2}

func (Coord) Euclidean

func (c Coord) Euclidean(other Coord) float64

Euclidean calculates the euclidean (actual) distance: ((x2 - x1)^2) + (y2 - y1)^2)^0.5

func (Coord) InDirectionOf

func (c Coord) InDirectionOf(source Coord, dir Direction) bool

func (Coord) Manhattan

func (c Coord) Manhattan(other Coord) int

Manhattan calculates the manhattan distance: |x2 - x1| + |y2 - y1|

func (Coord) Reverse

func (c Coord) Reverse() Coord

Reverse reverses the coordinate: {-1 * x, -1 * y}

type CoordComparator

type CoordComparator func(Coord, Coord) bool

type Direction

type Direction Coord

type Game

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

type GameState

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

func (GameState) Logger

func (state GameState) Logger(logger log.Logger) log.Logger

func (GameState) Next

func (state GameState) Next(dir Direction) GameState

type Ruleset

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

Jump to

Keyboard shortcuts

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