refactor(core): enhance MoveType to support capture flag and update related logic
Build & Test (NowChessSystems) TeamCity build failed
Build & Test (NowChessSystems) TeamCity build failed
This commit is contained in:
@@ -242,8 +242,7 @@ class GameEngine(
|
||||
case PromotionPiece.Bishop => "B"
|
||||
case PromotionPiece.Knight => "N"
|
||||
s"${move.to}=$ppChar"
|
||||
case MoveType.Normal =>
|
||||
val isCapture = boardBefore.pieceAt(move.to).isDefined
|
||||
case MoveType.Normal(isCapture) =>
|
||||
boardBefore.pieceAt(move.from).map(_.pieceType) match
|
||||
case Some(PieceType.Pawn) =>
|
||||
if isCapture then s"${move.from.file.toString.toLowerCase}x${move.to}"
|
||||
|
||||
@@ -158,7 +158,7 @@ class GameEnginePromotionTest extends AnyFunSuite with Matchers:
|
||||
def legalMoves(context: GameContext, square: Square): List[Move] =
|
||||
DefaultRules.legalMoves(context, square).map { m =>
|
||||
m.moveType match
|
||||
case MoveType.Promotion(_) => Move(m.from, m.to, MoveType.Normal)
|
||||
case MoveType.Promotion(_) => Move(m.from, m.to, MoveType.Normal())
|
||||
case _ => m
|
||||
}
|
||||
def allLegalMoves(context: GameContext): List[Move] =
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
package de.nowchess.chess.logic
|
||||
|
||||
import de.nowchess.api.board.*
|
||||
import de.nowchess.api.move.PromotionPiece
|
||||
import de.nowchess.api.game.HistoryMove
|
||||
import org.scalatest.funsuite.AnyFunSuite
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
||||
class HistoryMoveTest extends AnyFunSuite with Matchers:
|
||||
|
||||
private def sq(f: File, r: Rank): Square = Square(f, r)
|
||||
|
||||
test("Move with promotion records the promotion piece"):
|
||||
val move = HistoryMove(sq(File.E, Rank.R7), sq(File.E, Rank.R8), None, Some(PromotionPiece.Queen))
|
||||
move.promotionPiece should be (Some(PromotionPiece.Queen))
|
||||
|
||||
test("Normal move has no promotion piece"):
|
||||
val move = HistoryMove(sq(File.E, Rank.R2), sq(File.E, Rank.R4), None, None)
|
||||
move.promotionPiece should be (None)
|
||||
|
||||
test("HistoryMove default values are compatible with normal pawn move"):
|
||||
val move = HistoryMove(sq(File.E, Rank.R2), sq(File.E, Rank.R4))
|
||||
move.castleSide shouldBe None
|
||||
move.promotionPiece shouldBe None
|
||||
move.pieceType shouldBe PieceType.Pawn
|
||||
move.isCapture shouldBe false
|
||||
|
||||
test("HistoryMove stores castle side and capture marker"):
|
||||
val move = HistoryMove(
|
||||
from = sq(File.E, Rank.R1),
|
||||
to = sq(File.G, Rank.R1),
|
||||
castleSide = Some("Kingside"),
|
||||
pieceType = PieceType.King
|
||||
)
|
||||
move.castleSide shouldBe Some("Kingside")
|
||||
move.pieceType shouldBe PieceType.King
|
||||
|
||||
test("HistoryMove stores explicit piece and capture flags"):
|
||||
val move = HistoryMove(
|
||||
from = sq(File.G, Rank.R1),
|
||||
to = sq(File.F, Rank.R3),
|
||||
pieceType = PieceType.Knight,
|
||||
isCapture = true
|
||||
)
|
||||
move.pieceType shouldBe PieceType.Knight
|
||||
move.isCapture shouldBe true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user