v0.13.1 concession management and record, clients update, version report
test / test (push) Canceled after 0s
test / test (push) Canceled after 0s
This commit is contained in:
1 parent
f1ac4cbbe7
commit
6e8d80c788
30 files changed
+704
-81
No files matched your search
@@ -41,7 +41,8 @@ type UndoRequest struct {
|
||||
// GameResponse is the live game. Termination names how a finished game ended;
|
||||
// DrawOffer is the color whose draw offer awaits an answer; DrawOutcome
|
||||
// reports what a draw request did ("offered", "accepted", "declined") and is
|
||||
// set only on responses to that request.
|
||||
// set only on responses to that request. Concession is the game's first
|
||||
// resignation or agreed draw, kept after an undo continues play.
|
||||
type GameResponse struct {
|
||||
GameID string `json:"gameId"`
|
||||
FEN string `json:"fen"`
|
||||
@@ -50,11 +51,22 @@ type GameResponse struct {
|
||||
Termination string `json:"termination,omitempty"`
|
||||
DrawOffer string `json:"drawOffer,omitempty"`
|
||||
DrawOutcome string `json:"drawOutcome,omitempty"`
|
||||
Concession *Concession `json:"concession,omitempty"`
|
||||
Moves []string `json:"moves"`
|
||||
Players PlayersResponse `json:"players"`
|
||||
LastMove *MoveInfo `json:"lastMove,omitempty"`
|
||||
}
|
||||
|
||||
// Concession records a resignation or agreed draw. Result uses the enclosing
|
||||
// response's vocabulary: a state ("black wins") in GameResponse, a stored
|
||||
// result ("black_wins") in GameHistoryResponse. Ply is the number of moves
|
||||
// played when it was made.
|
||||
type Concession struct {
|
||||
Result string `json:"result"`
|
||||
Termination string `json:"termination"`
|
||||
Ply int `json:"ply"`
|
||||
}
|
||||
|
||||
type MoveInfo struct {
|
||||
Move string `json:"move"`
|
||||
PlayerColor string `json:"playerColor"` // "w" or "b"
|
||||
@@ -73,7 +85,8 @@ type BoardResponse struct {
|
||||
//
|
||||
// PGNResult is the PGN result token ("1-0", "0-1", "1/2-1/2", or "*") and
|
||||
// Termination names how a result was reached (see core.Termination; omitted
|
||||
// while the game is unfinished).
|
||||
// while the game is unfinished). Concession is the game's first resignation
|
||||
// or agreed draw, kept when an undo continued play past it.
|
||||
type GameHistoryResponse struct {
|
||||
GameID string `json:"gameId"`
|
||||
InitialFEN string `json:"initialFen"`
|
||||
@@ -82,6 +95,7 @@ type GameHistoryResponse struct {
|
||||
Termination string `json:"termination,omitempty"`
|
||||
StartTimeUTC time.Time `json:"startTimeUtc"`
|
||||
EndTimeUTC *time.Time `json:"endTimeUtc,omitempty"`
|
||||
Concession *Concession `json:"concession,omitempty"`
|
||||
Players PlayersResponse `json:"players"`
|
||||
Moves []HistoryMove `json:"moves"`
|
||||
}
|
||||
|
||||
@@ -15,4 +15,5 @@ const (
|
||||
ErrUnauthorized = "UNAUTHORIZED"
|
||||
ErrConflict = "GAME_CONFLICT"
|
||||
ErrStorageUnavailable = "STORAGE_UNAVAILABLE"
|
||||
ErrRouteNotFound = "NOT_FOUND"
|
||||
)
|
||||
@@ -91,6 +91,13 @@ func (t Termination) ValidFor(s State) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// IsConcession reports whether the players chose the result: a resignation or
|
||||
// a draw by agreement. A concession is final when both sides are human; against
|
||||
// the computer play may continue, and the first concession stays on record.
|
||||
func (t Termination) IsConcession() bool {
|
||||
return t == TermResignation || t == TermAgreement
|
||||
}
|
||||
|
||||
// ParseColor accepts "w", "b", "white", or "black"; anything else is zero.
|
||||
func ParseColor(s string) Color {
|
||||
switch s {
|
||||
|
||||
Reference in new issue
Block a user