v0.11.0 harden persistence and prepare game replays
This commit is contained in:
@@ -5,7 +5,7 @@ type State int
|
||||
const (
|
||||
StateOngoing State = iota
|
||||
StatePending // Computer is calculating a move
|
||||
StateStuck // Computer is calculating a move
|
||||
StateStuck // Engine work failed and requires recovery or undo
|
||||
StateWhiteWins
|
||||
StateBlackWins
|
||||
StateDraw
|
||||
@@ -31,4 +31,31 @@ func (s State) String() string {
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IsTerminal reports whether the game has a durable result. Pending and stuck
|
||||
// are operational states and must not be archived as completed games.
|
||||
func (s State) IsTerminal() bool {
|
||||
switch s {
|
||||
case StateWhiteWins, StateBlackWins, StateDraw, StateStalemate:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Result returns the stable persistence/API value for a terminal state.
|
||||
func (s State) Result() (string, bool) {
|
||||
switch s {
|
||||
case StateWhiteWins:
|
||||
return "white_wins", true
|
||||
case StateBlackWins:
|
||||
return "black_wins", true
|
||||
case StateDraw:
|
||||
return "draw", true
|
||||
case StateStalemate:
|
||||
return "stalemate", true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user