Documentation ¶
Index ¶
Constants ¶
const ( HazardDamagePerTurn = 15 MaximumSnakeHealth = 100 )
const ( RulesetStandard = "standard" RulesetSolo = "solo" RulesetRoyale = "royale" RulesetSquad = "squad" RulesetConstrictor = "constrictor" RulesetWrapped = "wrapped" )
Variables ¶
var ErrNoPossibleMove = fmt.Errorf("no possible moves")
ErrNoPossibleMove indicates that no legal move is possible from the current position
Functions ¶
This section is empty.
Types ¶
type Battlesnake ¶
type Battlesnake struct { ID string `json:"id"` Name string `json:"name"` Health int32 `json:"health"` Body CoordList `json:"body"` Head Coord `json:"head"` Length int32 `json:"length"` Shout string `json:"shout"` }
func (Battlesnake) IsValid ¶
func (bs Battlesnake) IsValid(b Board, g Game) bool
IsValid determines if the snake is 'valid' on the given board. Valid snakes: * have possible moves * have non-zero health
func (Battlesnake) PossibleMoves ¶
func (bs Battlesnake) PossibleMoves(b Board, g Game) (CoordList, error)
PossibleMoves returns the list of possible coords the Battlesnake could take based on its current position and the provided board. It takes the board bounds and hazards into consideration. An error will the thrown if no moves are possible.
func (Battlesnake) Project ¶
func (bs Battlesnake) Project(loc Coord, board Board) Battlesnake
Project moves the Battlesnake to the given coordinate on the given board
type Board ¶
type Board struct { Height int `json:"height"` Width int `json:"width"` Food CoordList `json:"food"` Hazards CoordList `json:"hazards"` Snakes []Battlesnake `json:"snakes"` }
type BoardState ¶
type BoardState struct { Turn int `json:"turn"` Board Board `json:"board"` You Battlesnake `json:"you"` }
type Coord ¶
type Coord struct { X int `json:"x"` Y int `json:"y"` Direction Direction `json:"-"` Score float64 `json:"-"` }
Coord represents a point on the game board, optionally also containing the direction that resulted in the Coord.
func (Coord) DistanceFrom ¶
DistanceFrom returns the distance this Coord is from the given Coord
func (Coord) Project ¶
Project shifts the Coord in the given direction and returns the result. The resulting position is not guaranteed to be valid.
func (Coord) WithinBounds ¶
WithinBounds determines if the Coord is within the boundaries of the given Board. The game board is represented by a standard 2D grid, oriented with (0,0) in the bottom left. The Y-Axis is positive in the up direction, and X-Axis is positive to the right. Coordinates begin at zero, such that a board that is 11x11 will have coordinates ranging from [0, 10].
func (Coord) WrapForBoard ¶
WrapForBoard wraps the given coordinate around the edge of the given game board so that it remains valid. Note this is only valid for the 'wrapped' ruleset.
type CoordList ¶
type CoordList []Coord
CoordList is a list of Coords
func (CoordList) AverageDistance ¶
AverageDistance returns the average distance the given coordinate is from the list by calculating the distance from each point and averaging them.
func (CoordList) Directions ¶
Directions returns a slice of Direction referenced by the list
func (CoordList) Eliminate ¶
Eliminate returns a subset CoordList by eliminating any Coord present in the candidates list
type GameRequest ¶
type GameRequest struct { Game Game `json:"game"` Turn int `json:"turn"` Board Board `json:"board"` You Battlesnake `json:"you"` }
func (GameRequest) ToBoardState ¶
func (gr GameRequest) ToBoardState() BoardState
type SolveOptions ¶
type SolveOptions struct { Lookahead bool ConsiderOpponentNextMove bool UseSingleBestOption bool FoodReward int HazardPenalty int }
var DefaultSolveOptions SolveOptions = SolveOptions{ Lookahead: true, ConsiderOpponentNextMove: true, UseSingleBestOption: false, FoodReward: 20, HazardPenalty: 40, }
type Solver ¶
type Solver struct { Game Game Turn int Board Board You Battlesnake // contains filtered or unexported fields }
func CreateSolver ¶
func CreateSolver(gr GameRequest) *Solver
func (Solver) PickMove ¶
func (s Solver) PickMove(possibleMoves CoordList, opts SolveOptions) (Direction, error)
func (Solver) PossibleMoves ¶
func (s Solver) PossibleMoves(opts SolveOptions) (CoordList, error)
PossibleMoves returns a list of possible moves that could be taken next for the given game state. An error is raised if something prevents that.