Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 23e727a7dc | |||
| 57a5185212 | |||
| 249a67b883 | |||
| bf0b9862fc | |||
| 1811f74aa7 | |||
| a9a4cdf590 | |||
| 395318909b | |||
| 23a5c763c5 | |||
| 14e88470de |
+1
-5
@@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
id("org.sonarqube") version "7.2.3.7755"
|
||||
id("org.scoverage") version "8.1" apply false
|
||||
}
|
||||
|
||||
group = "de.nowchess"
|
||||
@@ -29,10 +28,7 @@ val versions = mapOf(
|
||||
"SCALA_LIBRARY" to "2.13.18",
|
||||
"SCALATEST" to "3.2.19",
|
||||
"SCALATEST_JUNIT" to "0.1.11",
|
||||
"SCOVERAGE" to "2.1.1",
|
||||
"SCALAFX" to "21.0.0-R32",
|
||||
"JAVAFX" to "21.0.1",
|
||||
"JUNIT_BOM" to "5.13.4"
|
||||
"SCOVERAGE" to "2.1.1"
|
||||
)
|
||||
extra["VERSIONS"] = versions
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.nowchess.chess.engine
|
||||
|
||||
import scala.collection.mutable
|
||||
import de.nowchess.api.board.{Board, Color}
|
||||
import de.nowchess.api.board.{Board, Color, File, Piece, PieceType, Rank, Square}
|
||||
import de.nowchess.chess.logic.GameHistory
|
||||
import de.nowchess.chess.observer.*
|
||||
import org.scalatest.funsuite.AnyFunSuite
|
||||
@@ -86,6 +86,28 @@ class GameEngineLoadPgnTest extends AnyFunSuite with Matchers:
|
||||
// state is reset to initial (reset happens before replay, which fails)
|
||||
engine.history.moves shouldBe empty
|
||||
|
||||
test("loadPgn: promotion in PGN is replayed correctly"):
|
||||
val engine = new GameEngine()
|
||||
val pgn =
|
||||
"""[Event "T"]
|
||||
|
||||
1. b4 h6 2. b5 h5 3. b6 h4 4. bxa7 h3 5. a8=Q
|
||||
"""
|
||||
engine.loadPgn(pgn) shouldBe Right(())
|
||||
engine.history.moves.length shouldBe 9
|
||||
|
||||
test("loadPgn: en passant capture in PGN is replayed correctly"):
|
||||
val engine = new GameEngine()
|
||||
val pgn =
|
||||
"""[Event "T"]
|
||||
|
||||
1. e4 e6 2. e5 d5 3. exd6
|
||||
"""
|
||||
engine.loadPgn(pgn) shouldBe Right(())
|
||||
engine.history.moves.length shouldBe 5
|
||||
engine.board.pieceAt(Square(File.D, Rank.R6)) shouldBe Some(Piece(Color.White, PieceType.Pawn))
|
||||
engine.board.pieceAt(Square(File.D, Rank.R5)) shouldBe None
|
||||
|
||||
// ── undo/redo notation events ─────────────────────────────────────────────
|
||||
|
||||
test("undo emits MoveUndoneEvent with pgnNotation"):
|
||||
@@ -140,18 +162,16 @@ class GameEngineLoadPgnTest extends AnyFunSuite with Matchers:
|
||||
val engine = new GameEngine()
|
||||
val cap = new EventCapture()
|
||||
engine.subscribe(cap)
|
||||
// White builds a capture on the a-file: b4, ... a6, b5, ... h6, bxa6
|
||||
engine.processUserInput("b2b4")
|
||||
engine.processUserInput("a7a6")
|
||||
engine.processUserInput("b4b5")
|
||||
engine.processUserInput("h7h6")
|
||||
engine.processUserInput("b5a6") // white pawn captures black pawn
|
||||
// e4, then Black plays d5, White pawn on e4 captures on d5
|
||||
engine.processUserInput("e2e4")
|
||||
engine.processUserInput("d7d5")
|
||||
engine.processUserInput("e4d5") // white pawn captures black pawn
|
||||
engine.undo()
|
||||
cap.events.clear()
|
||||
engine.redo()
|
||||
val evt = cap.events.last.asInstanceOf[MoveRedoneEvent]
|
||||
evt.fromSquare shouldBe "b5"
|
||||
evt.toSquare shouldBe "a6"
|
||||
evt.fromSquare shouldBe "e4"
|
||||
evt.toSquare shouldBe "d5"
|
||||
evt.capturedPiece.isDefined shouldBe true
|
||||
|
||||
test("loadPgn: clears previous game state before loading"):
|
||||
|
||||
@@ -96,6 +96,32 @@ class PgnValidatorTest extends AnyFunSuite with Matchers:
|
||||
game.moves.last.castleSide shouldBe Some(CastleSide.Queenside)
|
||||
case Left(err) => fail(s"Expected Right but got Left($err)")
|
||||
|
||||
test("validatePgn: valid promotion is accepted"):
|
||||
val pgn =
|
||||
"""[Event "Test"]
|
||||
|
||||
1. b4 h6 2. b5 h5 3. b6 h4 4. bxa7 h3 5. a8=Q
|
||||
"""
|
||||
PgnParser.validatePgn(pgn) match
|
||||
case Right(game) =>
|
||||
game.moves.takeWhile(m => m.promotionPiece.isEmpty).length shouldBe 8
|
||||
game.moves.last.promotionPiece shouldBe Some(PromotionPiece.Queen)
|
||||
case Left(err) => fail(s"Expected Right but got Left($err)")
|
||||
|
||||
test("validatePgn: en passant capture is parsed correctly"):
|
||||
val pgn =
|
||||
"""[Event "Test"]
|
||||
|
||||
1. e4 e6 2. e5 d5 3. exd6
|
||||
"""
|
||||
PgnParser.validatePgn(pgn) match
|
||||
case Right(game) =>
|
||||
game.moves.length shouldBe 5
|
||||
val epMove = game.moves.last
|
||||
epMove.isCapture shouldBe true
|
||||
epMove.pieceType shouldBe PieceType.Pawn
|
||||
case Left(err) => fail(s"Expected Right but got Left($err)")
|
||||
|
||||
test("validatePgn: disambiguation with two rooks is accepted"):
|
||||
val pieces: Map[Square, Piece] = Map(
|
||||
Square(File.A, Rank.R1) -> Piece(Color.White, PieceType.Rook),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("scala")
|
||||
id("org.scoverage")
|
||||
id("org.scoverage") version "8.1"
|
||||
application
|
||||
}
|
||||
|
||||
@@ -55,10 +55,10 @@ dependencies {
|
||||
implementation(project(":modules:api"))
|
||||
|
||||
// ScalaFX dependencies
|
||||
implementation("org.scalafx:scalafx_3:${versions["SCALAFX"]!!}")
|
||||
implementation("org.scalafx:scalafx_3:21.0.0-R32")
|
||||
|
||||
// JavaFX dependencies for the current platform
|
||||
val javaFXVersion = versions["JAVAFX"]!!
|
||||
val javaFXVersion = "21.0.1"
|
||||
val osName = System.getProperty("os.name").lowercase()
|
||||
val platform = when {
|
||||
osName.contains("win") -> "win"
|
||||
@@ -71,7 +71,7 @@ dependencies {
|
||||
implementation("org.openjfx:javafx-$module:$javaFXVersion:$platform")
|
||||
}
|
||||
|
||||
testImplementation(platform("org.junit:junit-bom:${versions["JUNIT_BOM"]!!}"))
|
||||
testImplementation(platform("org.junit:junit-bom:5.13.4"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testImplementation("org.scalatest:scalatest_3:${versions["SCALATEST"]!!}")
|
||||
testImplementation("co.helmethair:scalatest-junit-runner:${versions["SCALATEST_JUNIT"]!!}")
|
||||
|
||||
@@ -23,11 +23,10 @@ import de.nowchess.chess.notation.{FenExporter, FenParser, PgnExporter, PgnParse
|
||||
class ChessBoardView(val stage: Stage, private val engine: GameEngine) extends BorderPane:
|
||||
|
||||
private val squareSize = 70.0
|
||||
private val comicSansFontFamily = "Comic Sans MS"
|
||||
private val boardGrid = new GridPane()
|
||||
private val messageLabel = new Label {
|
||||
text = "Welcome!"
|
||||
font = Font.font(comicSansFontFamily, 16)
|
||||
font = Font.font("Comic Sans MS", 16)
|
||||
padding = Insets(10)
|
||||
}
|
||||
|
||||
@@ -46,7 +45,7 @@ class ChessBoardView(val stage: Stage, private val engine: GameEngine) extends B
|
||||
children = Seq(
|
||||
new Label {
|
||||
text = "Chess"
|
||||
font = Font.font(comicSansFontFamily, 24)
|
||||
font = Font.font("Comic Sans MS", 24)
|
||||
style = "-fx-font-weight: bold;"
|
||||
},
|
||||
messageLabel
|
||||
@@ -70,17 +69,17 @@ class ChessBoardView(val stage: Stage, private val engine: GameEngine) extends B
|
||||
alignment = Pos.Center
|
||||
children = Seq(
|
||||
new Button("Undo") {
|
||||
font = Font.font(comicSansFontFamily, 12)
|
||||
font = Font.font("Comic Sans MS", 12)
|
||||
onAction = _ => if engine.canUndo then engine.undo()
|
||||
style = "-fx-background-radius: 8; -fx-background-color: #B9DAD1;"
|
||||
},
|
||||
new Button("Redo") {
|
||||
font = Font.font(comicSansFontFamily, 12)
|
||||
font = Font.font("Comic Sans MS", 12)
|
||||
onAction = _ => if engine.canRedo then engine.redo()
|
||||
style = "-fx-background-radius: 8; -fx-background-color: #B9C2DA;"
|
||||
},
|
||||
new Button("Reset") {
|
||||
font = Font.font(comicSansFontFamily, 12)
|
||||
font = Font.font("Comic Sans MS", 12)
|
||||
onAction = _ => engine.reset()
|
||||
style = "-fx-background-radius: 8; -fx-background-color: #E1EAA9;"
|
||||
}
|
||||
@@ -91,22 +90,22 @@ class ChessBoardView(val stage: Stage, private val engine: GameEngine) extends B
|
||||
alignment = Pos.Center
|
||||
children = Seq(
|
||||
new Button("FEN Export") {
|
||||
font = Font.font(comicSansFontFamily, 12)
|
||||
font = Font.font("Comic Sans MS", 12)
|
||||
onAction = _ => doFenExport()
|
||||
style = "-fx-background-radius: 8; -fx-background-color: #DAC4B9;"
|
||||
},
|
||||
new Button("FEN Import") {
|
||||
font = Font.font(comicSansFontFamily, 12)
|
||||
font = Font.font("Comic Sans MS", 12)
|
||||
onAction = _ => doFenImport()
|
||||
style = "-fx-background-radius: 8; -fx-background-color: #DAD4B9;"
|
||||
},
|
||||
new Button("PGN Export") {
|
||||
font = Font.font(comicSansFontFamily, 12)
|
||||
font = Font.font("Comic Sans MS", 12)
|
||||
onAction = _ => doPgnExport()
|
||||
style = "-fx-background-radius: 8; -fx-background-color: #C4DAB9;"
|
||||
},
|
||||
new Button("PGN Import") {
|
||||
font = Font.font(comicSansFontFamily, 12)
|
||||
font = Font.font("Comic Sans MS", 12)
|
||||
onAction = _ => doPgnImport()
|
||||
style = "-fx-background-radius: 8; -fx-background-color: #B9DAC4;"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user