api

package
v0.0.0-...-12cc957 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package api implements the Battlesnake API for hosting a Battlesnake. To host a Battlesnake, implement the Snek interface and serve it up with Router.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Router

func Router(newSnek func() Snek) http.Handler

Router returns an http.Handler that serves up a Snek.

Types

type Battlesnake

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

type Board

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

type Game

type Game struct {
	ID      string                 `json:"id"`
	Ruleset map[string]interface{} `json:"ruleset"`
	Timeout int                    `json:"timeout"`
}

type GameRequest

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

type InfoResponse

type InfoResponse struct {
	APIVersion string `json:"apiversion"`
	Author     string `json:"author,omitempty"`
	Color      string `json:"color,omitempty"`
	Head       string `json:"head,omitempty"`
	Tail       string `json:"tail,omitempty"`
	Version    string `json:"version,omitempty"`
}

type MoveResponse

type MoveResponse struct {
	Move  string `json:"move"`
	Shout string `json:"shout"`
}

type Point

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

type Snek

type Snek interface {
	Start(*State) error
	Move(*State) (string, string, error)
	End(*State) error
}

Snek defines the interactions of a Battlesnake with the API.

type State

type State struct {
	Game  Game
	Turn  int
	Board Board
	Me    Battlesnake
}

State defines the game state on a given turn.

Everything else in this file is wireformat types explained at https://docs.battlesnake.com/references/api.

Jump to

Keyboard shortcuts

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