rules

package
v0.0.0-...-b90c408 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2019 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	// SlowSnakeMS represents what is considered a slow response time to the Validate* calls.
	SlowSnakeMS = 1000
)

Variables

This section is empty.

Functions

func CheckForGameOver

func CheckForGameOver(mode GameMode, gt *pb.GameFrame) bool

CheckForGameOver checks if the game has ended. End condition is dependent on game mode.

func CreateInitialGame

func CreateInitialGame(req *pb.CreateRequest) (*pb.Game, []*pb.GameFrame, error)

CreateInitialGame creates a new game based on the create request passed in

func GameTick

func GameTick(game *pb.Game, lastFrame *pb.GameFrame) (*pb.GameFrame, error)

GameTick runs the game one tick and updates the state

func NotifyGameEnd

func NotifyGameEnd(game *pb.Game, frame *pb.GameFrame)

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 Coords

type Coords struct {
	X int32 `json:"x"`
	Y int32 `json:"y"`
}

Coords represents a point on the board

type Game

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

Game represents the current game state

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

type SnakeMetadata struct {
	Snake *pb.Snake
	Color string
	Err   error
}

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

type SnakeUpdate struct {
	Snake *pb.Snake
	Move  string
	Err   error
}

SnakeUpdate bundles together a snake with a move for processing

func GatherSnakeMoves

func GatherSnakeMoves(timeout time.Duration, game *pb.Game, gameFrame *pb.GameFrame) []*SnakeUpdate

GatherSnakeMoves goes and queries each snake for the snake move

type StartResponse

type StartResponse struct {
	Color string
}

StartResponse is the format for /start responses

Jump to

Keyboard shortcuts

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