feat: implement legal castling #1

Merged
Janis merged 12 commits from castling into main 2026-03-24 17:55:01 +01:00
Owner

Summary

  • Introduces GameContext wrapper (board + castling rights) threading through the entire engine pipeline
  • Extends MoveValidator with castlingTargets, context-aware legalTargets/isLegal overloads, and helpers (isCastle, castleSide)
  • Updates GameRules.legalMoves and gameStatus to use GameContext, preventing false stalemate when castling is the only legal move
  • Adds castle detection and atomic execution (withCastle) to GameController.processMove, plus full rights revocation via source- and
    destination-square tables

Test Plan

  • 142 tests passing, 100% statement and branch coverage on modules/core
  • White/Black kingside (e1g1/e8g8) and queenside (e1c1/e8c8) castling moves execute correctly
  • All six legality conditions enforced (rights flags, home squares, empty transit, king not in check, transit/landing squares not attacked)
  • Rights revoked on king moves, own rook moves, castle moves, and enemy rook captures
  • False stalemate correctly prevented when castling is the only escape
## Summary - Introduces `GameContext` wrapper (board + castling rights) threading through the entire engine pipeline - Extends `MoveValidator` with `castlingTargets`, context-aware `legalTargets`/`isLegal` overloads, and helpers (`isCastle`, `castleSide`) - Updates `GameRules.legalMoves` and `gameStatus` to use `GameContext`, preventing false stalemate when castling is the only legal move - Adds castle detection and atomic execution (`withCastle`) to `GameController.processMove`, plus full rights revocation via source- and destination-square tables ## Test Plan - [ ] 142 tests passing, 100% statement and branch coverage on `modules/core` - [ ] White/Black kingside (e1g1/e8g8) and queenside (e1c1/e8c8) castling moves execute correctly - [ ] All six legality conditions enforced (rights flags, home squares, empty transit, king not in check, transit/landing squares not attacked) - [ ] Rights revoked on king moves, own rook moves, castle moves, and enemy rook captures - [ ] False stalemate correctly prevented when castling is the only escape
lq64 added 11 commits 2026-03-24 17:05:37 +01:00
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Introduces GameContext (board + per-side CastlingRights), CastleSide enum,
and a Board.withCastle extension method. Also pins missing verification
checksums for com.fasterxml:oss-parent:41 and org.junit:junit-bom:5.9.2.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Switch legalMoves to the context-aware MoveValidator.legalTargets(ctx, from)
so castling destinations are included, and simulate castle moves via withCastle
when filtering for self-check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- gameStatus now accepts GameContext instead of Board so legalMoves
  (which already requires GameContext for castling) is called directly
  without discarding castling rights
- All four existing gameStatus call sites in GameRulesTest migrated to ctx(...)
- New test: castling as sole legal move returns Normal, not Drawn
- GameController.processMove updated to wrap newBoard in GameContext at
  the gameStatus call site (full ctx propagation deferred to Task 6)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
refactor: migrate GameController to GameContext (signatures only)
Build & Test (NowChessSystems) TeamCity build finished
62e180c6d9
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Detect castle moves via MoveValidator.isCastle and dispatch to
Board.withCastle so both king and rook are moved atomically.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
feat: add castling rights revocation to processMove
Build & Test (NowChessSystems) TeamCity build finished
b0141d2c89
Introduces applyRightsRevocation helper that revokes rights on castle
moves, king/rook departures from home squares, and enemy captures on
rook home squares. Six new tests verify all revocation paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Janis approved these changes 2026-03-24 17:36:29 +01:00
Janis added 1 commit 2026-03-24 17:46:03 +01:00
chore: Merge remote-tracking branch 'origin/main' into castling
Build & Test (NowChessSystems) TeamCity build finished
4a7813f4ff
Janis merged commit 00d326c1ba into main 2026-03-24 17:55:01 +01:00
Janis deleted branch castling 2026-03-24 17:55:01 +01:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NowChess/NowChessSystems#1