From cab8a5a83e810d14c97fbb26f0cdfe1b86e88d43 Mon Sep 17 00:00:00 2001 From: jbion Date: Tue, 19 Feb 2019 18:09:27 +0100 Subject: Fix board gold access and cleanup tests --- .../src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt | 9 ++------- .../src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt | 6 +++--- .../main/kotlin/org/luxons/sevenwonders/game/moves/MoveType.kt | 2 +- .../org/luxons/sevenwonders/game/resources/ResourceType.kt | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) (limited to 'game-engine/src/main/kotlin') diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt index 3cb14083..63d5052f 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt @@ -1,15 +1,15 @@ package org.luxons.sevenwonders.game import org.luxons.sevenwonders.game.api.CustomizableSettings -import org.luxons.sevenwonders.game.data.definitions.WonderSide import org.luxons.sevenwonders.game.api.WonderSidePickMethod +import org.luxons.sevenwonders.game.data.definitions.WonderSide import java.util.Random internal class Settings( val nbPlayers: Int, customSettings: CustomizableSettings = CustomizableSettings() ) { - val random: Random + val random: Random = customSettings.randomSeedForTests?.let { Random(it) } ?: Random() val timeLimitInSeconds: Int = customSettings.timeLimitInSeconds val initialGold: Int = customSettings.initialGold val discardedCardGold: Int = customSettings.discardedCardGold @@ -21,11 +21,6 @@ internal class Settings( private val wonderSidePickMethod: WonderSidePickMethod = customSettings.wonderSidePickMethod private var lastPickedSide: WonderSide? = null - init { - val seed = customSettings.randomSeedForTests - this.random = if (seed != null) Random(seed) else Random() - } - fun pickWonderSide(): WonderSide { val newSide = wonderSidePickMethod.pickSide(random, lastPickedSide) lastPickedSide = newSide diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt index c4dbeb21..470f3ba0 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt @@ -36,9 +36,9 @@ class Table internal constructor(val boards: List) { } internal fun resolveMilitaryConflicts() { - for (i in 0 until nbPlayers) { - val board1 = getBoard(i) - val board2 = getBoard(i, RelativeBoardPosition.RIGHT) + repeat(nbPlayers) { + val board1 = getBoard(it) + val board2 = getBoard(it, RelativeBoardPosition.RIGHT) resolveConflict(board1, board2) } } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/MoveType.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/MoveType.kt index fc859931..ae00f23f 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/MoveType.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/MoveType.kt @@ -4,7 +4,7 @@ import org.luxons.sevenwonders.game.PlayerContext import org.luxons.sevenwonders.game.api.PlayerMove import org.luxons.sevenwonders.game.cards.Card -enum class MoveType(val create: (move: PlayerMove, card: Card, context: PlayerContext) -> Move) { +enum class MoveType(private val create: (move: PlayerMove, card: Card, context: PlayerContext) -> Move) { PLAY(::PlayCardMove), PLAY_FREE(::PlayFreeCardMove), UPGRADE_WONDER(::BuildWonderMove), diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt index 7e259023..5c92b887 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt @@ -1,6 +1,6 @@ package org.luxons.sevenwonders.game.resources -enum class ResourceType(val symbol: Char?) { +enum class ResourceType(val symbol: Char) { WOOD('W'), STONE('S'), ORE('O'), -- cgit