api

package
v0.0.0-...-351bd47 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MovePath         = "/move"
	PingPath         = "/ping"
	DefaultMoveLimit = 2 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CommonDBFields

type CommonDBFields struct {
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Game

type Game struct {
	ID int64 `gorm:"column:id"`

	MatchId int64 `gorm:"column:match_id"`
	WhiteId int64 `gorm:"column:white_player_id"`
	BlackId int64 `gorm:"column:black_player_id"`

	Reason string `gorm:"column:reason"`
	Status string `gorm:"column:status"`

	CommonDBFields
}

func (*Game) Outcome

func (g *Game) Outcome() (game.Outcome, error)

type GameResult

type GameResult struct {
	White         Player
	Black         Player
	Outcome       game.Outcome
	VictoryReason Victory
	States        []game.State
}

type GameStatus

type GameStatus string
const (
	GameScheduled GameStatus = "scheduled"
	GameDraw      GameStatus = "draw"
	GameBlackWins GameStatus = "black_wins"
	GameWhiteWins GameStatus = "white_wins"
)

func (GameStatus) String

func (s GameStatus) String() string

type GameWithDetails

type GameWithDetails struct {
	Game
	WhitePlayer Player
	BlackPlayer Player
}

func (GameWithDetails) TableName

func (c GameWithDetails) TableName() string

type GamesService

type GamesService interface {
	List() ([]Game, error)
	ListDetailed() ([]*GameWithDetails, error)
}

type Match

type Match struct {
	ID int64 `gorm:"column:id"`

	PID1 int64 `gorm:"column:player_1_id"`
	PID2 int64 `gorm:"column:player_2_id"`

	CommonDBFields
}

type MatchesService

type MatchesService interface {
	// Run creates a match and schedules it for execution.
	Run(playerID1, playerID2 int64) (*Match, error)
}

type MoveRequest

type MoveRequest struct {
	State      game.State `json:"state"`
	LimitMilli int64      `json:"limit_milli"`
}

type Player

type Player struct {
	Name    string
	Version int64
	Path    string

	ID int64 `gorm:"column:id"`

	AuthorId int64 `gorm:"column:user_id"`

	CommonDBFields
}

Player is an AI agent running on an HTTP server

type PlayersService

type PlayersService interface {
	Upload(userID int64, p Player, executable io.Reader) (*Player, error)
	Create(userID int64, p Player) (*Player, error)
	List() ([]Player, error)
	Delete(id int64) error
}

type Ranking

type Ranking struct {
	Rank   int     `json:"rank"`
	Player string  `json:"player"`
	Author string  `json:"author"`
	Rating float64 `json:"rating"`
	Wins   int     `json:"wins"`
	Losses int     `json:"losses"`
}

type RankingsService

type RankingsService interface {
	List() ([]*Ranking, error)
}

type Record

type Record struct {
	GameID  int64 `gorm:"column:game_id"`
	TurnNum int64 `gorm:"column:turn_num"`

	State string `gorm:"column:state"`

	CommonDBFields
}

type Services

type Services struct {
	Rankings RankingsService
	Games    GamesService
	Matches  MatchesService
	Players  PlayersService
	Users    UsersService

	DB *gorm.DB
}

type User

type User struct {
	Name  string
	Email string

	ID int64 `gorm:"column:id"`

	CommonDBFields
}

type UsersService

type UsersService interface {
	Create(User) (*User, error)
	List() ([]User, error)
	Delete(id int64) error
}

type Victory

type Victory int
const (
	NoVictory Victory = iota
	MovesDepleted
	StonesDepleted
	InvalidResponse
	TimelimitExceeded
)

func (Victory) String

func (v Victory) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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