From 2762d7d0ea69291593662a9c2d934e45caa23dbb Mon Sep 17 00:00:00 2001 From: joffrey-bion Date: Tue, 2 Feb 2021 14:40:26 +0100 Subject: Filter only affordable transactions Resolves: https://github.com/joffrey-bion/seven-wonders/issues/81 --- .../org/luxons/sevenwonders/engine/cards/Requirements.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'sw-engine/src/main/kotlin') 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) } /** -- cgit