From 073768b1c3749813b1b0cd688b8aaa79d4996bd3 Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Wed, 22 May 2019 01:57:01 +0200 Subject: Fix tests --- .../src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt | 4 +++- .../org/luxons/sevenwonders/game/resources/BestPriceCalculator.kt | 3 ++- .../org/luxons/sevenwonders/game/resources/ResourceTransactions.kt | 7 +------ 3 files changed, 6 insertions(+), 8 deletions(-) (limited to 'sw-engine') 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 = - 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.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() -- cgit