v0.13.1 concession management and record, clients update, version report
test / test (push) Canceled after 0s

This commit is contained in:
lixen committed 2026-09-29 02:09:45 -04:00
1 parent f1ac4cbbe7
commit 6e8d80c788
30 files changed
+704 -81

No files matched your search

+9
View File
@@ -43,11 +43,20 @@ 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 is the game's first resignation or agreed draw; the server keeps
// it when an undo continues play against the computer.
type Concession struct {
Result string `json:"result"`
Termination string `json:"termination"`
Ply int `json:"ply"`
}
type ResignRequest struct {
Color string `json:"color,omitempty"`
}
+32 -2
View File
@@ -408,6 +408,23 @@ func printOutcome(resp *api.GameResponse) {
}
}
// printConcession notes a resignation or agreed draw that play continued
// past; the server keeps it on record.
func printConcession(resp *api.GameResponse) {
c := resp.Concession
if c == nil || (c.Result == resp.State && c.Termination == resp.Termination) {
return
}
event := "A draw was agreed"
switch c.Result {
case "white wins":
event = "Black resigned"
case "black wins":
event = "White resigned"
}
display.Println(display.Yellow, "%s at ply %d; it stays on record while play continues.", event, c.Ply)
}
func drawReason(termination string) string {
switch termination {
case "insufficient_material":
@@ -498,6 +515,7 @@ func undoHandler(s *session.Session, args []string) error {
s.SetLastMoveCount(len(resp.Moves))
s.SetGameState(resp)
display.Println(display.Green, "Undid %d move(s)", count)
printConcession(resp)
return nil
}
@@ -561,6 +579,8 @@ func showBoardHandler(s *session.Session, args []string) error {
}
fmt.Println()
}
printOutcome(game)
printConcession(game)
return nil
}
@@ -619,10 +639,13 @@ func pollHandler(s *session.Session, args []string) error {
c := s.GetClient().(*api.Client)
moveCount := s.GetLastMoveCount()
previous := s.CurrentGameState
display.Println(display.Cyan, "Long-polling for updates (move count: %d)...", moveCount)
display.Println(display.Cyan, "This may take up to 30 seconds")
// The server answers at once for a finished game, and wakes a poll for a
// move, an undo, a result, or a draw offer.
resp, err := c.GetGameWithPoll(gameID, moveCount)
if err != nil {
return err
@@ -631,14 +654,21 @@ func pollHandler(s *session.Session, args []string) error {
s.SetLastMoveCount(len(resp.Moves))
s.SetGameState(resp)
if len(resp.Moves) > moveCount {
switch {
case len(resp.Moves) > moveCount:
display.Println(display.Green, "Game updated! New moves detected")
if resp.LastMove != nil {
fmt.Printf("Last move: %s\n", resp.LastMove.Move)
}
} else {
case len(resp.Moves) < moveCount:
display.Println(display.Green, "Game updated: %d move(s) taken back", moveCount-len(resp.Moves))
case previous == nil || previous.GameID != resp.GameID ||
previous.State != resp.State || previous.DrawOffer != resp.DrawOffer:
display.Println(display.Green, "Game updated")
default:
display.Println(display.Yellow, "No updates (timeout)")
}
printOutcome(resp)
return nil
}