Skip to content

fix: implement proper bishop color detection in insufficient material check#2

Open
nikhilachale wants to merge 1 commit into
mainfrom
session/che-3
Open

fix: implement proper bishop color detection in insufficient material check#2
nikhilachale wants to merge 1 commit into
mainfrom
session/che-3

Conversation

@nikhilachale
Copy link
Copy Markdown
Owner

Summary

Fixed insufficient material draw detection to properly handle bishops on different color squares.

Problem

The previous implementation declared a draw for any two bishops regardless of their square colors. However, bishops on opposite color squares can potentially deliver checkmate in rare positions.

Solution

  • Track bishop positions on the board during insufficient material detection
  • Calculate square colors using (x + y) % 2 formula (0 = light, 1 = dark)
  • Only declare draw when both bishops are on the same color squares
  • Maintain backward compatibility with fallback to draw for edge cases

Changes

  • Modified isInsufficientMaterial() method in packages/Chess/src/Game.ts
  • Added bishop position tracking array
  • Implemented square color calculation
  • Fixed TypeScript type safety issues with non-null assertions

Testing

  • All build, typecheck, and lint checks pass
  • Manual verification of compiled JavaScript confirms logic is correct

Test Plan

  • Build passes: pnpm build
  • Typecheck passes: pnpm check-types
  • Lint passes: pnpm lint
  • Manual verification of bishop color logic

🤖 Generated with Claude Code

… check

Fixed insufficient material draw detection to properly handle bishops
on different color squares. Previously, any two bishops would result
in a draw, but bishops on opposite colors can potentially checkmate
in rare positions.

Changes:
- Track bishop positions on the board
- Calculate square colors using (x + y) % 2
- Only declare draw when bishops are on same color squares
- Maintain backward compatibility with fallback to draw for edge cases

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant