diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-02 14:40:26 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-02 14:47:32 +0100 |
commit | 2762d7d0ea69291593662a9c2d934e45caa23dbb (patch) | |
tree | 92f067984c0862a676dcb4e5b095506e54f23ea2 /sw-engine/src/main/kotlin/org/luxons | |
parent | Move prepareMove log before the actual preparation (diff) | |
download | seven-wonders-2762d7d0ea69291593662a9c2d934e45caa23dbb.tar.gz seven-wonders-2762d7d0ea69291593662a9c2d934e45caa23dbb.tar.bz2 seven-wonders-2762d7d0ea69291593662a9c2d934e45caa23dbb.zip |
Filter only affordable transactions
Resolves:
https://github.com/joffrey-bion/seven-wonders/issues/81
Diffstat (limited to 'sw-engine/src/main/kotlin/org/luxons')
-rw-r--r-- | sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/cards/Requirements.kt | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/cards/Requirements.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/cards/Requirements.kt index 1d03aa76..4872f44f 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/cards/Requirements.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/cards/Requirements.kt @@ -6,6 +6,8 @@ import org.luxons.sevenwonders.engine.boards.Board import org.luxons.sevenwonders.engine.resources.* import org.luxons.sevenwonders.model.resources.ResourceTransactions import org.luxons.sevenwonders.model.resources.bestPrice +import org.luxons.sevenwonders.model.resources.noTransactionOptions +import org.luxons.sevenwonders.model.resources.totalPrice @Serializable data class Requirements internal constructor( @@ -36,15 +38,16 @@ data class Requirements internal constructor( } private fun satisfactionWithPotentialHelp(player: Player): RequirementsSatisfaction { - val options = transactionOptions(resources, player) - val minPrice = options.bestPrice + gold - if (options.isEmpty()) { + val allOptions = transactionOptions(resources, player) + if (allOptions.isEmpty()) { return RequirementsSatisfaction.unavailableResources() } - if (player.board.gold < minPrice) { - return RequirementsSatisfaction.missingGoldForResources(minPrice, options) + val minPrice = allOptions.bestPrice + gold + if (minPrice > player.board.gold) { + return RequirementsSatisfaction.missingGoldForResources(minPrice, noTransactionOptions()) } - return RequirementsSatisfaction.metWithHelp(minPrice, options) + val availableOptions = allOptions.filter { it.totalPrice + gold <= player.board.gold } + return RequirementsSatisfaction.metWithHelp(minPrice, availableOptions) } /** |