MCPcopy Create free account
hub / github.com/code100x/chess / Game

Class Game

apps/ws/src/Game.ts:41–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41export class Game {
42 public gameId: string;
43 public player1UserId: string;
44 public player2UserId: string | null;
45 public board: Chess;
46 private moveCount = 0;
47 private timer: NodeJS.Timeout | null = null;
48 private moveTimer: NodeJS.Timeout | null = null;
49 public result: GAME_RESULT | null = null;
50 private player1TimeConsumed = 0;
51 private player2TimeConsumed = 0;
52 private startTime = new Date(Date.now());
53 private lastMoveTime = new Date(Date.now());
54
55 constructor(player1UserId: string, player2UserId: string | null, gameId?: string, startTime?: Date) {
56 this.player1UserId = player1UserId;
57 this.player2UserId = player2UserId;
58 this.board = new Chess();
59 this.gameId = gameId ?? randomUUID();
60 if (startTime) {
61 this.startTime = startTime;
62 this.lastMoveTime = startTime;
63 }
64 }
65
66 seedMoves(moves: {
67 id: string;
68 gameId: string;
69 moveNumber: number;
70 from: string;
71 to: string;
72 comments: string | null;
73 timeTaken: number | null;
74 createdAt: Date;
75 }[]) {
76 console.log(moves);
77 moves.forEach((move) => {
78 if (
79 isPromoting(this.board, move.from as Square, move.to as Square)
80 ) {
81 this.board.move({
82 from: move.from,
83 to: move.to,
84 promotion: 'q',
85 });
86 } else {
87 this.board.move({
88 from: move.from,
89 to: move.to,
90 });
91 }
92 });
93 this.moveCount = moves.length;
94 if (moves[moves.length - 1]) {
95 this.lastMoveTime = moves[moves.length - 1].createdAt;
96 }
97
98 moves.map((move, index) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected