Commit 34136e4e authored by morkolai's avatar morkolai
Browse files

checks if move is legal before move

parent 7894b4ca
......@@ -35,9 +35,13 @@ class Game(gameState: GameState, playerIds: LinkedHashSet<Int>) {
return this.gameState.getBoardState().fields[cubeCoordinates]?.hasPiece() == true
}
fun isLegalMove(fromCoordinates: Vector3, toCoordinates: Vector3): Boolean {
return getGameState()?.getGameMode()?.getPossibleMoves(fromCoordinates)?.contains(toCoordinates) ?: false
}
fun movePiece(fromCoordinates: Vector3, toCoordinates: Vector3, playerId: Int, gameController: GameController): Boolean {
// Check if players turn
if (playerId == playerTurnId) {
if (playerId == playerTurnId && isLegalMove(fromCoordinates,toCoordinates)) {
// TODO: Check if valid move
val pieceMoved: Boolean = this.gameState.getBoardState().movePiece(fromCoordinates, toCoordinates)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment