refactor(core): replace GameHistory with HistoryMove in PGN export logic

This commit is contained in:
2026-04-05 17:08:54 +02:00
parent a1b7cc7f4a
commit 432385c7b0
13 changed files with 110 additions and 218 deletions
@@ -1,51 +0,0 @@
package de.nowchess.api.game
import de.nowchess.api.board.{PieceType, Square}
import de.nowchess.api.move.{Move, PromotionPiece}
/** A single move recorded in the game history. Distinct from api.move.Move which represents user intent. */
case class HistoryMove(
from: Square,
to: Square,
castleSide: Option[String] = None,
promotionPiece: Option[PromotionPiece] = None,
pieceType: PieceType = PieceType.Pawn,
isCapture: Boolean = false
)
/** Complete game history: ordered list of moves plus the half-move clock for the 50-move rule.
*
* @param moves moves played so far, oldest first
* @param halfMoveClock plies since the last pawn move or capture (FIDE 50-move rule counter)
*
* Deprecated: Use GameContext instead. This exists for compatibility during migration.
*/
case class GameHistory(moves: List[HistoryMove] = List.empty, halfMoveClock: Int = 0):
/** Add a raw HistoryMove record. Clock increments by 1.
* Use the coordinate overload when you know whether the move is a pawn move or capture.
*/
def addMove(move: HistoryMove): GameHistory =
GameHistory(moves :+ move, halfMoveClock + 1)
/** Add a move by coordinates.
*
* @param wasPawnMove true when the moving piece is a pawn — resets the clock to 0
* @param wasCapture true when a piece was captured (including en passant) — resets the clock to 0
*
* If neither flag is set the clock increments by 1.
*/
def addMove(
from: Square,
to: Square,
castleSide: Option[String] = None,
promotionPiece: Option[PromotionPiece] = None,
wasPawnMove: Boolean = false,
wasCapture: Boolean = false,
pieceType: PieceType = PieceType.Pawn
): GameHistory =
val newClock = if wasPawnMove || wasCapture then 0 else halfMoveClock + 1
GameHistory(moves :+ HistoryMove(from, to, castleSide, promotionPiece, pieceType, wasCapture), newClock)
object GameHistory:
val empty: GameHistory = GameHistory()
@@ -0,0 +1,15 @@
package de.nowchess.api.game
import de.nowchess.api.board.{PieceType, Square}
import de.nowchess.api.move.PromotionPiece
/** A single move recorded in game history and PGN workflows. */
case class HistoryMove(
from: Square,
to: Square,
castleSide: Option[String] = None,
promotionPiece: Option[PromotionPiece] = None,
pieceType: PieceType = PieceType.Pawn,
isCapture: Boolean = false
)