Stage 17 round 5 — backend/correctness bug fixes
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Failing after 12s
CI / ui (pull_request) Successful in 30s
CI / gate (pull_request) Failing after 1s
CI / deploy (pull_request) Has been skipped
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Failing after 12s
CI / ui (pull_request) Successful in 30s
CI / gate (pull_request) Failing after 1s
CI / deploy (pull_request) Has been skipped
- Resign on the opponent's turn: engine ResignSeat(seat) resigns a specific seat (not just toMove); game.Resign bypasses the turn check and forfeits the actor's seat. - Quick-match cancel was a UI no-op (only stopped polling): add the full path (REST /lobby/cancel -> gateway lobby.cancel -> client) and clear the matchmaker's pending result on Cancel, so a cancelled search is dequeued (no 'already queued', no later robot-substituted game). NewGame dequeues on cancel and on abandon. - Lobby win/loss: result.ts ranked by score, so a 0-0 resignation read as a win. The winner now takes rank 1 and the viewer is placed from rank 2 — matching the game-detail screen. - Friend request to a robot: robots no longer block requests; the request stays pending and expires (friendRequestTTL), mirroring a human who ignores it. - Nudge cooldown: ErrNudgeTooSoon now maps to a distinct nudge_too_soon code with a correct message; the chat nudge button disables during the hourly cooldown; the nudge note reads 'Waiting for your move!' (button keeps the Nudge action label). Tests: engine/service off-turn resign, matchmaker cancel-clears-result, friend-to-robot inttest, result.ts 0-0 resignation, nudge_too_soon mapping.
This commit is contained in:
@@ -248,17 +248,29 @@ func (g *Game) Exchange(tiles []byte) (MoveRecord, error) {
|
||||
// winning regardless of score. A missed-turn timeout reuses Resign in the game
|
||||
// domain, so it inherits this win/loss.
|
||||
func (g *Game) Resign() (MoveRecord, error) {
|
||||
return g.ResignSeat(g.toMove)
|
||||
}
|
||||
|
||||
// ResignSeat resigns a specific seat regardless of whose turn it is, so a player
|
||||
// may forfeit on the opponent's turn. The resigning seat always loses (winner()
|
||||
// skips resigned seats). The turn cursor only advances when the seat that resigned
|
||||
// was the one to move; resigning an off-turn seat leaves the current player's turn
|
||||
// intact. It returns ErrGameOver on a finished game or for an out-of-range or
|
||||
// already-resigned seat.
|
||||
func (g *Game) ResignSeat(seat int) (MoveRecord, error) {
|
||||
if g.over {
|
||||
return MoveRecord{}, ErrGameOver
|
||||
}
|
||||
player := g.toMove
|
||||
g.resigned[player] = true
|
||||
g.disposeHand(player)
|
||||
rec := MoveRecord{Player: player, Action: ActionResign, Total: g.scores[player]}
|
||||
if seat < 0 || seat >= len(g.hands) || g.resigned[seat] {
|
||||
return MoveRecord{}, ErrGameOver
|
||||
}
|
||||
g.resigned[seat] = true
|
||||
g.disposeHand(seat)
|
||||
rec := MoveRecord{Player: seat, Action: ActionResign, Total: g.scores[seat]}
|
||||
g.log = append(g.log, rec)
|
||||
if g.activeCount() <= 1 {
|
||||
g.finish(EndResign)
|
||||
} else {
|
||||
} else if seat == g.toMove {
|
||||
g.advance()
|
||||
}
|
||||
return rec, nil
|
||||
|
||||
@@ -69,6 +69,39 @@ func TestResignTrailingPlayerLoses(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestResignSeatOffTurn covers a forfeit on the opponent's turn: after player 0
|
||||
// moves it is player 1's turn, yet player 0 resigns its own seat — the resigner
|
||||
// loses, the opponent wins, and the game ends.
|
||||
func TestResignSeatOffTurn(t *testing.T) {
|
||||
g := openingGame(t)
|
||||
|
||||
hint, ok := g.HintView()
|
||||
if !ok {
|
||||
t.Fatal("opening game has no hint")
|
||||
}
|
||||
if _, err := g.SubmitPlay(hint.Dir, hint.Tiles); err != nil { // player 0 moves
|
||||
t.Fatalf("player 0 play: %v", err)
|
||||
}
|
||||
if g.ToMove() != 1 {
|
||||
t.Fatalf("after player 0's move, toMove = %d, want 1", g.ToMove())
|
||||
}
|
||||
|
||||
// Player 0 resigns although it is player 1's turn.
|
||||
rec, err := g.ResignSeat(0)
|
||||
if err != nil {
|
||||
t.Fatalf("player 0 off-turn resign: %v", err)
|
||||
}
|
||||
if rec.Player != 0 || rec.Action != ActionResign {
|
||||
t.Errorf("resign record = seat %d action %v, want seat 0 resign", rec.Player, rec.Action)
|
||||
}
|
||||
if !g.Over() || g.Reason() != EndResign {
|
||||
t.Fatalf("game over=%v reason=%v, want over with resign", g.Over(), g.Reason())
|
||||
}
|
||||
if res := g.Result(); res.Winner != 1 {
|
||||
t.Errorf("winner = %d, want 1 (the non-resigner)", res.Winner)
|
||||
}
|
||||
}
|
||||
|
||||
// TestResignOnFinishedGame rejects a second transition.
|
||||
func TestResignOnFinishedGame(t *testing.T) {
|
||||
g := newEnglishGame(t, 1)
|
||||
|
||||
Reference in New Issue
Block a user