summaryrefslogtreecommitdiff
path: root/sw-common-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'sw-common-model/src')
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/CustomizableSettings.kt47
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Settings.kt18
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt (renamed from sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt)26
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Player.kt28
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt21
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt2
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt31
-rw-r--r--sw-common-model/src/commonTest/kotlin/org/luxons/sevenwonders/model/WonderSidePickMethodTest.kt91
8 files changed, 97 insertions, 167 deletions
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/CustomizableSettings.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/CustomizableSettings.kt
deleted file mode 100644
index 86a11bc1..00000000
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/CustomizableSettings.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.luxons.sevenwonders.model
-
-import kotlinx.serialization.Serializable
-import kotlin.random.Random
-
-@Serializable
-data class CustomizableSettings(
- val randomSeedForTests: Long? = null,
- val timeLimitInSeconds: Int = 45,
- val wonderSidePickMethod: WonderSidePickMethod = WonderSidePickMethod.EACH_RANDOM,
- val initialGold: Int = 3,
- val discardedCardGold: Int = 3,
- val defaultTradingCost: Int = 2,
- val pointsPer3Gold: Int = 1,
- val lostPointsPerDefeat: Int = 1,
- val wonPointsPerVictoryPerAge: Map<Int, Int> = mapOf(1 to 1, 2 to 3, 3 to 5)
-)
-
-enum class WonderSide {
- A,
- B
-}
-
-enum class WonderSidePickMethod {
- ALL_A {
- override fun pickSide(random: Random, lastPickedSide: WonderSide?): WonderSide {
- return WonderSide.A
- }
- },
- ALL_B {
- override fun pickSide(random: Random, lastPickedSide: WonderSide?): WonderSide {
- return WonderSide.B
- }
- },
- EACH_RANDOM {
- override fun pickSide(random: Random, lastPickedSide: WonderSide?): WonderSide {
- return if (random.nextBoolean()) WonderSide.A else WonderSide.B
- }
- },
- SAME_RANDOM_FOR_ALL {
- override fun pickSide(random: Random, lastPickedSide: WonderSide?): WonderSide {
- return lastPickedSide ?: if (random.nextBoolean()) WonderSide.A else WonderSide.B
- }
- };
-
- abstract fun pickSide(random: Random, lastPickedSide: WonderSide?): WonderSide
-}
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Settings.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Settings.kt
new file mode 100644
index 00000000..21be1c1b
--- /dev/null
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Settings.kt
@@ -0,0 +1,18 @@
+package org.luxons.sevenwonders.model
+
+import kotlinx.serialization.Serializable
+import kotlin.random.Random
+
+@Serializable
+data class Settings(
+ val randomSeedForTests: Long? = null,
+ val timeLimitInSeconds: Int = 45,
+ val initialGold: Int = 3,
+ val discardedCardGold: Int = 3,
+ val defaultTradingCost: Int = 2,
+ val pointsPer3Gold: Int = 1,
+ val lostPointsPerDefeat: Int = 1,
+ val wonPointsPerVictoryPerAge: Map<Int, Int> = mapOf(1 to 1, 2 to 3, 3 to 5)
+) {
+ val random: Random by lazy { randomSeedForTests?.let { Random(it) } ?: Random }
+}
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt
index d22a350a..1438600a 100644
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt
@@ -1,7 +1,7 @@
package org.luxons.sevenwonders.model.api
import kotlinx.serialization.Serializable
-import org.luxons.sevenwonders.model.api.actions.Icon
+import org.luxons.sevenwonders.model.wonders.PreGameWonder
const val SEVEN_WONDERS_WS_ENDPOINT = "/seven-wonders-websocket"
@@ -15,6 +15,7 @@ data class LobbyDTO(
val name: String,
val owner: String,
val players: List<PlayerDTO>,
+ val allWonders: List<PreGameWonder>,
val state: State,
val hasEnoughPlayers: Boolean,
val maxPlayersReached: Boolean
@@ -43,26 +44,3 @@ data class Actionability(
val canDo: Boolean,
val tooltip: String
)
-
-interface BasicPlayerInfo {
- val username: String
- val displayName: String
- val icon: Icon?
-}
-
-@Serializable
-data class ConnectedPlayer(
- override val username: String,
- override val displayName: String,
- override val icon: Icon?
-) : BasicPlayerInfo
-
-@Serializable
-data class PlayerDTO(
- override val username: String,
- override val displayName: String,
- override val icon: Icon?,
- val index: Int,
- val isGameOwner: Boolean,
- val isReady: Boolean
-) : BasicPlayerInfo
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Player.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Player.kt
new file mode 100644
index 00000000..7161b53d
--- /dev/null
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Player.kt
@@ -0,0 +1,28 @@
+package org.luxons.sevenwonders.model.api
+
+import kotlinx.serialization.Serializable
+import org.luxons.sevenwonders.model.api.actions.Icon
+import org.luxons.sevenwonders.model.wonders.AssignedWonder
+
+interface BasicPlayerInfo {
+ val username: String
+ val displayName: String
+ val icon: Icon?
+}
+
+@Serializable
+data class ConnectedPlayer(
+ override val username: String,
+ override val displayName: String,
+ override val icon: Icon?
+) : BasicPlayerInfo
+
+@Serializable
+data class PlayerDTO(
+ override val username: String,
+ override val displayName: String,
+ override val icon: Icon?,
+ val wonder: AssignedWonder,
+ val isGameOwner: Boolean,
+ val isReady: Boolean
+) : BasicPlayerInfo
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt
index 0687e968..4a721a94 100644
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt
@@ -1,7 +1,8 @@
package org.luxons.sevenwonders.model.api.actions
import kotlinx.serialization.Serializable
-import org.luxons.sevenwonders.model.CustomizableSettings
+import org.luxons.sevenwonders.model.wonders.AssignedWonder
+import org.luxons.sevenwonders.model.Settings
import org.luxons.sevenwonders.model.PlayerMove
/**
@@ -58,8 +59,8 @@ class PrepareMoveAction(
)
/**
- * The action to update the order of the players around the table. Can only be called in the lobby by the owner of the
- * game.
+ * The action to update the order of the players around the table.
+ * Can only be called in the lobby by the owner of the game.
*/
@Serializable
class ReorderPlayersAction(
@@ -70,6 +71,18 @@ class ReorderPlayersAction(
)
/**
+ * The action to update the wonders assigned to each player.
+ * Can only be called in the lobby by the owner of the game.
+ */
+@Serializable
+class ReassignWondersAction(
+ /**
+ * The list of wonders assigned to each player, in the players' order.
+ */
+ val assignedWonders: List<AssignedWonder>
+)
+
+/**
* The action to update the settings of the game. Can only be called in the lobby by the owner of the game.
*/
@Serializable
@@ -77,7 +90,7 @@ class UpdateSettingsAction(
/**
* The new values for the settings.
*/
- val settings: CustomizableSettings
+ val settings: Settings
)
/**
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt
index 96027612..b0e73ed5 100644
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt
@@ -46,7 +46,7 @@ data class HandCard(
@Serializable
data class PreparedCard(
- val player: PlayerDTO,
+ val username: String,
val cardBack: CardBack?
)
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt
index 9e9a5b38..888e1c47 100644
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt
@@ -6,6 +6,37 @@ import org.luxons.sevenwonders.model.cards.CardBack
import org.luxons.sevenwonders.model.cards.PlayabilityLevel
import org.luxons.sevenwonders.model.resources.ResourceTransactions
import org.luxons.sevenwonders.model.resources.ResourceType
+import kotlin.random.Random
+
+typealias WonderName = String
+
+@Serializable
+data class PreGameWonder(
+ val name: WonderName,
+ val images: Map<WonderSide, String>
+)
+
+@Serializable
+data class AssignedWonder(
+ val name: WonderName,
+ val side: WonderSide,
+ val image: String
+)
+
+@Serializable
+enum class WonderSide {
+ A,
+ B
+}
+
+fun List<PreGameWonder>.deal(nbPlayers: Int, random: Random = Random): List<AssignedWonder> =
+ shuffled(random).take(nbPlayers).map { it.withRandomSide(random) }
+
+fun PreGameWonder.withRandomSide(random: Random = Random): AssignedWonder {
+ val side = WonderSide.values().random(random)
+ val sideImage = images.getValue(side)
+ return AssignedWonder(name, side, sideImage)
+}
@Serializable
data class ApiWonder(
diff --git a/sw-common-model/src/commonTest/kotlin/org/luxons/sevenwonders/model/WonderSidePickMethodTest.kt b/sw-common-model/src/commonTest/kotlin/org/luxons/sevenwonders/model/WonderSidePickMethodTest.kt
deleted file mode 100644
index 70a061e3..00000000
--- a/sw-common-model/src/commonTest/kotlin/org/luxons/sevenwonders/model/WonderSidePickMethodTest.kt
+++ /dev/null
@@ -1,91 +0,0 @@
-package org.luxons.sevenwonders.model
-
-import kotlin.random.Random
-import kotlin.test.BeforeTest
-import kotlin.test.Test
-import kotlin.test.assertEquals
-
-class WonderSidePickMethodTest {
-
- private lateinit var random: Random
-
- private lateinit var random2: Random
-
- @BeforeTest
- fun setUp() {
- random = Random(421) // starts with TRUE
- random2 = Random(42) // starts with FALSE
- }
-
- @Test
- fun pick_allA() {
- var side: WonderSide? = null
- repeat(10) {
- side = WonderSidePickMethod.ALL_A.pickSide(random, side)
- assertEquals(WonderSide.A, side)
- }
- }
-
- @Test
- fun pick_allB() {
- var side: WonderSide? = null
- repeat(10) {
- side = WonderSidePickMethod.ALL_B.pickSide(random, side)
- assertEquals(WonderSide.B, side)
- }
- }
-
- @Test
- fun pick_eachRandom() {
- var side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, null)
- assertEquals(WonderSide.A, side)
- side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, side)
- assertEquals(WonderSide.A, side)
- side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, side)
- assertEquals(WonderSide.B, side)
- side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, side)
- assertEquals(WonderSide.A, side)
- side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, side)
- assertEquals(WonderSide.B, side)
- side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, side)
- assertEquals(WonderSide.B, side)
- }
-
- @Test
- fun pick_eachRandom2() {
- var side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, null)
- assertEquals(WonderSide.B, side)
- side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, side)
- assertEquals(WonderSide.B, side)
- side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, side)
- assertEquals(WonderSide.A, side)
- side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, side)
- assertEquals(WonderSide.A, side)
- side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, side)
- assertEquals(WonderSide.B, side)
- side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, side)
- assertEquals(WonderSide.B, side)
- }
-
- @Test
- fun pick_allSameRandom_sameAsFirst() {
- repeat(10) {
- val side = WonderSidePickMethod.SAME_RANDOM_FOR_ALL.pickSide(random,
- WonderSide.A
- )
- assertEquals(WonderSide.A, side)
- }
- repeat(10) {
- val side = WonderSidePickMethod.SAME_RANDOM_FOR_ALL.pickSide(random,
- WonderSide.B
- )
- assertEquals(WonderSide.B, side)
- }
- }
-
- @Test
- fun pick_allSameRandom_firstIsRandom() {
- assertEquals(WonderSide.A, WonderSidePickMethod.SAME_RANDOM_FOR_ALL.pickSide(random, null))
- assertEquals(WonderSide.B, WonderSidePickMethod.SAME_RANDOM_FOR_ALL.pickSide(random2, null))
- }
-}
bgstack15