diff options
Diffstat (limited to 'sw-engine/src/main')
4 files changed, 10 insertions, 9 deletions
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Boards.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Boards.kt index 7ff870cf..0d8369ac 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Boards.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Boards.kt @@ -73,7 +73,7 @@ internal fun InternalWonderStage.toApiWonderStage(isLastBuiltStage: Boolean, las internal fun InternalProduction.toApiProduction(): ApiProduction = ApiProduction( fixedResources = getFixedResources().toCountedResourcesList(), - alternativeResources = getAlternativeResources() + alternativeResources = getAlternativeResources().sortedBy { it.size } ) internal fun InternalRequirements.toApiRequirements(): ApiRequirements = diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/serializers/ProductionSerializer.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/serializers/ProductionSerializer.kt index 467b0912..c98f20a8 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/serializers/ProductionSerializer.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/serializers/ProductionSerializer.kt @@ -24,14 +24,14 @@ internal class ProductionSerializer : JsonSerializer<Production>, JsonDeserializ } } - private fun serializeAsChoice(choices: Set<Set<ResourceType>>, context: JsonSerializationContext): JsonElement { + private fun serializeAsChoice(choices: List<Set<ResourceType>>, context: JsonSerializationContext): JsonElement { if (choices.isEmpty()) { return JsonNull.INSTANCE } if (choices.size > 1) { throw IllegalArgumentException("Cannot serialize a production with more than one choice") } - val str = choices.flatten().map { it.symbol }.joinToString("/") + val str = choices[0].map { it.symbol }.joinToString("/") return context.serialize(str) } diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/resources/BestPriceCalculator.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/resources/BestPriceCalculator.kt index 85b07a80..dd2d2cae 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/resources/BestPriceCalculator.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/resources/BestPriceCalculator.kt @@ -15,7 +15,7 @@ data class TransactionPlan(val price: Int, val possibleTransactions: Set<Resourc private class ResourcePool( val provider: Provider?, private val rules: TradingRules, - choices: Set<Set<ResourceType>> + choices: List<Set<ResourceType>> ) { val choices: Set<MutableSet<ResourceType>> = choices.mapTo(HashSet()) { it.toMutableSet() } diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/resources/Production.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/resources/Production.kt index 46ec66f7..4f9bbe90 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/resources/Production.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/resources/Production.kt @@ -5,11 +5,12 @@ import java.util.EnumSet data class Production internal constructor( private val fixedResources: MutableResources = mutableResourcesOf(), - private val alternativeResources: MutableSet<Set<ResourceType>> = mutableSetOf() + // cannot be a Set because the same choices can be there multiple times + private val alternativeResources: MutableList<Set<ResourceType>> = mutableListOf() ) { fun getFixedResources(): Resources = fixedResources - fun getAlternativeResources(): Set<Set<ResourceType>> = alternativeResources + fun getAlternativeResources(): List<Set<ResourceType>> = alternativeResources fun addFixedResource(type: ResourceType, quantity: Int) = fixedResources.add(type, quantity) @@ -25,8 +26,8 @@ data class Production internal constructor( alternativeResources.addAll(production.getAlternativeResources()) } - internal fun asChoices(): Set<Set<ResourceType>> { - val fixedAsChoices = fixedResources.toList().mapTo(HashSet()) { EnumSet.of(it) } + internal fun asChoices(): List<Set<ResourceType>> { + val fixedAsChoices = fixedResources.toList().map { EnumSet.of(it) } return fixedAsChoices + alternativeResources } @@ -42,7 +43,7 @@ data class Production internal constructor( private fun containedInAlternatives( resources: MutableResources, - alternatives: MutableSet<Set<ResourceType>> + alternatives: MutableList<Set<ResourceType>> ): Boolean { if (resources.isEmpty()) { return true |