diff --git a/packages/Chess/src/Game.ts b/packages/Chess/src/Game.ts index baa9d57..636f96b 100644 --- a/packages/Chess/src/Game.ts +++ b/packages/Chess/src/Game.ts @@ -327,10 +327,16 @@ export class ChessGame { private isInsufficientMaterial(): boolean { const pieces: string[] = []; - for (let row of this.state.board) { - for (let cell of row) { - if (cell !== "" && cell.toLowerCase() !== "k") { - pieces.push(cell); + const bishopPositions: { x: number; y: number }[] = []; + + for (let x = 0; x < 8; x++) { + for (let y = 0; y < 8; y++) { + const piece = this.state.board[x]?.[y]; + if (piece && piece !== "" && piece.toLowerCase() !== "k") { + pieces.push(piece); + if (piece.toLowerCase() === "b") { + bishopPositions.push({ x, y }); + } } } } @@ -343,8 +349,15 @@ export class ChessGame { if (pieces.length === 2) { const [p1, p2] = pieces.map(p => p.toLowerCase()); if (p1 === "b" && p2 === "b") { - // Need to check bishop colors, but basic case = same color bishops - return true; + // Check if bishops are on the same color squares + if (bishopPositions.length === 2) { + const b1 = bishopPositions[0]!; + const b2 = bishopPositions[1]!; + const b1Color = (b1.x + b1.y) % 2; // 0 = light square, 1 = dark square + const b2Color = (b2.x + b2.y) % 2; + return b1Color === b2Color; // Only draw if both bishops are on same color + } + return true; // Default to true if we can't determine positions } }