summaryrefslogtreecommitdiff
path: root/sw-engine/src/main/kotlin
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2019-05-22 01:57:01 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2019-05-22 01:57:01 +0200
commit073768b1c3749813b1b0cd688b8aaa79d4996bd3 (patch)
tree25a0758b5c1584409061d7847019a2ca547f670f /sw-engine/src/main/kotlin
parentMove common module declarations into api package (diff)
downloadseven-wonders-073768b1c3749813b1b0cd688b8aaa79d4996bd3.tar.gz
seven-wonders-073768b1c3749813b1b0cd688b8aaa79d4996bd3.tar.bz2
seven-wonders-073768b1c3749813b1b0cd688b8aaa79d4996bd3.zip
Fix tests
Diffstat (limited to 'sw-engine/src/main/kotlin')
-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