summaryrefslogtreecommitdiff
path: root/sw-engine/src
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@gmail.com>2023-04-30 03:31:12 +0200
committerJoffrey Bion <joffrey.bion@gmail.com>2023-04-30 03:31:12 +0200
commit38c4cd33e676d1e042cd3dcf30d7f3915d37d253 (patch)
tree5271b5f99178efb04194282382ab980af83597b7 /sw-engine/src
parentFix missing West Trading Post as parent for Forum (diff)
downloadseven-wonders-38c4cd33e676d1e042cd3dcf30d7f3915d37d253.tar.gz
seven-wonders-38c4cd33e676d1e042cd3dcf30d7f3915d37d253.tar.bz2
seven-wonders-38c4cd33e676d1e042cd3dcf30d7f3915d37d253.zip
Prevent duplicate cards even with "special free" ability
Resolves: https://github.com/joffrey-bion/seven-wonders/issues/142
Diffstat (limited to 'sw-engine/src')
-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