summaryrefslogtreecommitdiff
path: root/sw-engine/src/main/kotlin/org/luxons
diff options
context:
space:
mode:
Diffstat (limited to 'sw-engine/src/main/kotlin/org/luxons')
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/cards/Cards.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayCardMove.kt3
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeCardMove.kt3
3 files changed, 7 insertions, 1 deletions
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/cards/Cards.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/cards/Cards.kt
index a20f37a0..4ca87734 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/cards/Cards.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/cards/Cards.kt
@@ -32,7 +32,7 @@ internal data class Card(
private fun isChainableOn(board: Board): Boolean = !isAlreadyOnBoard(board) && isAnyParentOnBoard(board)
- private fun isAlreadyOnBoard(board: Board): Boolean = board.isPlayed(name)
+ fun isAlreadyOnBoard(board: Board): Boolean = board.isPlayed(name)
private fun isAnyParentOnBoard(board: Board): Boolean = chainParents.any { board.isPlayed(it) }
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayCardMove.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayCardMove.kt
index 66ac4e4c..f87350d4 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayCardMove.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayCardMove.kt
@@ -9,6 +9,9 @@ internal class PlayCardMove(move: PlayerMove, card: Card, player: PlayerContext)
CardFromHandMove(move, card, player) {
init {
+ if (card.isAlreadyOnBoard(player.board)) {
+ throw InvalidMoveException(this, "card ${card.name} is already on the board")
+ }
if (!card.isPlayableOnBoardWith(player.board, transactions)) {
throw InvalidMoveException(this, "requirements not met to play the card ${card.name}")
}
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeCardMove.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeCardMove.kt
index d4067a2b..13212e4a 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeCardMove.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeCardMove.kt
@@ -13,6 +13,9 @@ internal class PlayFreeCardMove(move: PlayerMove, card: Card, playerContext: Pla
if (!board.canPlayFreeCard(playerContext.currentAge)) {
throw InvalidMoveException(this, "no free card available for the current age ${playerContext.currentAge}")
}
+ if (card.isAlreadyOnBoard(board)) {
+ throw InvalidMoveException(this, "card ${card.name} is already on the board")
+ }
}
override fun place(discardedCards: MutableList<Card>) = playerContext.board.addCard(card)
bgstack15