summaryrefslogtreecommitdiff
path: root/game-engine/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'game-engine/src/main/kotlin')
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt2
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Requirements.kt13
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializer.kt5
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializer.kt9
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializer.kt6
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt2
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt2
7 files changed, 12 insertions, 27 deletions
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt
index d3327ba5..af956695 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt
@@ -86,7 +86,7 @@ class Game internal constructor(
* ready to [play the current turn][playTurn].
*/
fun allPlayersPreparedTheirMove(): Boolean {
- val nbExpectedMoves = currentTurnInfo.filter { it.action !== Action.WAIT }.count()
+ val nbExpectedMoves = currentTurnInfo.count { it.action !== Action.WAIT }
return preparedMoves.size == nbExpectedMoves
}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Requirements.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Requirements.kt
index ad50a1c6..69fb5d61 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Requirements.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Requirements.kt
@@ -20,9 +20,8 @@ data class Requirements internal constructor(
*
* @return true if the given board meets these requirements without any transaction with its neighbours
*/
- internal fun areMetWithoutNeighboursBy(board: Board): Boolean {
- return hasRequiredGold(board) && producesRequiredResources(board)
- }
+ internal fun areMetWithoutNeighboursBy(board: Board): Boolean =
+ hasRequiredGold(board) && producesRequiredResources(board)
/**
* Returns whether the given board meets these requirements, if the specified resources are bought from neighbours.
@@ -59,18 +58,14 @@ data class Requirements internal constructor(
return !solution.possibleTransactions.isEmpty() && solution.price <= board.gold - gold
}
- private fun hasRequiredGold(board: Board): Boolean {
- return board.gold >= gold
- }
+ private fun hasRequiredGold(board: Board): Boolean = board.gold >= gold
private fun hasRequiredGold(board: Board, resourceTransactions: ResourceTransactions): Boolean {
val resourcesPrice = board.tradingRules.computeCost(resourceTransactions)
return board.gold >= gold + resourcesPrice
}
- private fun producesRequiredResources(board: Board): Boolean {
- return board.production.contains(resources)
- }
+ private fun producesRequiredResources(board: Board): Boolean = board.production.contains(resources)
private fun producesRequiredResourcesWithHelp(board: Board, transactions: ResourceTransactions): Boolean {
val totalBoughtResources = transactions.asResources()
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializer.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializer.kt
index cff2b974..4520c821 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializer.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializer.kt
@@ -12,9 +12,8 @@ import java.lang.reflect.Type
internal class ResourceTypeSerializer : JsonSerializer<ResourceType>, JsonDeserializer<ResourceType> {
- override fun serialize(type: ResourceType, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
- return JsonPrimitive(type.symbol!!)
- }
+ override fun serialize(type: ResourceType, typeOfSrc: Type, context: JsonSerializationContext): JsonElement =
+ JsonPrimitive(type.symbol)
@Throws(JsonParseException::class)
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): ResourceType {
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializer.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializer.kt
index b794f884..b4784689 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializer.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializer.kt
@@ -26,12 +26,5 @@ internal class ResourceTypesSerializer : JsonSerializer<List<ResourceType>>, Jso
json: JsonElement,
typeOfT: Type,
context: JsonDeserializationContext
- ): List<ResourceType> {
- val s = json.asString
- val resources = ArrayList<ResourceType>()
- for (c in s.toCharArray()) {
- resources.add(ResourceType.fromSymbol(c))
- }
- return resources
- }
+ ): List<ResourceType> = json.asString.map { ResourceType.fromSymbol(it) }
}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializer.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializer.kt
index c988b097..1b1373ed 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializer.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializer.kt
@@ -21,8 +21,6 @@ internal class ResourcesSerializer : JsonSerializer<Resources>, JsonDeserializer
}
@Throws(JsonParseException::class)
- override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Resources {
- val s = json.asString
- return s.toCharArray().map { ResourceType.fromSymbol(it) to 1 }.toResources()
- }
+ override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Resources =
+ json.asString.map { ResourceType.fromSymbol(it) to 1 }.toResources()
}
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 d45d0ce7..60d57e44 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
@@ -7,7 +7,7 @@ typealias ResourceTransactions = Collection<ResourceTransaction>
fun noTransactions(): ResourceTransactions = emptySet()
fun Map<Provider, Resources>.toTransactions(): ResourceTransactions =
- filter { (_, res) -> !res.isEmpty() }.map { (p, res) -> ResourceTransaction(p, res) }.toSet()
+ filterValues { !it.isEmpty() }.map { (p, res) -> ResourceTransaction(p, res) }.toSet()
fun ResourceTransactions.asResources(): Resources = map { it.resources }.merge()
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt
index 26d66f00..3953d4dc 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt
@@ -7,7 +7,7 @@ import org.luxons.sevenwonders.game.cards.Requirements
import org.luxons.sevenwonders.game.effects.Effect
import org.luxons.sevenwonders.game.resources.ResourceTransactions
-class WonderStage internal constructor(val requirements: Requirements, val effects: List<Effect>) {
+class WonderStage internal constructor(val requirements: Requirements, internal val effects: List<Effect>) {
var cardBack: CardBack? = null
private set
bgstack15