summaryrefslogtreecommitdiff
path: root/sw-engine/src/main
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-05-28 20:26:29 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-05-31 11:16:00 +0200
commit36103b92ce4b6cd00925d861f4fb5e381cdc4833 (patch)
tree4c2bfced8317526b24da23fcef9febe6368c736e /sw-engine/src/main
parentAttempt at fixing race conditions with bot subscriptions (diff)
downloadseven-wonders-36103b92ce4b6cd00925d861f4fb5e381cdc4833.tar.gz
seven-wonders-36103b92ce4b6cd00925d861f4fb5e381cdc4833.tar.bz2
seven-wonders-36103b92ce4b6cd00925d861f4fb5e381cdc4833.zip
Simplify settings and allow choosing wonders
Diffstat (limited to 'sw-engine/src/main')
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Settings.kt29
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/GameDefinition.kt30
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/definitions/WonderDefinition.kt9
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/BuildWonderMove.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/CopyGuildMove.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/DiscardMove.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/Move.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayCardMove.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeCardMove.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeDiscardedCardMove.kt2
11 files changed, 32 insertions, 52 deletions
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Settings.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Settings.kt
deleted file mode 100644
index 7461762a..00000000
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Settings.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.luxons.sevenwonders.engine
-
-import org.luxons.sevenwonders.model.CustomizableSettings
-import org.luxons.sevenwonders.model.WonderSide
-import org.luxons.sevenwonders.model.WonderSidePickMethod
-import kotlin.random.Random
-
-internal class Settings(
- val nbPlayers: Int,
- customSettings: CustomizableSettings = CustomizableSettings()
-) {
- val random: Random = customSettings.randomSeedForTests?.let { Random(it) } ?: Random
- val timeLimitInSeconds: Int = customSettings.timeLimitInSeconds
- val initialGold: Int = customSettings.initialGold
- val discardedCardGold: Int = customSettings.discardedCardGold
- val defaultTradingCost: Int = customSettings.defaultTradingCost
- val pointsPer3Gold: Int = customSettings.pointsPer3Gold
- val lostPointsPerDefeat: Int = customSettings.lostPointsPerDefeat
- val wonPointsPerVictoryPerAge: Map<Int, Int> = customSettings.wonPointsPerVictoryPerAge
-
- private val wonderSidePickMethod: WonderSidePickMethod = customSettings.wonderSidePickMethod
- private var lastPickedSide: WonderSide? = null
-
- fun pickWonderSide(): WonderSide {
- val newSide = wonderSidePickMethod.pickSide(random, lastPickedSide)
- lastPickedSide = newSide
- return newSide
- }
-}
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt
index 3f8f0437..a78d6d4b 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/boards/Board.kt
@@ -1,7 +1,6 @@
package org.luxons.sevenwonders.engine.boards
import org.luxons.sevenwonders.engine.Player
-import org.luxons.sevenwonders.engine.Settings
import org.luxons.sevenwonders.engine.cards.Card
import org.luxons.sevenwonders.engine.effects.SpecialAbility
import org.luxons.sevenwonders.engine.resources.Production
@@ -9,6 +8,7 @@ import org.luxons.sevenwonders.engine.resources.TradingRules
import org.luxons.sevenwonders.engine.resources.mutableResourcesOf
import org.luxons.sevenwonders.engine.wonders.Wonder
import org.luxons.sevenwonders.model.Age
+import org.luxons.sevenwonders.model.Settings
import org.luxons.sevenwonders.model.cards.Color
import org.luxons.sevenwonders.model.score.PlayerScore
import org.luxons.sevenwonders.model.score.ScoreCategory
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/GameDefinition.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/GameDefinition.kt
index 962b88e1..b33c9d50 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/GameDefinition.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/GameDefinition.kt
@@ -4,7 +4,6 @@ import com.github.salomonbrys.kotson.typeToken
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import org.luxons.sevenwonders.engine.Game
-import org.luxons.sevenwonders.engine.Settings
import org.luxons.sevenwonders.engine.boards.Board
import org.luxons.sevenwonders.engine.data.definitions.DecksDefinition
import org.luxons.sevenwonders.engine.data.definitions.WonderDefinition
@@ -23,7 +22,9 @@ import org.luxons.sevenwonders.engine.effects.ScienceProgress
import org.luxons.sevenwonders.engine.resources.Production
import org.luxons.sevenwonders.engine.resources.Resources
import org.luxons.sevenwonders.model.Age
-import org.luxons.sevenwonders.model.CustomizableSettings
+import org.luxons.sevenwonders.model.wonders.AssignedWonder
+import org.luxons.sevenwonders.model.Settings
+import org.luxons.sevenwonders.model.wonders.PreGameWonder
import org.luxons.sevenwonders.model.resources.ResourceType
internal const val LAST_AGE: Age = 3
@@ -35,23 +36,30 @@ internal data class GlobalRules(
class GameDefinition internal constructor(
rules: GlobalRules,
- private val wonders: List<WonderDefinition>,
+ wonderDefinitions: List<WonderDefinition>,
private val decksDefinition: DecksDefinition
) {
val minPlayers: Int = rules.minPlayers
val maxPlayers: Int = rules.maxPlayers
- fun initGame(id: Long, customSettings: CustomizableSettings, nbPlayers: Int): Game {
- val settings = Settings(nbPlayers, customSettings)
- val boards = assignBoards(settings, nbPlayers)
- val decks = decksDefinition.prepareDecks(settings.nbPlayers, settings.random)
+ val allWonders: List<PreGameWonder> = wonderDefinitions.map { w ->
+ PreGameWonder(
+ w.name,
+ w.sides.mapValues { (_, def) -> def.image })
+ }
+
+ private val wondersByName = wonderDefinitions.associateBy { it.name }
+
+ fun createGame(id: Long, wonders: Collection<AssignedWonder>, settings: Settings): Game {
+ val nbPlayers = wonders.size
+ val boards = wonders.mapIndexed { index, wonder -> wonder.createBoard(index, settings) }
+ val decks = decksDefinition.prepareDecks(nbPlayers, settings.random)
return Game(id, settings, boards, decks)
}
- private fun assignBoards(settings: Settings, nbPlayers: Int): List<Board> {
- return wonders.shuffled(settings.random)
- .take(nbPlayers)
- .mapIndexed { i, wDef -> Board(wDef.create(settings.pickWonderSide()), i, settings) }
+ private fun AssignedWonder.createBoard(playerIndex: Int, settings: Settings): Board {
+ val wonder = wondersByName[name] ?: error("Unknown wonder '$name'")
+ return Board(wonder.create(side), playerIndex, settings)
}
companion object {
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/definitions/WonderDefinition.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/definitions/WonderDefinition.kt
index 4c5c8e09..58964e83 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/definitions/WonderDefinition.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/data/definitions/WonderDefinition.kt
@@ -3,12 +3,13 @@ package org.luxons.sevenwonders.engine.data.definitions
import org.luxons.sevenwonders.engine.cards.Requirements
import org.luxons.sevenwonders.engine.wonders.Wonder
import org.luxons.sevenwonders.engine.wonders.WonderStage
-import org.luxons.sevenwonders.model.WonderSide
+import org.luxons.sevenwonders.model.wonders.WonderName
+import org.luxons.sevenwonders.model.wonders.WonderSide
import org.luxons.sevenwonders.model.resources.ResourceType
internal class WonderDefinition(
- private val name: String,
- private val sides: Map<WonderSide, WonderSideDefinition>
+ val name: WonderName,
+ val sides: Map<WonderSide, WonderSideDefinition>
) {
fun create(wonderSide: WonderSide): Wonder = sides[wonderSide]!!.createWonder(name)
}
@@ -16,7 +17,7 @@ internal class WonderDefinition(
internal class WonderSideDefinition(
private val initialResource: ResourceType,
private val stages: List<WonderStageDefinition>,
- private val image: String
+ val image: String
) {
fun createWonder(name: String): Wonder = Wonder(name, initialResource, stages.map { it.create() }, image)
}
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/BuildWonderMove.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/BuildWonderMove.kt
index 942d9db1..aaa26f7e 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/BuildWonderMove.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/BuildWonderMove.kt
@@ -1,8 +1,8 @@
package org.luxons.sevenwonders.engine.moves
import org.luxons.sevenwonders.engine.PlayerContext
-import org.luxons.sevenwonders.engine.Settings
import org.luxons.sevenwonders.engine.cards.Card
+import org.luxons.sevenwonders.model.Settings
import org.luxons.sevenwonders.model.PlayerMove
internal class BuildWonderMove(move: PlayerMove, card: Card, player: PlayerContext) :
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/CopyGuildMove.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/CopyGuildMove.kt
index 9cb57481..c3ba8e9a 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/CopyGuildMove.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/CopyGuildMove.kt
@@ -1,9 +1,9 @@
package org.luxons.sevenwonders.engine.moves
import org.luxons.sevenwonders.engine.PlayerContext
-import org.luxons.sevenwonders.engine.Settings
import org.luxons.sevenwonders.engine.cards.Card
import org.luxons.sevenwonders.engine.effects.SpecialAbility
+import org.luxons.sevenwonders.model.Settings
import org.luxons.sevenwonders.model.PlayerMove
import org.luxons.sevenwonders.model.boards.RelativeBoardPosition
import org.luxons.sevenwonders.model.cards.Color
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/DiscardMove.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/DiscardMove.kt
index a8f2aebf..92fb4952 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/DiscardMove.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/DiscardMove.kt
@@ -1,8 +1,8 @@
package org.luxons.sevenwonders.engine.moves
import org.luxons.sevenwonders.engine.PlayerContext
-import org.luxons.sevenwonders.engine.Settings
import org.luxons.sevenwonders.engine.cards.Card
+import org.luxons.sevenwonders.model.Settings
import org.luxons.sevenwonders.model.PlayerMove
internal class DiscardMove(move: PlayerMove, card: Card, player: PlayerContext) :
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/Move.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/Move.kt
index 1035c1b8..a1790baa 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/Move.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/Move.kt
@@ -1,8 +1,8 @@
package org.luxons.sevenwonders.engine.moves
import org.luxons.sevenwonders.engine.PlayerContext
-import org.luxons.sevenwonders.engine.Settings
import org.luxons.sevenwonders.engine.cards.Card
+import org.luxons.sevenwonders.model.Settings
import org.luxons.sevenwonders.model.MoveType
import org.luxons.sevenwonders.model.PlayerMove
import org.luxons.sevenwonders.model.resources.ResourceTransactions
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayCardMove.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayCardMove.kt
index 17b1a48a..250424c7 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayCardMove.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayCardMove.kt
@@ -1,8 +1,8 @@
package org.luxons.sevenwonders.engine.moves
import org.luxons.sevenwonders.engine.PlayerContext
-import org.luxons.sevenwonders.engine.Settings
import org.luxons.sevenwonders.engine.cards.Card
+import org.luxons.sevenwonders.model.Settings
import org.luxons.sevenwonders.model.PlayerMove
internal class PlayCardMove(move: PlayerMove, card: Card, player: PlayerContext) :
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeCardMove.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeCardMove.kt
index 310500c7..acaa2c95 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeCardMove.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeCardMove.kt
@@ -1,8 +1,8 @@
package org.luxons.sevenwonders.engine.moves
import org.luxons.sevenwonders.engine.PlayerContext
-import org.luxons.sevenwonders.engine.Settings
import org.luxons.sevenwonders.engine.cards.Card
+import org.luxons.sevenwonders.model.Settings
import org.luxons.sevenwonders.model.PlayerMove
internal class PlayFreeCardMove(move: PlayerMove, card: Card, playerContext: PlayerContext) :
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeDiscardedCardMove.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeDiscardedCardMove.kt
index 5147ed82..2fc03c92 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeDiscardedCardMove.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/moves/PlayFreeDiscardedCardMove.kt
@@ -1,9 +1,9 @@
package org.luxons.sevenwonders.engine.moves
import org.luxons.sevenwonders.engine.PlayerContext
-import org.luxons.sevenwonders.engine.Settings
import org.luxons.sevenwonders.engine.cards.Card
import org.luxons.sevenwonders.engine.effects.SpecialAbility
+import org.luxons.sevenwonders.model.Settings
import org.luxons.sevenwonders.model.PlayerMove
internal class PlayFreeDiscardedCardMove(
bgstack15