Version: v0.0.0-...-bf9d846 Latest Latest

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

Go to latest
Published: Sep 6, 2020 License: MIT Imports: 10 Imported by: 0




This section is empty.


This section is empty.


func DecodeSnakeRequest

func DecodeSnakeRequest(req *http.Request, decoded *SnakeRequest) error


type AI

type AI interface {
	Ping() (*PingResponse, error)
	Start(ctx context.Context, sr SnakeRequest) error
	Move(ctx context.Context, sr SnakeRequest) (*MoveResponse, error)
	End(ctx context.Context, sr SnakeRequest) error

AI is an individual snake AI.

type Board

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

Board is the game board.

func (Board) DeadlyAdjacent

func (b Board) DeadlyAdjacent(x Coord) []Coord

DeadlyAdjacent returns all of the adjacent deadly coordinates from this one.

func (Board) Inside

func (b Board) Inside(x Coord) bool

Inside checks if a point is inside the board.

func (Board) IsDeadly

func (b Board) IsDeadly(x Coord) bool

IsDeadly checks if a point would kill a snake if it moved into it.

type Coord

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

Coord is an X,Y coordinate pair.

func (Coord) Dir

func (l Coord) Dir(r Coord) string

Dir computes the net immediate direction from point l to point r

func (Coord) Down

func (l Coord) Down() Coord

func (Coord) Eq

func (l Coord) Eq(r Coord) bool

Eq checks if one Coord equals another.

func (Coord) Left

func (l Coord) Left() Coord

func (Coord) Right

func (l Coord) Right() Coord

func (Coord) String

func (l Coord) String() string

func (Coord) Up

func (l Coord) Up() Coord

type Game

type Game struct {
	ID string `json:"id"`

type Line

type Line struct {
	A, B Coord

Line is a pair of coordinates forming a line.

func (Line) Distance

func (l Line) Distance() float64

Distance is the net distance from A to B.

func (Line) Manhattan

func (l Line) Manhattan() float64

The Manhattan distance of a line.

func (Line) Slope

func (l Line) Slope() float64

Slope is the angle of the line in degrees.

type MoveResponse

type MoveResponse struct {
	Move string `json:"move"`

func (MoveResponse) F

func (m MoveResponse) F() ln.F

type PingResponse

type PingResponse struct {
	APIVersion string `json:"apiversion,omitempty"`
	Color      string `json:"color,omitempty"`
	HeadType   string `json:"head,omitempty"`
	TailType   string `json:"tail,omitempty"`

func (PingResponse) F

func (s PingResponse) F() ln.F

type Server

type Server struct {
	Brain AI
	Name  string

Server wraps an AI.

func (Server) ServeHTTP

func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Snake

type Snake struct {
	ID     string  `json:"id"`
	Name   string  `json:"name"`
	Health int     `json:"health"`
	Body   []Coord `json:"body"`

Snake is a competitor.

type SnakeRequest

type SnakeRequest struct {
	Game  Game  `json:"game"`
	Turn  int   `json:"turn"`
	Board Board `json:"board"`
	You   Snake `json:"you"`

func (SnakeRequest) F

func (sr SnakeRequest) F() ln.F

Jump to

Keyboard shortcuts

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