feat: highlight legal moves on chess board interaction
This commit is contained in:
@@ -12,6 +12,7 @@ import scalafx.stage.Stage
|
|||||||
import de.nowchess.api.board.{Board, Color, Piece, PieceType, Square, File, Rank}
|
import de.nowchess.api.board.{Board, Color, Piece, PieceType, Square, File, Rank}
|
||||||
import de.nowchess.api.move.PromotionPiece
|
import de.nowchess.api.move.PromotionPiece
|
||||||
import de.nowchess.chess.engine.GameEngine
|
import de.nowchess.chess.engine.GameEngine
|
||||||
|
import de.nowchess.chess.logic.GameRules
|
||||||
|
|
||||||
/** ScalaFX chess board view that displays the game state.
|
/** ScalaFX chess board view that displays the game state.
|
||||||
* Uses chess sprites and color palette.
|
* Uses chess sprites and color palette.
|
||||||
@@ -128,6 +129,11 @@ class ChessBoardView(val stage: Stage, private val engine: GameEngine) extends B
|
|||||||
if piece.color == currentTurn then
|
if piece.color == currentTurn then
|
||||||
selectedSquare = Some(clickedSquare)
|
selectedSquare = Some(clickedSquare)
|
||||||
highlightSquare(rank, file, PieceSprites.SquareColors.Selected)
|
highlightSquare(rank, file, PieceSprites.SquareColors.Selected)
|
||||||
|
val legalDests = GameRules.legalMoves(currentBoard, engine.history, currentTurn)
|
||||||
|
.collect { case (`clickedSquare`, to) => to }
|
||||||
|
legalDests.foreach { sq =>
|
||||||
|
highlightSquare(sq.rank.ordinal, sq.file.ordinal, PieceSprites.SquareColors.ValidMove)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case Some(fromSquare) =>
|
case Some(fromSquare) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user