Commit Graph

43 Commits

Author SHA1 Message Date
Janis c75a3a28af test: add tests for undo and redo notifications in GameEngine
Build & Test (NowChessSystems) TeamCity build finished
2026-03-31 09:34:39 +02:00
Janis 40086a331f fix: improve TerminalUI coverage and make MoveCommand/ResetCommand immutable
**TerminalUI Coverage Fix:**
- Added explicit test for empty input case (lines 64-65 previously uncovered)
- Test "TerminalUI should explicitly handle empty input by re-prompting" validates
  that multiple empty inputs are properly handled by re-prompting
- UI module coverage improved to near-100%

**MoveCommand Immutability (Anti-pattern Fix):**
- Changed MoveCommand fields from var to val: moveResult, previousBoard,
  previousHistory, previousTurn
- Changed ResetCommand fields from var to val: previousBoard, previousHistory,
  previousTurn
- Updated GameEngine to use .copy() instead of direct mutation when updating
  command state (lines 88, 95, 103, 112)
- Removed 3 edge-case tests that relied on command mutation (now impossible with
  immutable fields)

**MoveCommand Immutability Tests:**
- Added MoveCommandImmutabilityTest to verify:
  - Fields cannot be mutated after creation
  - equals/hashCode respect immutability invariant
  - .copy() creates new instances with updated values

All tests pass; 100% core coverage maintained.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-31 08:43:44 +02:00
Janis 8f64273ceb fix: add thread-safety synchronization to Observable and CommandInvoker
Test-driven fixes for code review blockers NCS-16:

**Observable (CRITICAL):** Added synchronized blocks to subscribe, unsubscribe,
notifyObservers, and observerCount to prevent race conditions when concurrent
threads register observers while notifications are dispatched.

**CommandInvoker (IMPORTANT):** Added synchronized blocks to all methods
(execute, undo, redo, history, getCurrentIndex, canUndo, canRedo, clear) to
ensure atomic access to mutable state (executedCommands, currentIndex).

Tests:
- Added ObservableThreadSafetyTest: 3 tests for concurrent subscribe/unsubscribe/notify
- Added CommandInvokerThreadSafetyTest: 2 tests for concurrent execute/undo/redo
- All 54 existing tests remain green
- Full build passes with 100% core coverage

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-31 08:32:15 +02:00
Janis 418e45e805 refactor: simplify undo and redo logic in GameEngine and removed Hacky Test
Build & Test (NowChessSystems) TeamCity build failed
2026-03-30 22:38:13 +02:00
shahdlala66 75f2363517 fix: PR issues fixed
Build & Test (NowChessSystems) TeamCity build failed
2026-03-30 21:48:04 +02:00
shahdlala66 ab96aee3ea test: 100%
Build & Test (NowChessSystems) TeamCity build failed
2026-03-30 21:42:52 +02:00
shahdlala66 5278de96a5 test: reached 99% for GameEngine
Build & Test (NowChessSystems) TeamCity build failed
2026-03-30 00:32:10 +02:00
shahdlala66 f0cd46f132 test: more branch coverage for CommandInvoker
Build & Test (NowChessSystems) TeamCity build finished
2026-03-29 21:08:07 +02:00
shahdlala66 9c1acfc9db feat: undo/redo added 2026-03-29 20:58:33 +02:00
shahdlala66 d2f294294f feat: core sepration, observer added 2026-03-29 20:47:58 +02:00
Janis 7d60c4bb29 feat: enhance FEN and PGN parsers with additional test cases and coverage improvements 2026-03-29 17:49:05 +02:00
Janis 60b02d8f20 style: replace .isDefined/.get with pattern matching in PgnParser
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 17:14:41 +02:00
Janis 9bc1ef550f feat: add PGN exporter for game notation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 17:14:41 +02:00
Janis 98896535ed feat: add PGN parser with algebraic move notation
Implements PgnParser with parsePgn(), parseAlgebraicMove(), and move
resolution using geometric piece reachability with disambiguation support
for piece type, file, and rank hints.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-29 17:13:16 +02:00
Janis 18c712d5c9 feat: add full FEN parsing with GameState support
Implements parseFen() in FenParser and gameStateToFen() in FenExporter,
covering all 6 FEN fields (piece placement, active color, castling,
en passant, half-move clock, full-move number).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 17:12:29 +02:00
Janis ade9d14ddc feat: add FEN exporter and round-trip tests
Implements FenExporter.boardToFen() converting Board to FEN piece-placement string,
and adds three round-trip tests (initial position, empty board, partial position).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 17:11:31 +02:00
Janis 5db1405066 feat: add FEN piece-placement parser
Implements FenParser.parseBoard() to parse FEN piece-placement strings
into a Board, with proper None propagation on invalid input.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 17:11:13 +02:00
lq64 919beb3b4b feat: NCS-9 En passant implementation (#8)
Build & Test (NowChessSystems) TeamCity build finished
- Add EnPassantCalculator to derive the en passant target square from GameHistory, detect en passant captures, and
  compute the captured pawn's square
  - Extend MoveValidator.legalTargets to include the en passant diagonal square in pawn legal targets
  - Extend GameController.processMove to remove the captured pawn from the board when an en passant capture is played

  Details

  En passant is derived purely from the last HistoryMove — no new state is introduced. If the last move was a double
  pawn push, the target square is the square the pawn passed through. The board mutation follows the same pattern as
  castling: board.withMove moves the capturing pawn, then board.removed removes the captured pawn from its actual square
   (which differs from the destination square).

  Test Plan

  - EnPassantCalculatorTest — 14 unit tests covering target derivation, captured square calculation, and capture
  detection for both colors
  - MoveValidatorTest — 5 new tests: ep target included/excluded based on history, adjacency filter, both colors, case _
   branch coverage
  - GameControllerTest — 2 integration tests: white and black en passant capture removes pawn from board and returns
  correct captured piece
  - 100% scoverage (line/branch/method) confirmed

Co-authored-by: LQ63 <lkhermann@web.de>
Reviewed-on: #8
Reviewed-by: Janis <janis-e@gmx.de>
Co-authored-by: Leon Hermann <lq@blackhole.local>
Co-committed-by: Leon Hermann <lq@blackhole.local>
2026-03-29 17:06:50 +02:00
TeamCity ee79dc5b98 ci: bump version with Build-20 2026-03-29 12:06:38 +00:00
Janis f28e69dc18 feat: NCS-6 Implementing FEN & PGN (#7)
Build & Test (NowChessSystems) TeamCity build finished
Reviewed-on: #7
Reviewed-by: Leon Hermann <lq@blackhole.local>
2026-03-29 14:02:25 +02:00
Janis f4c18d22d7 refactor: NCS-8 removed Context and replaced it with History (#6)
Build & Test (NowChessSystems) TeamCity build finished
Reviewed-on: #6
2026-03-28 18:08:55 +01:00
TeamCity 4d800e88eb ci: bump version with Build-18 2026-03-28 12:39:59 +00:00
TeamCity 9190d1e5a0 ci: bump version with v17%
Build & Test (NowChessSystems) TeamCity build finished
2026-03-27 09:25:13 +00:00
Janis d675966436 refactor: replace return/var in castlingTargets with functional style (#4)
Build & Test (NowChessSystems) TeamCity build finished
Reviewed-on: #4
Co-authored-by: Janis <janis.e.20@gmx.de>
Co-committed-by: Janis <janis.e.20@gmx.de>
2026-03-25 08:48:49 +01:00
Janis b4116e9a82 test: add unit tests for API response, board, color, game state, move, piece, and square (#3)
Build & Test (NowChessSystems) TeamCity build finished
Reviewed-on: #3
2026-03-25 08:19:43 +01:00
lq64 00d326c1ba feat: implement legal castling (#1)
Build & Test (NowChessSystems) TeamCity build finished
## 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

Co-authored-by: LQ63 <lkhermann@web.de>
Co-authored-by: Janis <janis.e.20@gmx.de>
Reviewed-on: #1
Reviewed-by: Janis <janis-e@gmx.de>
Co-authored-by: Leon Hermann <lq@blackhole.local>
Co-committed-by: Leon Hermann <lq@blackhole.local>
2026-03-24 17:55:00 +01:00
Janis 7b1f8b1176 fix: update main class path in build configuration and adjust VCS directory mapping
Build & Test (NowChessSystems) TeamCity build finished
2026-03-24 09:59:13 +01:00
Janis aedd787b77 fix: add missing kings to gameLoop capture test board 2026-03-23 22:37:15 +01:00
Janis f0481e2561 fix: correct test board positions and captureOutput/withInput interaction
- Add BlackKing/WhiteKing to capture board in 'legal capture returns Moved'
  so the position is not treated as stalemate after the capture.
- Move WhiteKing from A3 to C3 in three MovedInCheck tests so it no
  longer blocks the rook's path along file A.
- Remove Console.withOut(System.out) from withInput so it no longer
  overrides the ByteArrayOutputStream installed by captureOutput.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 22:32:51 +01:00
Janis 5264a22541 feat: wire check/checkmate/stalemate into processMove and gameLoop
Replace stub branches with GameRules.gameStatus dispatch in processMove
and fill in MovedInCheck/Checkmate/Stalemate cases in gameLoop.
Document 6 pre-existing test bugs in docs/unresolved.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 22:30:09 +01:00
Janis 13ac90a42f test: add failing GameControllerTest cases for check/checkmate/stalemate
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 22:16:53 +01:00
Janis 8b7ec57e5e feat: add MovedInCheck/Checkmate/Stalemate MoveResult variants (stub dispatch)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:48:32 +01:00
Janis 94a02ff684 feat: implement GameRules with isInCheck, legalMoves, gameStatus
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:42:21 +01:00
Janis 86552b52bd test: add failing GameRulesTest for check/checkmate/stalemate
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:34:24 +01:00
Janis 76d4168038 feat: add GameRules stub with PositionStatus enum 2026-03-23 21:29:41 +01:00
Janis fe39d27d91 test: add unit test for clean exit on 'quit' command in Main 2026-03-22 15:31:02 +01:00
Janis 551e08cef3 build: migrate to ScalaTest and Scoverage, replacing JaCoCo across modules 2026-03-22 15:28:02 +01:00
Janis 5a21e57ca9 chore: Update build configuration for Scoverage and ScalaTest integration 2026-03-22 14:19:44 +01:00
Janis 51b210e9eb chore: Update documentation and improve test writing guidelines 2026-03-22 11:47:20 +01:00
Janis a8abd69e0e chore: Add initial implementation of move validation logic and game controller 2026-03-21 21:26:37 +01:00
Janis 1f1d3b670f chore: Refactor chess logic to MVC pattern and enhance board representation 2026-03-21 20:37:33 +01:00
Janis 9c2456e928 chore: Set up shared-models library and initial project structure for NowChessSystems 2026-03-21 17:07:28 +01:00
Janis a8d457a612 chore: Configure Scala build with dependencies and project structure 2026-03-21 15:52:51 +01:00