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>
This commit is contained in:
2026-04-03 12:49:47 +02:00
parent 51ffd7aac9
commit 8a198cbdf6
4 changed files with 388 additions and 0 deletions
@@ -0,0 +1,29 @@
package de.nowchess.rules
import de.nowchess.chess.{Move, Situation, Square}
/** Extension point for chess rule variants. Implement to support Chess960, etc. */
trait RuleSet:
/** All pseudo-legal moves for the piece on `square` (ignores check). */
def candidateMoves(situation: Situation, square: Square): List[Move]
/** Legal moves for `square`: candidates that don't leave own king in check. */
def legalMoves(situation: Situation, square: Square): List[Move]
/** All legal moves for the side to move. */
def allLegalMoves(situation: Situation): List[Move]
/** True if the side to move's king is in check. */
def isCheck(situation: Situation): Boolean
/** True if the side to move is in check and has no legal moves. */
def isCheckmate(situation: Situation): Boolean
/** True if the side to move is not in check and has no legal moves. */
def isStalemate(situation: Situation): Boolean
/** True if neither side has enough material to checkmate. */
def isInsufficientMaterial(situation: Situation): Boolean
/** True if halfMoveClock >= 100 (50-move rule). */
def isFiftyMoveRule(situation: Situation): Boolean