summaryrefslogtreecommitdiff
path: root/sw-engine/src/test
diff options
context:
space:
mode:
authorjoffrey-bion <joffrey.bion@gmail.com>2020-11-25 23:57:16 +0100
committerjoffrey-bion <joffrey.bion@gmail.com>2020-11-25 23:57:16 +0100
commitd0a5abc2bd0f86be86b773e3f77712b2602bdc24 (patch)
tree0ab7bd4f540a4e6d4e090c1c4f48e5331a00f24c /sw-engine/src/test
parentUpgrade dependencies (diff)
downloadseven-wonders-d0a5abc2bd0f86be86b773e3f77712b2602bdc24.tar.gz
seven-wonders-d0a5abc2bd0f86be86b773e3f77712b2602bdc24.tar.bz2
seven-wonders-d0a5abc2bd0f86be86b773e3f77712b2602bdc24.zip
Fix resource transactions calculations
Resolves: https://github.com/joffrey-bion/seven-wonders/issues/49
Diffstat (limited to 'sw-engine/src/test')
-rw-r--r--sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/resources/BestPriceCalculatorTest.kt45
-rw-r--r--sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt2
2 files changed, 41 insertions, 6 deletions
diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/resources/BestPriceCalculatorTest.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/resources/BestPriceCalculatorTest.kt
index ba0fdf1b..36e4046f 100644
--- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/resources/BestPriceCalculatorTest.kt
+++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/resources/BestPriceCalculatorTest.kt
@@ -10,11 +10,7 @@ import org.luxons.sevenwonders.engine.test.testTable
import org.luxons.sevenwonders.model.resources.Provider.LEFT_PLAYER
import org.luxons.sevenwonders.model.resources.Provider.RIGHT_PLAYER
import org.luxons.sevenwonders.model.resources.ResourceTransactions
-import org.luxons.sevenwonders.model.resources.ResourceType.CLAY
-import org.luxons.sevenwonders.model.resources.ResourceType.GLASS
-import org.luxons.sevenwonders.model.resources.ResourceType.ORE
-import org.luxons.sevenwonders.model.resources.ResourceType.STONE
-import org.luxons.sevenwonders.model.resources.ResourceType.WOOD
+import org.luxons.sevenwonders.model.resources.ResourceType.*
import org.luxons.sevenwonders.model.resources.noTransactions
import kotlin.test.assertEquals
@@ -109,6 +105,45 @@ class BestPriceCalculatorTest {
}
@Test
+ fun bestPrice_mixedResources_overridenCost_sameMultipleTimes() {
+ val left = testBoard(WOOD)
+
+ val main = testBoard(WOOD)
+ main.tradingRules.setCost(CLAY, LEFT_PLAYER, 1)
+ main.tradingRules.setCost(CLAY, RIGHT_PLAYER, 1)
+
+ main.publicProduction.addFixedResource(STONE, 1)
+ main.publicProduction.addChoice(CLAY, ORE)
+ main.production.addFixedResource(STONE, 1)
+ main.production.addChoice(CLAY, ORE)
+
+ val right = testBoard(CLAY)
+ right.publicProduction.addFixedResource(ORE, 1)
+ right.publicProduction.addFixedResource(CLAY, 1)
+ right.publicProduction.addFixedResource(WOOD, 2)
+ right.production.addFixedResource(ORE, 1)
+ right.production.addFixedResource(CLAY, 1)
+ right.production.addFixedResource(WOOD, 2)
+
+ val table = Table(listOf(main, right, left))
+
+ val player0 = SimplePlayer(0, table)
+ val player1 = SimplePlayer(1, table)
+ val player2 = SimplePlayer(2, table)
+
+ val resources = resourcesOf(WOOD, CLAY, CLAY, CLAY)
+
+ val claysRight = createTransaction(RIGHT_PLAYER, CLAY, CLAY)
+ val claysLeft = createTransaction(LEFT_PLAYER, CLAY, CLAY)
+ val clayLeft = createTransaction(LEFT_PLAYER, CLAY)
+ val clayRight = createTransaction(RIGHT_PLAYER, CLAY)
+
+ assertEquals(solutions(2, createTransactions(claysRight)), bestSolution(resources, player0))
+ assertEquals(solutions(2, createTransactions(clayLeft)), bestSolution(resources, player1))
+ assertEquals(solutions(6, createTransactions(claysLeft, clayRight)), bestSolution(resources, player2))
+ }
+
+ @Test
fun bestPrice_chooseCheapest() {
val left = testBoard(WOOD)
diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt
index a1b42b49..a7ed406b 100644
--- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt
+++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/test/TestUtils.kt
@@ -70,7 +70,7 @@ internal fun createTransactions(provider: Provider, vararg resources: ResourceTy
internal fun createTransactions(vararg transactions: ResourceTransaction): ResourceTransactions = transactions.toSet()
internal fun createTransaction(provider: Provider, vararg resources: ResourceType): ResourceTransaction =
- ResourceTransaction(provider, resources.map { CountedResource(1, it) })
+ ResourceTransaction(provider, resources.groupBy { it }.map { (type, reps) -> CountedResource(reps.size, type) })
internal fun createRequirements(vararg types: ResourceType): Requirements =
Requirements(resources = resourcesOf(*types))
bgstack15