Commit Graph

94 Commits

Author SHA1 Message Date
Janis 03c3b90d06 refactor(tests): streamline test cases for ApiResponse, Board, GameContext, Piece, and Square 2026-04-05 22:10:13 +02:00
Janis 3cec5b8898 refactor(tests): enhance test coverage for move application and piece movement logic 2026-04-05 22:03:40 +02:00
Janis 4cf39e3e97 refactor(core): enhance castling logic to include rook movement and improve safety checks 2026-04-05 19:17:23 +02:00
Janis 2cd3ea35f6 refactor(tests): improve FEN and PGN parser test cases for clarity and coverage 2026-04-05 18:41:26 +02:00
Janis 08a8778227 refactor(core): optimize castling move logic and enhance move notation methods
Build & Test (NowChessSystems) TeamCity build failed
2026-04-05 17:58:09 +02:00
Janis 0778882db6 refactor(core): simplify castling logic and improve move translation methods
Build & Test (NowChessSystems) TeamCity build failed
2026-04-05 17:48:06 +02:00
Janis 1fc5e43e77 refactor(core): enhance MoveType to support capture flag and update related logic
Build & Test (NowChessSystems) TeamCity build failed
2026-04-05 17:28:56 +02:00
Janis 432385c7b0 refactor(core): replace GameHistory with HistoryMove in PGN export logic 2026-04-05 17:08:54 +02:00
Janis a1b7cc7f4a refactor(core): streamline FEN and PGN export/import methods in ChessBoardView 2026-04-05 17:01:34 +02:00
Janis 17fa13c82a test(core): add GameEngineLoadGameTest for loadGame/exportGame
Add 3 focused tests for GameEngine load/export functionality:
- loadGame with PgnParser validates PGN parsing and undo/redo state
- loadGame with FenParser validates position loading without move replay
- exportGame with PgnExporter validates PGN output

Fix: PgnParser now extends GameContextImport trait for consistency with FenParser.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 15:22:04 +02:00
Janis e88f502ffc refactor(core): add loadGame/exportGame, remove loadPgn from GameEngine
- Add imports for GameContextImport and GameContextExport
- Add loadGame(importer, input) method to load game from importer
- Add exportGame(exporter) method to export current game context
- Remove entire loadPgn method (replaced by loadGame)
- Remove GameEngineLoadPgnTest (tests old loadPgn API)

loadGame supports both move replay and direct position loading:
- If no moves, sets position directly via loadPosition
- If moves exist, replays through command system for undo/redo support
- Notifies PgnLoadedEvent on success

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 14:51:33 +02:00
Janis 8b5303fdab test(io): add exportGameContext tests
Add two simple tests for exportGameContext functionality:
1. Test that moves are preserved in PGN output
2. Test that empty game exports headers with proper terminator

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:45:25 +02:00
Janis 16a9632e69 fix(io): add error handling for missing piece in PgnExporter replay
Replace unsafe fallback to Pawn with explicit exception on invariant
violation. This ensures data corruption in GameContext.moves is detected
immediately rather than producing silently incorrect PGN output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:22:13 +02:00
Janis 09a70ed435 feat(io): implement PgnExporter.exportGameContext with move replay
PgnExporter now extends GameContextExport and implements exportGameContext,
which replays moves from GameContext.initial to reconstruct HistoryMove records
with proper castling/promotion info before generating PGN.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:20:59 +02:00
Janis f0316013fc test(io): add importGameContext tests to PgnParserTest
Added three test cases to validate importGameContext method:
1. Valid PGN with moves returns Right with populated GameContext
2. Invalid PGN (illegal move) returns Left with error message
3. PGN with no moves returns Right with initial position

Tests use coordinate notation (e.g., e2e4) compatible with importGameContext's move replay mechanism.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:19:55 +02:00
Janis 2d07f1f75a refactor(io): remove dead code from PgnParser.importGameContext
Remove unnecessary if/else check (lines 49-50) that could never be true.
DefaultRules.applyMove always calls .withMove(move) on the context,
so finalCtx.moves is always populated when game.moves.nonEmpty.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:15:41 +02:00
Janis 7c42260d14 feat(io): implement PgnParser.importGameContext with move replay
Implement the importGameContext method to validate PGN input via validatePgn()
and replay each move using DefaultRules.applyMove to populate GameContext.moves.
Returns final GameContext with all moves applied or error message on failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:14:25 +02:00
Janis 9f48f7afeb test(io): add comprehensive error path coverage to FenParserTest
Added 3 new tests for missing error paths:
- Invalid en passant square parsing (e.g., "x5")
- Half-move clock non-integer (e.g., "abc")
- Full-move number non-integer (e.g., "abc")

Updated 3 existing error tests to verify error messages:
- "expected 6" for invalid parts count
- "color" for invalid active color
- "castling" for invalid castling rights

All error assertions now use .fold() to verify message content, improving test robustness. Test count increased from 19 to 22.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:12:19 +02:00
Janis 3214386556 fix(io): update FEN tests to use Either API after parseFen signature change
FenParser.parseFen now returns Either[String, GameContext] instead of Option.
Updated all tests to use Either combinators (isRight, isLeft, fold) instead
of Option methods (isDefined, get). Both FenParserTest and FenExporterTest
now properly handle the Either-based return type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:10:24 +02:00
Janis c0a3592d3d refactor(io): implement FenParser.parseFen returning Either with detailed error messages
Update parseFen to return Either[String, GameContext] with specific error messages for each validation failure:
- Invalid parts count: reports expected 6 fields
- Invalid board: clear message about board position
- Invalid color: explains expected 'w' or 'b'
- Invalid castling, en passant, and move counts with clear descriptions

Simplify importGameContext to delegate directly to parseFen.

Keep helper methods (parseColor, parseCastling, parseEnPassant, etc.) returning Option as before.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 12:58:15 +02:00
Janis 6fcb880b93 fix(io): update GameContextExport to Scala 3 syntax and add importGameContext tests
- Update GameContextExport trait to use Scala 3 syntax (colon-based) to match GameContextImport
- Add test coverage for FenParser.importGameContext method:
  * Valid FEN string returns Right[GameContext] with correct context data
  * Invalid FEN string returns Left[String] with error message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 12:43:25 +02:00
Janis f6f05ff2a1 refactor(io): change GameContextImport return type from Option to Either
Update GameContextImport trait to return Either[String, GameContext] instead of
Option[GameContext] to provide better error context during parsing. Update FenParser
implementation to convert Option to Either using toRight().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 12:33:13 +02:00
Janis e2fe56ea87 docs: add IO interface refactor design spec
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 09:33:50 +02:00
Janis fa5cdf4e9c refactor(core): enhance GameEngine and GUI for undo/redo functionality and integrate FEN/PGN export/import
Build & Test (NowChessSystems) TeamCity build failed
2026-04-04 21:02:39 +02:00
Janis 9b3bbfbcb7 refactor(core): integrate Rule module and update GameContext handling 2026-04-04 20:25:20 +02:00
Janis 6def31dd80 refactor(core): add IO module and integrate GameContext import/export traits 2026-04-04 19:50:08 +02:00
Janis c08e5f8c62 refactor(core): migrate GameState to GameContext and update FEN handling
Build & Test (NowChessSystems) TeamCity build failed
2026-04-04 17:55:08 +02:00
Janis 6283db85c0 refactor(core): add tests for GameEngine move notation and event handling
Build & Test (NowChessSystems) TeamCity build failed
2026-04-04 17:36:15 +02:00
Janis 9e5ef5a059 refactor(core): NCS-22 update GameEngine to use GameContext and integrate Rule module
Build & Test (NowChessSystems) TeamCity build failed
2026-04-04 17:11:53 +02:00
Janis 3d9a108bdc refactor(core): NCS-22 update GameEngine to use GameContext and integrate Rule module
Build & Test (NowChessSystems) TeamCity build failed
2026-04-04 17:11:11 +02:00
Janis b184d50265 refactor(core): cleanup UI and notation imports for NCS-22 interface abstraction
Build & Test (NowChessSystems) TeamCity build failed
- Removed unused CastleSide import from PgnExporter
- Updated TerminalUI and GUIObserver to use GameContext
- Temporarily disabled GUI FEN/PGN import-export (requires full rework with GameContext)
- Deleted unused logic files and GameController per spec

Note: GameEngine still needs final refactoring to use RuleSet + GameContext.
Core architecture (api -> rule -> core) is structurally complete.
2026-04-03 17:16:40 +02:00
Janis 2b23b62b74 refactor(core): delete GameController (replaced by GameEngine + RuleSet) 2026-04-03 17:15:44 +02:00
Janis 7516828fb1 refactor(core): remove duplicate logic files (moved to StandardRules) 2026-04-03 17:12:57 +02:00
Janis cd6cce163d refactor(core): remove GameController, update events to GameContext, verify build
Task 6: Updated all GameEvent case classes to use context: GameContext instead of separate board/history/turn
Task 7: Deleted old logic files and restored as compatibility layer in modules/api
Task 8: Verified build - main source compilation succeeds

Changes:
- Updated Observer.scala events: all GameEvent subclasses now accept GameContext
- Restored GameHistory and HistoryMove to modules/api as compatibility types
- Restored logic files (GameRules, MoveValidator, etc.) with updated imports
- Updated GameEngine to use currentContext helper for event creation
- Updated GameController to convert CastleSide to String for HistoryMove
- Updated PgnParser/PgnExporter to work with String representation of castling
- Added modules:rule to settings.gradle.kts for dependency resolution
- All main source code compiles successfully; tests expected to need refactoring

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-04-03 17:10:03 +02:00
Janis 8d9996bfed build: configure rule module and add dependency from core
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-04-03 13:17:21 +02:00
Janis c59cc2ddcf refactor(rule): implement StandardRules with GameContext 2026-04-03 13:11:20 +02:00
Janis 60e43027fa refactor(rule): update RuleSet to use GameContext
Replace Situation parameter with GameContext across all RuleSet methods
to align with the new game state abstraction. Updated imports to use the
api module's types (GameContext, Square, Move).

StandardRules will need to be updated in Task 3 to implement the new
interface signature and use api types instead of maichess.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-04-03 12:57:45 +02:00
Janis 8a198cbdf6 feat(api): add immutable GameContext type
Bundles complete game state (board, turn, castling rights, en passant, halfMoveClock, moves)
with immutable builder methods for functional state transitions.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-04-03 12:49:47 +02:00
TeamCity 51ffd7aac9 ci: bump version with Build-28 2026-04-03 09:09:16 +00:00
Janis 1b9eb471de fix: set PYTHONUTF8 environment variable for coverage scripts (#16)
Build & Test (NowChessSystems) TeamCity build finished
Reviewed-on: #16
Co-authored-by: Janis <janis.e.20@gmx.de>
Co-committed-by: Janis <janis.e.20@gmx.de>
core-0.10.0 ui-0.5.0 api-0.2.0
2026-04-03 11:03:02 +02:00
TeamCity 45013c87a9 ci: bump version with Build-27 2026-04-02 19:15:54 +00:00
Janis 80518719d5 feat: NCS-21 Write Scripts to automate certain tasks (#15)
Build & Test (NowChessSystems) TeamCity build finished
Co-authored-by: shahdlala66 <shahd.lala66@gmail.com>
Reviewed-on: #15
Co-authored-by: Janis <janis.e.20@gmx.de>
Co-committed-by: Janis <janis.e.20@gmx.de>
api-0.1.0 ui-0.4.0 core-0.9.0
2026-04-02 21:11:21 +02:00
TeamCity 2d6ead7e47 ci: bump version with Build-26 2026-04-01 20:53:08 +00:00
Janis 3ff80318b4 feat: NCS-17 Implement basic ScalaFX UI (#14)
Build & Test (NowChessSystems) TeamCity build finished
Co-authored-by: shahdlala66 <shahd.lala66@gmail.com>
Reviewed-on: #14
Co-authored-by: Janis <janis.e.20@gmx.de>
Co-committed-by: Janis <janis.e.20@gmx.de>
api-0.0.8 ui-0.3.0 core-0.8.0
2026-04-01 22:48:30 +02:00
TeamCity 9fb743d135 ci: bump version with Build-25 2026-04-01 08:40:41 +00:00
lq64 412ed986a9 feat: NCS-11 50-move rule (#9)
Build & Test (NowChessSystems) TeamCity build finished
Summary

  - Implements the FIDE 50-move draw rule: a player may claim a draw if no pawn move or capture has occurred in the last
   50 full moves (100 half-moves)
  - Draw is not automatic — the eligible player must claim it via a TUI menu shown at the start of their turn
  - halfMoveClock: Int is threaded through processMove and gameLoop; resets on pawn move, capture, or en passant;
  increments on all other moves

  Changes

  - GameController.scala: extended MoveResult.Moved and MoveResult.MovedInCheck with newHalfMoveClock: Int; added
  MoveResult.DrawClaimed; added halfMoveClock parameter to processMove and gameLoop; TUI menu shown when clock ≥ 100
  - Main.scala: initial gameLoop call passes halfMoveClock = 0
  - GameControllerTest.scala: updated all existing pattern matches; added 10 new tests covering clock reset, clock
  increment, draw claim, and TUI menu behaviour

  Test plan

  - processMove: 'draw' with halfMoveClock = 100 → DrawClaimed
  - processMove: 'draw' with halfMoveClock = 99 → InvalidFormat
  - Pawn move / capture / en passant → clock resets to 0
  - Quiet piece move → clock increments by 1
  - MovedInCheck carries updated clock
  - TUI menu appears when clock ≥ 100; option 1 claims draw, option 2 continues
  - No TUI menu when clock < 100
  - All 197 tests passing

Co-authored-by: LQ63 <lkhermann@web.de>
Reviewed-on: #9
Co-authored-by: Leon Hermann <lq@blackhole.local>
Co-committed-by: Leon Hermann <lq@blackhole.local>
ui-0.2.0 core-0.7.0 api-0.0.7
2026-04-01 10:36:24 +02:00
TeamCity 8bbeead702 ci: bump version with Build-24 2026-04-01 07:17:44 +00:00
Janis e5e20c566e fix: update move validation to check for king safety (#13)
Build & Test (NowChessSystems) TeamCity build finished
Reviewed-on: #13
core-0.6.0 api-0.0.6 ui-0.1.0
2026-04-01 09:07:06 +02:00
Janis 13bfc16cfe feat: NCS-10 Implement Pawn Promotion (#12)
Build & Test (NowChessSystems) TeamCity build finished
Reviewed-on: #12
Reviewed-by: Leon Hermann <lq@blackhole.local>
Co-authored-by: Janis <janis-e@gmx.de>
Co-committed-by: Janis <janis-e@gmx.de>
2026-03-31 22:18:14 +02:00
TeamCity 85cbf95c18 ci: bump version with Build-22 2026-03-31 08:35:28 +00:00