Skip to content

Implement Check Detection System#79

Open
walshb421 wants to merge 6 commits into
mainfrom
issue-76-check-detection
Open

Implement Check Detection System#79
walshb421 wants to merge 6 commits into
mainfrom
issue-76-check-detection

Conversation

@walshb421
Copy link
Copy Markdown
Owner

Summary

This PR implements a comprehensive check detection system for the chess engine, addressing issue #76.

New Methods Added to ChessBoard

  • get_king_position(color): Returns the (row, col) tuple of the specified color king
  • is_square_attacked(square, by_color): Returns True if any piece of the attacking color can reach the given square
  • is_in_check(color): Returns True if the king of the specified color is currently in check
  • would_be_in_check(move, color): Simulates a move and checks if it would leave the king in check

Updated Move Validation

  • can_move_piece(): Now filters out any move that would leave the king in check
  • castling_check(): Updated to enforce all castling rules (cannot castle out of, through, or into check)

Game State

  • Added in_check boolean to the game state JSON

How to Test

  1. Basic Check Detection

    • Load FEN: rnbqkbnr/pppp1ppp/8/4p3/6P1/5P2/PPPPP2P/RNBQKBNR b KQkq - 0 2
    • Move black queen to h4 (Qh4+) - white king should be in check
    • White should only be able to make moves that escape check
  2. Pinned Piece

    • Load FEN: rnb1kbnr/pppp1ppp/8/4p3/7q/5NP1/PPPPP2P/RNBQKB1R w KQkq - 0 3
    • The g3 pawn is pinned - try moving it (should be blocked)
  3. Castling Through Check

    • Load FEN: r3k2r/pppp1ppp/8/4p3/1b6/8/PPPPPPPP/R3K2R w KQkq - 0 1
    • White cannot castle queenside (d1 is attacked by bishop)

Closes #76

MCP Agent added 6 commits January 11, 2026 01:28
Add engine/fixtures.py with predefined chess positions for testing:
- Basic positions (starting, empty)
- Checkmate scenarios
- Special moves (en passant, castling)
- Check scenarios
- Pawn promotion positions
- Stalemate and endgame positions
- Add load_fen() method to parse FEN strings and set board state
- Add to_fen() method to export current position as FEN
- Add WebSocket callbacks for load_fen, load_fixture, get_fixtures
- Track en_passant_target for FEN compatibility
- Include turn and FEN in game state JSON
- Update en passant logic to work with FEN-loaded positions
- Convert indentation from tabs to spaces
- Add loadFen() to load arbitrary FEN positions
- Add loadFixture() to load named test fixtures
- Add getFixtures() to request fixture list from server
- Add reactive refs for turn, currentFen, and fixtures
- Update data watcher to handle new state fields
- Display current game state (turn, player, move number)
- Show current FEN with copy-to-clipboard button
- FEN input field to load arbitrary positions
- Dropdown with categorized test fixtures
- Reset board button
- Dark theme styling to match app
- Add DebugPanel component with toggle visibility
- Press D key to show/hide debug panel
- Add sidebar layout for debug panel
- Ignore keypress when typing in input fields
Base automatically changed from add-fen-support to main March 23, 2026 02:24
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