summaryrefslogtreecommitdiff
path: root/sw-engine/src
diff options
context:
space:
mode:
Diffstat (limited to 'sw-engine/src')
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt4
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculator.kt3
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt7
3 files changed, 6 insertions, 8 deletions
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt
index 60b04318..a9e3232d 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt
@@ -75,7 +75,9 @@ internal fun Requirements.toApiRequirements(): ApiRequirements =
)
internal fun Resources.toCountedResourcesList(): List<CountedResource> =
- quantities.map { (type, count) -> CountedResource(count, type) }.sortedBy { it.type }
+ quantities.filterValues { it > 0 }
+ .map { (type, count) -> CountedResource(count, type) }
+ .sortedBy { it.type }
internal fun Military.toApiMilitary(): ApiMilitary =
ApiMilitary(nbShields, totalPoints, nbDefeatTokens)
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculator.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculator.kt
index 6a49449b..e4d4c6c4 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculator.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculator.kt
@@ -119,6 +119,7 @@ private class BestPriceCalculator(resourcesToPay: Resources, player: Player) {
bestSolutions.clear()
}
// avoid mutating the resources from the transactions
- bestSolutions.add(boughtResources.mapValues { (_, res) -> res.copy() }.toTransactions())
+ val transactionSet = boughtResources.mapValues { (_, res) -> res.copy() }.toTransactions()
+ bestSolutions.add(transactionSet)
}
}
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
index 862b7caf..a7554768 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
@@ -9,12 +9,7 @@ import org.luxons.sevenwonders.game.api.toCountedResourcesList
fun Map<Provider, Resources>.toTransactions(): ResourceTransactions =
filterValues { !it.isEmpty() }
- .map { (p, res) ->
- ResourceTransaction(
- p,
- res.toCountedResourcesList()
- )
- }
+ .map { (p, res) -> ResourceTransaction(p, res.toCountedResourcesList()) }
.toSet()
fun ResourceTransactions.asResources(): Resources = flatMap { it.resources }.asResources()
bgstack15