diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2020-11-28 00:21:43 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2020-11-28 02:26:32 +0100 |
commit | b8a6afedb14a1d54d77df918dc1d5b53be11c44b (patch) | |
tree | 58143efb9ab9e91dc045dc5ddbb5aeca99ef3596 /sw-common-model/src/commonMain | |
parent | Add dialog to choose who to buy resources from (diff) | |
download | seven-wonders-b8a6afedb14a1d54d77df918dc1d5b53be11c44b.tar.gz seven-wonders-b8a6afedb14a1d54d77df918dc1d5b53be11c44b.tar.bz2 seven-wonders-b8a6afedb14a1d54d77df918dc1d5b53be11c44b.zip |
Make all transactions available
Sometimes the strategic move can be to spend more money on a different player, rather than less money on the wrong player.
We need to make these strategic moves available through the UI.
To make up for the explosion in combinations, we just have to get rid of the options that result in the same money for each neighbour.
As long as we give the same amounts, we don't care whether it's for wood or clay.
Related:
https://github.com/joffrey-bion/seven-wonders/issues/50
Diffstat (limited to 'sw-common-model/src/commonMain')
3 files changed, 18 insertions, 6 deletions
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt index 7b228d4d..14e6146a 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt @@ -2,8 +2,8 @@ package org.luxons.sevenwonders.model.cards import kotlinx.serialization.Serializable import org.luxons.sevenwonders.model.boards.Requirements -import org.luxons.sevenwonders.model.resources.PricedResourceTransactions -import org.luxons.sevenwonders.model.resources.noTransactions +import org.luxons.sevenwonders.model.resources.ResourceTransactionOptions +import org.luxons.sevenwonders.model.resources.singleOptionNoTransactionNeeded interface Card { val name: String @@ -82,7 +82,7 @@ data class CardPlayability( val isPlayable: Boolean, val isChainable: Boolean = false, val minPrice: Int = Int.MAX_VALUE, - val cheapestTransactions: Set<PricedResourceTransactions> = setOf(noTransactions()), + val transactionOptions: ResourceTransactionOptions = singleOptionNoTransactionNeeded(), val playabilityLevel: PlayabilityLevel, ) { val isFree: Boolean = minPrice == 0 @@ -92,7 +92,7 @@ data class CardPlayability( isPlayable = true, isChainable = false, minPrice = 0, - cheapestTransactions = setOf(noTransactions()), + transactionOptions = singleOptionNoTransactionNeeded(), playabilityLevel = PlayabilityLevel.SPECIAL_FREE, ) } diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/resources/Resources.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/resources/Resources.kt index 51e7f78d..fc99a41d 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/resources/Resources.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/resources/Resources.kt @@ -57,4 +57,16 @@ data class PricedResourceTransaction( typealias PricedResourceTransactions = Set<PricedResourceTransaction> +typealias ResourceTransactionOptions = List<PricedResourceTransactions> + +val PricedResourceTransactions.totalPrice: Int + get() = sumBy { it.totalPrice } + +val ResourceTransactionOptions.bestPrice: Int + get() = minOfOrNull { it.totalPrice } ?: Int.MAX_VALUE + fun noTransactions(): PricedResourceTransactions = emptySet() + +fun noTransactionOptions(): ResourceTransactionOptions = emptyList() + +fun singleOptionNoTransactionNeeded(): ResourceTransactionOptions = listOf(noTransactions()) diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt index 56b22e82..4767804a 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable import org.luxons.sevenwonders.model.boards.Requirements import org.luxons.sevenwonders.model.cards.CardBack import org.luxons.sevenwonders.model.cards.PlayabilityLevel -import org.luxons.sevenwonders.model.resources.PricedResourceTransactions +import org.luxons.sevenwonders.model.resources.ResourceTransactionOptions import org.luxons.sevenwonders.model.resources.ResourceType import kotlin.random.Random @@ -58,7 +58,7 @@ data class ApiWonderStage( data class WonderBuildability( val isBuildable: Boolean, val minPrice: Int, - val cheapestTransactions: Set<PricedResourceTransactions>, + val transactionsOptions: ResourceTransactionOptions, val playabilityLevel: PlayabilityLevel, ) { val isFree: Boolean = minPrice == 0 |