Documentation ¶
Index ¶
- Constants
- func CheckForGameOver(mode GameMode, gt *pb.GameFrame) bool
- func CreateInitialGame(req *pb.CreateRequest) (*pb.Game, []*pb.GameFrame, error)
- func GameTick(game *pb.Game, lastFrame *pb.GameFrame) (*pb.GameFrame, error)
- func NotifyGameEnd(game *pb.Game, frame *pb.GameFrame)
- func ValidateEnd(gameID string, url string, slowSnakeMS int32) *pb.SnakeResponseStatus
- func ValidateMove(gameID string, url string, slowSnakeMS int32) *pb.SnakeResponseStatus
- func ValidatePing(gameID string, url string, slowSnakeMS int32) *pb.SnakeResponseStatus
- func ValidateStart(gameID string, url string, slowSnakeMS int32) *pb.SnakeResponseStatus
- type Board
- type Coords
- type Game
- type GameMode
- type GameStatus
- type MoveResponse
- type Snake
- type SnakeMetadata
- type SnakeRequest
- type SnakeUpdate
- type StartResponse
Constants ¶
const ( // DeathCauseSnakeCollision is the death reason when 2 snakes collide with each other DeathCauseSnakeCollision = "snake-collision" // DeathCauseSnakeSelfCollision is the death reason when a snake collides with itself DeathCauseSnakeSelfCollision = "snake-self-collision" // DeathCauseStarvation is the death reason when a snakes health reaches zero DeathCauseStarvation = "starvation" // DeathCauseHeadToHeadCollision is when a snake dies from a head on head collision DeathCauseHeadToHeadCollision = "head-collision" // DeathCauseWallCollision is when a snake runs off the board DeathCauseWallCollision = "wall-collision" )
const (
// SlowSnakeMS represents what is considered a slow response time to the Validate* calls.
SlowSnakeMS = 1000
)
Variables ¶
This section is empty.
Functions ¶
func CheckForGameOver ¶
CheckForGameOver checks if the game has ended. End condition is dependent on game mode.
func CreateInitialGame ¶
CreateInitialGame creates a new game based on the create request passed in
func NotifyGameEnd ¶
NotifyGameEnd sends the /end requests to all the snakes.
func ValidateEnd ¶
func ValidateEnd(gameID string, url string, slowSnakeMS int32) *pb.SnakeResponseStatus
ValidateEnd validates the end end point on a snake server
func ValidateMove ¶
func ValidateMove(gameID string, url string, slowSnakeMS int32) *pb.SnakeResponseStatus
ValidateMove validates the move end point on a snake server
func ValidatePing ¶
func ValidatePing(gameID string, url string, slowSnakeMS int32) *pb.SnakeResponseStatus
ValidatePing validates the ping endpoint on a snake server
func ValidateStart ¶
func ValidateStart(gameID string, url string, slowSnakeMS int32) *pb.SnakeResponseStatus
ValidateStart validates the start end point on a snake server
Types ¶
type Board ¶
type Board struct { Height int32 `json:"height"` Width int32 `json:"width"` Food []Coords `json:"food"` Snakes []Snake `json:"snakes"` }
Board provides information about the game board
type GameMode ¶
type GameMode string
GameMode represents the mode the game is running in
const ( // GameModeSinglePlayer represents the game running in single player mode, this means the game will // run until the only snake in the game dies GameModeSinglePlayer GameMode = "single-player" // GameModeMultiPlayer represents when there is more then 1 snake in the game, this means the game will // run until there is zero or one snakes left alive in the game. GameModeMultiPlayer GameMode = "multi-player" )
type GameStatus ¶
type GameStatus string
GameStatus current status of a game
var ( // GameStatusStopped represents a stopped game GameStatusStopped GameStatus = "stopped" // GameStatusRunning represents a running game GameStatusRunning GameStatus = "running" // GameStatusError represents a game that ended because of an error GameStatusError GameStatus = "error" // GameStatusComplete represents a game that is done GameStatusComplete GameStatus = "complete" )
type MoveResponse ¶
type MoveResponse struct {
Move string
}
MoveResponse the message format of the move response from a Snake API call
type Snake ¶
type Snake struct { ID string `json:"id"` Name string `json:"name"` Health int32 `json:"health"` Body []Coords `json:"body"` }
Snake represents information about a snake in the game
type SnakeMetadata ¶
SnakeMetadata contains a snake and the metadata sent in the start response from the snake server.
type SnakeRequest ¶
type SnakeRequest struct { Game Game `json:"game"` Turn int32 `json:"turn"` Board Board `json:"board"` You Snake `json:"you"` }
SnakeRequest the message send for all snake api calls
type SnakeUpdate ¶
SnakeUpdate bundles together a snake with a move for processing
func GatherSnakeMoves ¶
GatherSnakeMoves goes and queries each snake for the snake move
type StartResponse ¶
type StartResponse struct {
Color string
}
StartResponse is the format for /start responses