feat(server): per-viewer capture tally on joined and update messages

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
claude (blind_chess)
2026-05-18 20:09:26 -04:00
parent 0498f1de43
commit ce36755a89
5 changed files with 67 additions and 1 deletions
+3 -1
View File
@@ -1,5 +1,5 @@
import type {
BoardView, Color, GameId, GameStatus, Mode, PlayerToken,
BoardView, CaptureTally, Color, GameId, GameStatus, Mode, PlayerToken,
PromotionType, Square, EndReason,
} from './types.js';
import type { Announcement } from './moderator.js';
@@ -34,6 +34,7 @@ export type ServerMessage =
mode: Mode;
highlightingEnabled: boolean;
opponentConnected: boolean;
captures: CaptureTally;
aiOpponent?: { color: Color; brain: 'casual' | 'recon' };
}
| {
@@ -45,6 +46,7 @@ export type ServerMessage =
drawOffer?: { from: Color } | null;
endReason?: EndReason;
winner?: Color | null;
captures: CaptureTally;
aiOpponent?: { color: Color; brain: 'casual' | 'recon' };
}
| { type: 'peer-status'; color: Color; connected: boolean; graceUntil?: number }
+9
View File
@@ -61,3 +61,12 @@ export function squareAt(fileIdx: number, rankIdx: number): Square | null {
const r = String.fromCharCode('1'.charCodeAt(0) + rankIdx);
return `${f}${r}` as Square;
}
/** Count of pieces by type — used for the capture tally. */
export type PieceTally = Partial<Record<PieceType, number>>;
/** Per-viewer capture tally: what you took, and what you lost. */
export interface CaptureTally {
byYou: PieceTally;
byOpponent: PieceTally;
}