Skip to content

Add stalemate detection, castling validation, move history tracking, PGN export, and draw detection#28

Merged
mgierschdev merged 5 commits intomainfrom
copilot/add-stalemate-detection
Dec 22, 2025
Merged

Add stalemate detection, castling validation, move history tracking, PGN export, and draw detection#28
mgierschdev merged 5 commits intomainfrom
copilot/add-stalemate-detection

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 21, 2025

Chess Engine Enhancement - Complete ✅

All required features have been successfully implemented and tested:

✅ Completed Features

  1. Stalemate Detection

    • Implemented isStalemate() in Chessboard class
    • Added DrawByStalemate state to GameState enum
    • Integrated into game flow in ChessGame.MoveController()
    • Full test coverage in DrawDetectionTest
  2. Castling with Full Validation

    • Implemented kingside and queenside castling for both colors
    • Validates all castling rules:
      • King and rook haven't moved
      • No pieces between king and rook
      • King not in check
      • King doesn't move through check
      • King doesn't land in check
    • Track piece movements to prevent illegal castling
    • Comprehensive test coverage in CastlingTest (7 tests)
    • Enabled previously disabled testCastlingThroughCheckIsRejected() test
  3. Pinned Piece Validation

    • Already implemented via filterMovesLeavingKingInCheck()
    • All edge cases handled correctly
    • Test testPinnedPieceCannotExposeKing() passes
  4. Move History Tracking

    • Created Move class to represent chess moves
    • Tracks all moves in ChessGame.moveHistory
    • Records piece, positions, captures, promotions, special moves
    • API endpoint /moveHistory to retrieve history
    • Used for PGN export and draw detection
  5. PGN Export

    • Created PGNExporter utility class
    • Implements standard PGN format with headers
    • Converts moves to algebraic notation
    • Handles castling notation (O-O, O-O-O)
    • Handles pawn captures, promotions
    • Determines game result (1-0, 0-1, 1/2-1/2, *)
    • API endpoint /exportPGN to get PGN string
    • Test coverage in PGNExporterTest (4 tests)
  6. Draw Detection

    • Stalemate: Player not in check with no legal moves
    • 50-move rule: Tracks half-moves since pawn move or capture
    • Threefold repetition: Simplified board hash comparison
    • Added draw states: DrawByStalemate, DrawByRepetition, DrawByFiftyMove
    • All integrated into move validation

📊 Test Results

  • Total Tests: 40 (all passing ✅)
  • No regressions in existing functionality
  • CodeQL Security Scan: 0 alerts ✅

🔧 API Additions

  • GET /moveHistory - Returns list of all moves
  • GET /exportPGN - Returns game in PGN format

📝 Technical Details

  • Avoided infinite recursion in castling validation by separating getCandidateMoves() from getValidMoves()
  • Castling moves validated separately from normal king moves
  • Proper tracking of piece movements for castling eligibility
  • Move history enables future features like game replay and analysis

📖 Documentation Updates

  • Updated README to reflect all implemented features
  • Moved completed features from "Future Improvements" to "Recently Implemented"
  • Added new API endpoints to REST API documentation with example curl commands
  • Updated main feature description to highlight new capabilities (stalemate, draw conditions, move history)
  • Removed completed items from "Known Limitations" section
Original prompt

This is a must, please develop:

  •  Stalemate Detection - Currently not implemented
  •  Castling Through Check - May not be fully validated (see ChessRulesTest)
  •  Pinned Piece Validation - Edge cases may exist (see ChessRulesTest)
  •  Move History - Track all moves in a game
  •  PGN Export - Save games in standard chess notation
     Move History Export - No PGN/FEN notation support
    Draw Detection - Stalemate, threefold repetition, 50-move rule not implemented
    Castling Through Check - May not be fully validated (see ChessRulesTest)
    Pinned Piece Validation - Edge cases may exist (see ChessRulesTest)
    Move History - Track all moves in a game
    PGN Export - Save games in standard chess notation
    Castling Through Check - May not be fully validated (see ChessRulesTest)
    Pinned Piece Validation - Edge cases may exist (see ChessRulesTest)
    Move History - Track all moves in a game
    PGN Export - Save games in standard chess notation

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Dec 21, 2025
Copilot AI and others added 3 commits December 21, 2025 21:31
Co-authored-by: mgierschdev <62764972+mgierschdev@users.noreply.github.com>
Co-authored-by: mgierschdev <62764972+mgierschdev@users.noreply.github.com>
Co-authored-by: mgierschdev <62764972+mgierschdev@users.noreply.github.com>
@mgierschdev
Copy link
Copy Markdown
Owner

@copilot Continue where you left

Co-authored-by: mgierschdev <62764972+mgierschdev@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 22, 2025

@copilot Continue where you left

I've completed the implementation by updating the README documentation to reflect all the features that were implemented:

✅ Updated main feature list to include stalemate, draw conditions, and move history
✅ Moved completed features from "Future Improvements" to "Recently Implemented" section
✅ Added new API endpoints (/moveHistory and /exportPGN) to REST API documentation
✅ Added example curl commands for the new endpoints
✅ Removed completed items from "Known Limitations"

All features are now fully implemented, tested (40 tests passing), and documented. The PR is ready for review. Commit: f3f3302

Copilot AI changed the title [WIP] Add stalemate detection and implement move history tracking Add stalemate detection, castling validation, move history tracking, PGN export, and draw detection Dec 22, 2025
@mgierschdev mgierschdev marked this pull request as ready for review December 22, 2025 03:46
@mgierschdev mgierschdev merged commit 8e4a803 into main Dec 22, 2025
8 checks passed
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.

2 participants