Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions packages/Chess/src/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
}
}
Expand All @@ -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
}
}

Expand Down