From b8a6afedb14a1d54d77df918dc1d5b53be11c44b Mon Sep 17 00:00:00 2001 From: joffrey-bion Date: Sat, 28 Nov 2020 00:21:43 +0100 Subject: 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 --- .../kotlin/org/luxons/sevenwonders/model/cards/Cards.kt | 8 ++++---- .../org/luxons/sevenwonders/model/resources/Resources.kt | 12 ++++++++++++ .../kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) (limited to 'sw-common-model') 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 = 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 +typealias ResourceTransactionOptions = List + +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, + val transactionsOptions: ResourceTransactionOptions, val playabilityLevel: PlayabilityLevel, ) { val isFree: Boolean = minPrice == 0 -- cgit