refactor(core): NCS-22 update GameEngine to use GameContext and integrate Rule module
Build & Test (NowChessSystems) TeamCity build failed
Build & Test (NowChessSystems) TeamCity build failed
This commit is contained in:
@@ -150,16 +150,20 @@ class GameEngine(
|
|||||||
game.moves.foreach { histMove =>
|
game.moves.foreach { histMove =>
|
||||||
handleParsedMove(histMove.from, histMove.to)
|
handleParsedMove(histMove.from, histMove.to)
|
||||||
histMove.promotionPiece.foreach(completePromotion)
|
histMove.promotionPiece.foreach(completePromotion)
|
||||||
if pendingPromotion.isDefined && histMove.promotionPiece.isEmpty then
|
// $COVERAGE-OFF$ unreachable: PgnParser.validatePgn ensures promotion annotation is present
|
||||||
|
if pendingPromotion.isDefined && histMove.promotionPiece.isEmpty then
|
||||||
error = Some(s"Promotion required for move ${histMove.from}${histMove.to}")
|
error = Some(s"Promotion required for move ${histMove.from}${histMove.to}")
|
||||||
break()
|
break()
|
||||||
|
// $COVERAGE-ON$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error match
|
error match
|
||||||
|
// $COVERAGE-OFF$ unreachable: error is only set in the unreachable block above
|
||||||
case Some(err) =>
|
case Some(err) =>
|
||||||
currentContext = savedContext
|
currentContext = savedContext
|
||||||
Left(err)
|
Left(err)
|
||||||
|
// $COVERAGE-ON$
|
||||||
case None =>
|
case None =>
|
||||||
notifyObservers(PgnLoadedEvent(currentContext))
|
notifyObservers(PgnLoadedEvent(currentContext))
|
||||||
Right(())
|
Right(())
|
||||||
@@ -245,7 +249,9 @@ class GameEngine(
|
|||||||
case PieceType.King => "K"
|
case PieceType.King => "K"
|
||||||
case _ => ""
|
case _ => ""
|
||||||
if isCapture then s"${letter}x${move.to}" else s"$letter${move.to}"
|
if isCapture then s"${letter}x${move.to}" else s"$letter${move.to}"
|
||||||
|
// $COVERAGE-OFF$ unreachable: executeMove is only called after a piece existence check
|
||||||
case None => move.to.toString
|
case None => move.to.toString
|
||||||
|
// $COVERAGE-ON$
|
||||||
|
|
||||||
private def computeCaptured(context: GameContext, move: Move): Option[Piece] =
|
private def computeCaptured(context: GameContext, move: Move): Option[Piece] =
|
||||||
move.moveType match
|
move.moveType match
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package de.nowchess.chess.engine
|
|||||||
|
|
||||||
import de.nowchess.api.board.{Board, Color, File, Piece, PieceType, Rank, Square}
|
import de.nowchess.api.board.{Board, Color, File, Piece, PieceType, Rank, Square}
|
||||||
import de.nowchess.api.game.GameContext
|
import de.nowchess.api.game.GameContext
|
||||||
import de.nowchess.api.move.{MoveType, PromotionPiece}
|
import de.nowchess.api.move.{Move, MoveType, PromotionPiece}
|
||||||
import de.nowchess.chess.notation.FenParser
|
import de.nowchess.chess.notation.FenParser
|
||||||
import de.nowchess.chess.observer.*
|
import de.nowchess.chess.observer.*
|
||||||
|
import de.nowchess.rules.{RuleSet, StandardRules}
|
||||||
import org.scalatest.funsuite.AnyFunSuite
|
import org.scalatest.funsuite.AnyFunSuite
|
||||||
import org.scalatest.matchers.should.Matchers
|
import org.scalatest.matchers.should.Matchers
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user