Documentation ¶
Index ¶
- Constants
- func ChangeSnakeRoute(w http.ResponseWriter, r *http.Request)
- func ConfigSetup()
- func DecideNextMove(request *MoveRequest) (string, error)
- func GameEndRoute(w http.ResponseWriter, r *http.Request)
- func GameStartRoute(w http.ResponseWriter, r *http.Request)
- func GetSnakeRoute(w http.ResponseWriter, r *http.Request)
- func HealthRequestRoute(w http.ResponseWriter, r *http.Request)
- func MoveRequestRoute(w http.ResponseWriter, r *http.Request)
- func Send(w http.ResponseWriter, code int, payload interface{})
- func SendError(w *http.ResponseWriter, r *http.Request, status int, systemCode string, ...)
- func SetupApp() *chi.Mux
- func StatusRequestRoute(w http.ResponseWriter, r *http.Request)
- func TestAPICall(method string, endpoint string, data io.Reader, handler http.HandlerFunc, ...) (code int, body *bytes.Buffer, err error)
- func UnmarshalMap(body *bytes.Buffer) (map[string]interface{}, error)
- func UnmarshalSlice(body *bytes.Buffer) ([]interface{}, error)
- type Battlesnake
- type Board
- type Configuration
- type Game
- type GameRequest
- type MoveRequest
- type MoveResponse
- type Point
- type SnakeOptions
Constants ¶
const ( BOARD_HEAD = "| H |" BOARD_BODY = "| B |" BOARD_FOOD = "| F |" BOARD_HAZARD = "| Z |" BOARD_ENEMY = "| E |" )
const ( // heads SNAKE_HEAD_STANDARD_DEFAULT = "default" SNAKE_HEAD_STANDARD_BELUGA = "beluga" SNAKE_HEAD_STANDARD_BENDR = "bendr" SNAKE_HEAD_STANDARD_DEAD = "dead" SNAKE_HEAD_STANDARD_EVIL = "evil" SNAKE_HEAD_STANDARD_FANG = "fang" SNAKE_HEAD_STANDARD_PIXEL = "pixel" SNAKE_HEAD_STANDARD_SAFE = "safe" SNAKE_HEAD_STANDARD_SAND_WORM = "sand-worm" SNAKE_HEAD_STANDARD_SHADES = "shades" SNAKE_HEAD_STANDARD_SILLY = "silly" SNAKE_HEAD_STANDARD_SMILE = "tongue" // heads - winter 2019 SNAKE_HEAD_WINTER_2019_BONHOMME = "bonhomme" SNAKE_HEAD_WINTER_2019_EARMUFFS = "earmuffs" SNAKE_HEAD_WINTER_2019_RUDOLPH = "rudolph" SNAKE_HEAD_WINTER_2019_SCARF = "scarf" SNAKE_HEAD_WINTER_2019_SKI = "ski" SNAKE_HEAD_WINTER_2019_SNOWMAN = "snowman" SNAKE_HEAD_WINTER_2019_SNOW_WORM = "snow-worm" // heads - stay home and code 2020 SNAKE_HEAD_CODE_2020_CAFFEINE = "caffeine" SNAKE_HEAD_CODE_2020_GAMER = "gamer" SNAKE_HEAD_CODE_2020_TIGER_KING = "tiger-king" SNAKE_HEAD_CODE_2020_WORKOUT = "workout" SNAKE_TAIL_STANDARD_DEFAULT = "default" SNAKE_TAIL_STANDARD_BLOCK_BUM = "block-bum" SNAKE_TAIL_STANDARD_BOLT = "bolt" SNAKE_TAIL_STANDARD_CURLED = "curled" SNAKE_TAIL_STANDARD_FAT_RATTLE = "fat-rattle" SNAKE_TAIL_STANDARD_FRECKLED = "freckled" SNAKE_TAIL_STANDARD_HOOK = "hook" SNAKE_TAIL_STANDARD_PIXEL = "pixel" SNAKE_TAIL_STANDARD_ROUND_BUM = "round-bum" SNAKE_TAIL_STANDARD_SHARP = "sharp" SNAKE_TAIL_STANDARD_SKINNY = "skinny" SNAKE_TAIL_STANDARD_SMALL_RATTLE = "small-rattle" // tails - winter 2019 SNAKE_TAIL_WINTER_2019_BONHOMME = "bonhomme" SNAKE_TAIL_WINTER_2019_FLAKE = "flake" SNAKE_TAIL_WINTER_2019_ICE_SKATE = "ice-skate" SNAKE_TAIL_WINTER_2019_PRESENT = "present" // tails - stay home and code 2020 SNAKE_TAIL_CODE_2020_COFFEE = "coffee" SNAKE_TAIL_CODE_2020_MOUSE = "mouse" SNAKE_TAIL_CODE_2020_TIGER_TAIL = "tiger-tail" SNAKE_TAIL_CODE_2020_WEIGHT = "weight" )
we specify all of the snake options here; the constants should be of SNAKE_WHAT_GROUP_NAME format. Only public customizations available for everyone are added here; feel free to override. Accurate as of 20210518: https://play.battlesnake.com/references/customizations/
Variables ¶
This section is empty.
Functions ¶
func ChangeSnakeRoute ¶
func ChangeSnakeRoute(w http.ResponseWriter, r *http.Request)
ChangeSnakeRoute allows the caller to change the snake details. Note that this is current unauthenticated so it could be used for bad intentions. You may want to comment this out in the http.go file
func ConfigSetup ¶
func ConfigSetup()
func DecideNextMove ¶
func DecideNextMove(request *MoveRequest) (string, error)
func GameEndRoute ¶
func GameEndRoute(w http.ResponseWriter, r *http.Request)
GameEndRoute is called at the end of the game and represents the final state of the game: https://docs.battlesnake.com/references/api#end
func GameStartRoute ¶
func GameStartRoute(w http.ResponseWriter, r *http.Request)
GameStartRoute is called when a new game is starting: https://docs.battlesnake.com/references/api#start
func GetSnakeRoute ¶
func GetSnakeRoute(w http.ResponseWriter, r *http.Request)
GetSnakeRoute gets the attributes about a snake. In the current UI, this route is not easily seen (missing the HTTP method in the menu)
func HealthRequestRoute ¶
func HealthRequestRoute(w http.ResponseWriter, r *http.Request)
HealthRequestRoute is the http end point for checking the server's health
func MoveRequestRoute ¶
func MoveRequestRoute(w http.ResponseWriter, r *http.Request)
MoveRequestRoute prompts the server for a new move
func Send ¶
func Send(w http.ResponseWriter, code int, payload interface{})
Send is a helper function to normalize what gets sent back and optionally log the request
func SendError ¶
func SendError(w *http.ResponseWriter, r *http.Request, status int, systemCode string, message string, data *map[string]interface{})
SendError allows for hooking into an error return so we can do things like trigger an error log
func StatusRequestRoute ¶
func StatusRequestRoute(w http.ResponseWriter, r *http.Request)
StatusRequestRoute is the http end point for checking the server's status
func TestAPICall ¶
func TestAPICall(method string, endpoint string, data io.Reader, handler http.HandlerFunc, authorizationKey string) (code int, body *bytes.Buffer, err error)
TestAPICall allows an easy way to test HTTP end points in unit testing
func UnmarshalMap ¶
UnmarshalMap helps to unmarshal the request for the testing calls
func UnmarshalSlice ¶
UnmarshalSlice unmarshals a response that is an array in the data
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"` }
Battlesnake is a single instance of a snake: https://docs.battlesnake.com/references/api#battlesnake
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"` }
Board is the primary view of the state of a game: https://docs.battlesnake.com/references/api#board
type Configuration ¶
type Configuration struct { APIPort int AuthSeed string AuthKey string ShowAuth bool Author string Version string SnakeColor string SnakeHead string SnakeTail string Shout string }
var Config *Configuration
type Game ¶
type Game struct { ID string `json:"id"` Ruleset struct { Name string `json:"name"` Version string `json:"version"` } `json:"ruleset"` Timeout int `json:"timeout"` // in milliseconds }
Game is the meta data about a Game: https://docs.battlesnake.com/references/api#game
type GameRequest ¶
type GameRequest struct { Game Game `json:"game"` Turn int64 `json:"turn"` Board Board `json:"board"` You Battlesnake `json:"you"` }
GameRequest is what the API will send when a snake is entered into a new game
type MoveRequest ¶
type MoveRequest struct { Game Game `json:"game"` Turn int `json:"turn"` Board Board `json:"board"` You Battlesnake `json:"you"` }
MoveRequest is the incoming HTTP request that contains the state of the game and requires a movement response: https://docs.battlesnake.com/references/api/sample-move-request
type MoveResponse ¶
type MoveResponse struct { Move string `json:"move"` // one of "up" "down" "left" "right" Shout string `json:"shout"` // what to yell }
MoveResponse is the response to the MoveRequest: https://docs.battlesnake.com/references/api/sample-move-request
type Point ¶
Point is an x:y coordinate on the board and is used for board layout and snake placement
type SnakeOptions ¶
type SnakeOptions struct { Color string `json:"color"` Head string `json:"head"` Tail string `json:"tail"` // Randomize is used for the route to change the snake Randomize bool `json:"randomize"` Shout string `json:"shout"` }
SnakeOptions are the different personalization options for a snake: https://play.battlesnake.com/references/customizations/