summaryrefslogtreecommitdiff
path: root/game-engine/src
diff options
context:
space:
mode:
Diffstat (limited to 'game-engine/src')
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt5
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt6
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/GameTest.kt6
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/TradingRulesTest.kt8
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt13
5 files changed, 17 insertions, 21 deletions
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt
index 95e6b13c..22cc36f0 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt
@@ -1,10 +1,11 @@
package org.luxons.sevenwonders.game.api
import org.luxons.sevenwonders.game.moves.MoveType
-import org.luxons.sevenwonders.game.resources.ResourceTransaction
+import org.luxons.sevenwonders.game.resources.ResourceTransactions
+import org.luxons.sevenwonders.game.resources.noTransactions
data class PlayerMove(
val type: MoveType,
val cardName: String,
- val transactions: Collection<ResourceTransaction> = emptyList()
+ val transactions: ResourceTransactions = noTransactions()
)
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
index c7ab3636..d45d0ce7 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
@@ -4,10 +4,10 @@ import org.luxons.sevenwonders.game.Player
typealias ResourceTransactions = Collection<ResourceTransaction>
-fun noTransactions(): ResourceTransactions = emptyList()
+fun noTransactions(): ResourceTransactions = emptySet()
-fun Map<Provider, Resources>.toTransactions() =
- filter { (_, res) -> !res.isEmpty() }.map { (p, res) -> ResourceTransaction(p, res) }
+fun Map<Provider, Resources>.toTransactions(): ResourceTransactions =
+ filter { (_, res) -> !res.isEmpty() }.map { (p, res) -> ResourceTransaction(p, res) }.toSet()
fun ResourceTransactions.asResources(): Resources = map { it.resources }.merge()
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/GameTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/GameTest.kt
index fb797b77..e1d8b7f9 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/GameTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/GameTest.kt
@@ -13,10 +13,10 @@ import org.luxons.sevenwonders.game.api.Table
import org.luxons.sevenwonders.game.data.GameDefinitionLoader
import org.luxons.sevenwonders.game.data.LAST_AGE
import org.luxons.sevenwonders.game.moves.MoveType
-import org.luxons.sevenwonders.game.resources.ResourceTransaction
import org.luxons.sevenwonders.game.resources.ResourceTransactions
import org.luxons.sevenwonders.game.resources.Resources
import org.luxons.sevenwonders.game.resources.bestSolution
+import org.luxons.sevenwonders.game.resources.noTransactions
import org.luxons.sevenwonders.game.test.testCustomizableSettings
import java.util.HashMap
@@ -83,9 +83,9 @@ class GameTest {
return PlayerMove(MoveType.DISCARD, firstCardInHand.card.name)
}
- private fun findResourcesToBuyFor(handCard: HandCard, turnInfo: PlayerTurnInfo): Collection<ResourceTransaction> {
+ private fun findResourcesToBuyFor(handCard: HandCard, turnInfo: PlayerTurnInfo): ResourceTransactions {
if (handCard.isFree) {
- return emptyList()
+ return noTransactions()
}
val requiredResources = handCard.card.requirements.resources
val table = turnInfo.table
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/TradingRulesTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/TradingRulesTest.kt
index e44c38f3..3e567493 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/TradingRulesTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/TradingRulesTest.kt
@@ -8,7 +8,6 @@ import org.junit.experimental.theories.Theory
import org.junit.runner.RunWith
import org.luxons.sevenwonders.game.test.createTransaction
import org.luxons.sevenwonders.game.test.createTransactions
-import java.util.ArrayList
@RunWith(Theories::class)
class TradingRulesTest {
@@ -102,9 +101,10 @@ class TradingRulesTest {
val rules = TradingRules(defaultCost)
rules.setCost(type, overriddenProvider, overriddenCost)
- val boughtResources = ArrayList<ResourceTransaction>(2)
- boughtResources.add(createTransaction(provider, type))
- boughtResources.add(createTransaction(overriddenProvider, type))
+ val boughtResources = createTransactions(
+ createTransaction(provider, type),
+ createTransaction(overriddenProvider, type)
+ )
assertEquals(defaultCost + overriddenCost, rules.computeCost(boughtResources))
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
index 383c77fa..c67a7052 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
@@ -102,11 +102,11 @@ infix fun Int.of(type: ResourceType): Resources {
internal fun createTransactions(provider: Provider, vararg resources: ResourceType): ResourceTransactions {
val transaction = createTransaction(provider, *resources)
- return listOf(transaction)
+ return createTransactions(transaction)
}
internal fun createTransactions(vararg transactions: ResourceTransaction): ResourceTransactions {
- return transactions.toList()
+ return transactions.toSet()
}
fun createTransaction(provider: Provider, vararg resources: ResourceType): ResourceTransaction {
@@ -209,13 +209,8 @@ internal fun playCardWithEffect(player: Player, color: Color, effect: Effect) {
card.applyTo(player, noTransactions())
}
-internal fun createMove(
- context: PlayerContext,
- card: Card,
- type: MoveType,
- vararg transactions: ResourceTransaction
-): Move {
- val playerMove = PlayerMove(type, card.name, Arrays.asList(*transactions))
+internal fun createMove(context: PlayerContext, card: Card, type: MoveType): Move {
+ val playerMove = PlayerMove(type, card.name)
return type.create(playerMove, card, context)
}
bgstack15