Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e9bb2feaf | ||
|
|
cc33dffd9a | ||
|
|
6c311ad304 |
@@ -51,8 +51,8 @@ integration:
|
|||||||
|
|
||||||
## Katan
|
## Katan
|
||||||
|
|
||||||
The island game is catalogue id `catan`, shown as **Katan**. It has two rule
|
The island game is catalogue id `catan`, shown as **Katan**. It has two expansions
|
||||||
sets chosen at setup: the base game (`docs/RULES-catan.md`), Cities & Knights
|
(toggles, `CatanOptions.expansions`; none on is the base game): the base game (`docs/RULES-catan.md`), Cities & Knights
|
||||||
(`docs/RULES-catan-ck.md`, code in `game/catan/CatanCk*.kt`, state behind
|
(`docs/RULES-catan-ck.md`, code in `game/catan/CatanCk*.kt`, state behind
|
||||||
`CatanState.ck`, which is null in the base game) and Seafarers
|
`CatanState.ck`, which is null in the base game) and Seafarers
|
||||||
(`docs/RULES-catan-seafarers.md`, code in `game/catan/CatanSea*.kt`, state behind
|
(`docs/RULES-catan-seafarers.md`, code in `game/catan/CatanSea*.kt`, state behind
|
||||||
|
|||||||
@@ -646,7 +646,7 @@ class CatanAi(private val profiles: AiProfiles = AiProfiles.DEFAULT) : GameAi<Ca
|
|||||||
if (!seen.add(v)) continue
|
if (!seen.add(v)) continue
|
||||||
if (CatanRules.vertexOpenForSettlement(state, v)) {
|
if (CatanRules.vertexOpenForSettlement(state, v)) {
|
||||||
val island = topo.vertexIsland[v]
|
val island = topo.vertexIsland[v]
|
||||||
val fresh = island >= 0 && island != sea.home && sea.islandBonus[island] == NO_PLAYER
|
val fresh = island >= 0 && !sea.isStart(island) && sea.islandBonus[island] == NO_PLAYER
|
||||||
val value = (spotValue(state, v) + if (fresh) 0.5 else 0.0) * Math.pow(0.85, depth.toDouble())
|
val value = (spotValue(state, v) + if (fresh) 0.5 else 0.0) * Math.pow(0.85, depth.toDouble())
|
||||||
best = maxOf(best, value)
|
best = maxOf(best, value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
package org.prolibertate.games.game.catan
|
package org.prolibertate.games.game.catan
|
||||||
|
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
import kotlinx.serialization.json.JsonArray
|
||||||
|
import kotlinx.serialization.json.JsonDecoder
|
||||||
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
|
import kotlinx.serialization.json.jsonObject
|
||||||
|
|
||||||
/** Sentinel stored in [CatanState.roads] for an unclaimed road position. */
|
/** Sentinel stored in [CatanState.roads] for an unclaimed road position. */
|
||||||
const val NO_PLAYER = -1
|
const val NO_PLAYER = -1
|
||||||
@@ -151,12 +160,9 @@ enum class CatanPhase {
|
|||||||
CHORE,
|
CHORE,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Which rules a table plays. The expansion is a whole rule set, not a toggle. */
|
/** An expansion a table can switch on. The base game is what is left with none selected. */
|
||||||
@Serializable
|
@Serializable
|
||||||
enum class CatanRuleSet {
|
enum class CatanExpansion {
|
||||||
/** The base game: development cards, Largest Army, a robber from the start. */
|
|
||||||
BASE,
|
|
||||||
|
|
||||||
/** Cities & Knights: commodities, knights, barbarians, city improvements. */
|
/** Cities & Knights: commodities, knights, barbarians, city improvements. */
|
||||||
CITIES_AND_KNIGHTS,
|
CITIES_AND_KNIGHTS,
|
||||||
|
|
||||||
@@ -164,15 +170,58 @@ enum class CatanRuleSet {
|
|||||||
SEAFARERS,
|
SEAFARERS,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
/**
|
||||||
|
* What a table plays: the expansions switched on, and the Seafarers map when that one is.
|
||||||
|
*
|
||||||
|
* Saves written before expansions became toggles carry `"ruleSet"` instead of `"expansions"`;
|
||||||
|
* [CatanOptionsSerializer] reads either.
|
||||||
|
*/
|
||||||
|
@Serializable(with = CatanOptionsSerializer::class)
|
||||||
data class CatanOptions(
|
data class CatanOptions(
|
||||||
val playerCount: Int = 3,
|
val playerCount: Int = 3,
|
||||||
val pointsToWin: Int = 10,
|
val pointsToWin: Int = 10,
|
||||||
val ruleSet: CatanRuleSet = CatanRuleSet.BASE,
|
val expansions: Set<CatanExpansion> = emptySet(),
|
||||||
|
val scenario: SeaScenario = SeaScenario.NEW_SHORES,
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
require(playerCount in 3..4) { "The island seats three or four players" }
|
require(playerCount in 3..4) { "The island seats three or four players" }
|
||||||
require(pointsToWin >= 2) { "pointsToWin must be at least 2" }
|
require(pointsToWin >= 2) { "pointsToWin must be at least 2" }
|
||||||
|
// Lifted once Cities & Knights runs on a Seafarers map.
|
||||||
|
require(expansions.size <= 1) { "Combining expansions is not supported yet" }
|
||||||
|
}
|
||||||
|
|
||||||
|
val seafarers: Boolean get() = CatanExpansion.SEAFARERS in expansions
|
||||||
|
val citiesAndKnights: Boolean get() = CatanExpansion.CITIES_AND_KNIGHTS in expansions
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The wire shape of [CatanOptions]. */
|
||||||
|
@Serializable
|
||||||
|
private class CatanOptionsWire(
|
||||||
|
val playerCount: Int = 3,
|
||||||
|
val pointsToWin: Int = 10,
|
||||||
|
val expansions: Set<CatanExpansion> = emptySet(),
|
||||||
|
val scenario: SeaScenario = SeaScenario.NEW_SHORES,
|
||||||
|
)
|
||||||
|
|
||||||
|
/** Reads the legacy single `ruleSet` field as an expansion set. */
|
||||||
|
object CatanOptionsSerializer : KSerializer<CatanOptions> {
|
||||||
|
override val descriptor: SerialDescriptor = CatanOptionsWire.serializer().descriptor
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: CatanOptions) = encoder.encodeSerializableValue(
|
||||||
|
CatanOptionsWire.serializer(),
|
||||||
|
CatanOptionsWire(value.playerCount, value.pointsToWin, value.expansions, value.scenario),
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): CatanOptions {
|
||||||
|
val input = decoder as JsonDecoder
|
||||||
|
var obj = input.decodeJsonElement().jsonObject
|
||||||
|
val legacy = (obj["ruleSet"] as? JsonPrimitive)?.content
|
||||||
|
if (legacy != null) {
|
||||||
|
val expansions = if (legacy == "BASE") emptyList() else listOf(JsonPrimitive(legacy))
|
||||||
|
obj = JsonObject(obj - "ruleSet" + ("expansions" to JsonArray(expansions)))
|
||||||
|
}
|
||||||
|
val wire = input.json.decodeFromJsonElement(CatanOptionsWire.serializer(), obj)
|
||||||
|
return CatanOptions(wire.playerCount, wire.pointsToWin, wire.expansions, wire.scenario)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,12 +465,17 @@ data class SeaState(
|
|||||||
val shipMoved: Boolean = false,
|
val shipMoved: Boolean = false,
|
||||||
/** Who holds the "new island" bonus for each island, or [NO_PLAYER]. The home island's is never awarded. */
|
/** Who holds the "new island" bonus for each island, or [NO_PLAYER]. The home island's is never awarded. */
|
||||||
val islandBonus: List<Int>,
|
val islandBonus: List<Int>,
|
||||||
/** The island the players start on. */
|
/** The island that counts as home: the largest, and the pirate-free start of the original map. */
|
||||||
val home: Int,
|
val home: Int,
|
||||||
|
/** The islands the starting settlements may go on. Empty in a save from before there were several: just [home]. */
|
||||||
|
val starts: List<Int> = emptyList(),
|
||||||
/** Gold owed after a roll, front first: each seat chooses [GoldOwed.count] cards. */
|
/** Gold owed after a roll, front first: each seat chooses [GoldOwed.count] cards. */
|
||||||
val gold: List<GoldOwed> = emptyList(),
|
val gold: List<GoldOwed> = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** Whether [island] is one the game starts on, and so never earns the new-island bonus. */
|
||||||
|
fun SeaState.isStart(island: Int): Boolean = island == home || island in starts
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GoldOwed(val seat: Int, val count: Int)
|
data class GoldOwed(val seat: Int, val count: Int)
|
||||||
|
|
||||||
|
|||||||
@@ -54,15 +54,15 @@ object CatanRules : GameRules<CatanState, CatanMove> {
|
|||||||
"Seat count ${config.seats.size} does not match ${options.playerCount} players"
|
"Seat count ${config.seats.size} does not match ${options.playerCount} players"
|
||||||
}
|
}
|
||||||
|
|
||||||
val sea = options.ruleSet == CatanRuleSet.SEAFARERS
|
val sea = options.seafarers
|
||||||
val scenario = SeaScenario.NEW_SHORES
|
val scenario = options.scenario
|
||||||
val seaBoard = if (sea) SeaBoards.generate(scenario, config.seed) else null
|
val seaBoard = if (sea) SeaBoards.generate(scenario, config.seed) else null
|
||||||
val topo = if (seaBoard != null) SeaBoards.topology(scenario) else CatanBoard.base
|
val topo = if (seaBoard != null) SeaBoards.topology(scenario) else CatanBoard.base
|
||||||
val board = seaBoard?.let { CatanBoard.Generated(it.terrains, it.numbers, it.robber, it.ports) }
|
val board = seaBoard?.let { CatanBoard.Generated(it.terrains, it.numbers, it.robber, it.ports) }
|
||||||
?: CatanBoard.generate(config.seed)
|
?: CatanBoard.generate(config.seed)
|
||||||
// A different random stream than the island, so the same seed still
|
// A different random stream than the island, so the same seed still
|
||||||
// produces both a fixed island and a fixed deck.
|
// produces both a fixed island and a fixed deck.
|
||||||
val ck = options.ruleSet == CatanRuleSet.CITIES_AND_KNIGHTS
|
val ck = options.citiesAndKnights
|
||||||
// Cities & Knights has no development cards: knights and progress
|
// Cities & Knights has no development cards: knights and progress
|
||||||
// cards take their place.
|
// cards take their place.
|
||||||
val devDeck = if (ck) {
|
val devDeck = if (ck) {
|
||||||
@@ -119,6 +119,7 @@ object CatanRules : GameRules<CatanState, CatanMove> {
|
|||||||
pirate = it.pirate,
|
pirate = it.pirate,
|
||||||
islandBonus = List(topo.islandCount) { NO_PLAYER },
|
islandBonus = List(topo.islandCount) { NO_PLAYER },
|
||||||
home = it.home,
|
home = it.home,
|
||||||
|
starts = it.starts,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -207,8 +208,8 @@ object CatanRules : GameRules<CatanState, CatanMove> {
|
|||||||
val moves = mutableListOf<SetupPlace>()
|
val moves = mutableListOf<SetupPlace>()
|
||||||
for (v in 0 until state.topo.VERTEX_COUNT) {
|
for (v in 0 until state.topo.VERTEX_COUNT) {
|
||||||
if (!vertexOpenForSettlement(state, v)) continue
|
if (!vertexOpenForSettlement(state, v)) continue
|
||||||
// Seafarers: everyone starts on the home island.
|
// Seafarers: the starting settlements go on a starting island.
|
||||||
if (state.sea != null && state.topo.vertexIsland[v] != state.sea.home) continue
|
if (state.sea != null && !state.sea.isStart(state.topo.vertexIsland[v])) continue
|
||||||
for (e in state.topo.VERTEX_EDGES[v]) {
|
for (e in state.topo.VERTEX_EDGES[v]) {
|
||||||
if (state.roads[e] != NO_PLAYER || !state.topo.edgeLand[e]) continue
|
if (state.roads[e] != NO_PLAYER || !state.topo.edgeLand[e]) continue
|
||||||
moves += SetupPlace(v, e)
|
moves += SetupPlace(v, e)
|
||||||
|
|||||||
@@ -5,11 +5,29 @@ import kotlin.random.Random
|
|||||||
|
|
||||||
/** The Seafarers maps on offer. Each is a fixed arrangement of land and sea; the tiles and numbers on it are shuffled. */
|
/** The Seafarers maps on offer. Each is a fixed arrangement of land and sea; the tiles and numbers on it are shuffled. */
|
||||||
@Serializable
|
@Serializable
|
||||||
enum class SeaScenario(val title: String, val blurb: String) {
|
enum class SeaScenario(val title: String, val blurb: String, val start: SeaStart = SeaStart.HOME_ONLY) {
|
||||||
NEW_SHORES(
|
NEW_SHORES(
|
||||||
"Heading for New Shores",
|
"Heading for New Shores",
|
||||||
"One large home island and three small ones to find by ship. Gold fields on two of the small islands.",
|
"One large home island and three small ones to find by ship. Gold fields on two of the small islands.",
|
||||||
),
|
),
|
||||||
|
FOUR_ISLANDS(
|
||||||
|
"Four Islands",
|
||||||
|
"Four equal islands, one start each, and two gold islets in the middle. Settle your own island, then sail.",
|
||||||
|
SeaStart.MAIN_ISLANDS,
|
||||||
|
),
|
||||||
|
THROUGH_THE_DESERT(
|
||||||
|
"Through the Desert",
|
||||||
|
"One island cut by a broad desert that yields nothing. Reach the far side by road, or sail round to the islets.",
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Where the starting settlements may go. */
|
||||||
|
enum class SeaStart {
|
||||||
|
/** The largest island only. */
|
||||||
|
HOME_ONLY,
|
||||||
|
|
||||||
|
/** Any island big enough to live on (four hexes or more); the small ones are prizes to sail to. */
|
||||||
|
MAIN_ISLANDS,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,8 +51,34 @@ object SeaBoards {
|
|||||||
"..........",
|
"..........",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val FOUR_ISLANDS_MAP = listOf(
|
||||||
|
"............",
|
||||||
|
"..###..###..",
|
||||||
|
"..###..###..",
|
||||||
|
"............",
|
||||||
|
"..$.....$...",
|
||||||
|
"............",
|
||||||
|
"..###..###..",
|
||||||
|
"..###..###..",
|
||||||
|
"............",
|
||||||
|
)
|
||||||
|
|
||||||
|
private val THROUGH_THE_DESERT_MAP = listOf(
|
||||||
|
"............",
|
||||||
|
".###DD###...",
|
||||||
|
".###DDD###..",
|
||||||
|
"..###DD###..",
|
||||||
|
"............",
|
||||||
|
"..$.....$...",
|
||||||
|
"............",
|
||||||
|
"...##...#...",
|
||||||
|
"............",
|
||||||
|
)
|
||||||
|
|
||||||
private fun rows(scenario: SeaScenario): List<String> = when (scenario) {
|
private fun rows(scenario: SeaScenario): List<String> = when (scenario) {
|
||||||
SeaScenario.NEW_SHORES -> NEW_SHORES_MAP
|
SeaScenario.NEW_SHORES -> NEW_SHORES_MAP
|
||||||
|
SeaScenario.FOUR_ISLANDS -> FOUR_ISLANDS_MAP
|
||||||
|
SeaScenario.THROUGH_THE_DESERT -> THROUGH_THE_DESERT_MAP
|
||||||
}
|
}
|
||||||
|
|
||||||
private val topologies = HashMap<SeaScenario, Topology>()
|
private val topologies = HashMap<SeaScenario, Topology>()
|
||||||
@@ -72,8 +116,13 @@ object SeaBoards {
|
|||||||
val pirate: Int,
|
val pirate: Int,
|
||||||
val ports: List<Port>,
|
val ports: List<Port>,
|
||||||
val home: Int,
|
val home: Int,
|
||||||
|
/** The islands the starting settlements may go on; always includes [home]. */
|
||||||
|
val starts: List<Int> = listOf(home),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** An island of this many land hexes or more can be started on. */
|
||||||
|
private const val MAIN_ISLAND_HEXES = 4
|
||||||
|
|
||||||
private val RESOURCE_TILES = listOf(
|
private val RESOURCE_TILES = listOf(
|
||||||
Terrain.FOREST, Terrain.PASTURE, Terrain.FIELDS, Terrain.HILLS, Terrain.MOUNTAINS,
|
Terrain.FOREST, Terrain.PASTURE, Terrain.FIELDS, Terrain.HILLS, Terrain.MOUNTAINS,
|
||||||
)
|
)
|
||||||
@@ -139,6 +188,13 @@ object SeaBoards {
|
|||||||
} ?: 0
|
} ?: 0
|
||||||
} ?: sea.first()
|
} ?: sea.first()
|
||||||
|
|
||||||
return Generated(terrains, numbers.toList(), desert, pirate, ports, home)
|
val starts = when (scenario.start) {
|
||||||
|
SeaStart.HOME_ONLY -> listOf(home)
|
||||||
|
SeaStart.MAIN_ISLANDS -> (0 until topo.islandCount).filter { island ->
|
||||||
|
topo.islandOf.count { it == island } >= MAIN_ISLAND_HEXES
|
||||||
|
}.ifEmpty { listOf(home) }
|
||||||
|
}
|
||||||
|
|
||||||
|
return Generated(terrains, numbers.toList(), desert, pirate, ports, home, starts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ internal object SeaRules {
|
|||||||
fun claimIsland(state: CatanState, seat: Int, vertex: Int): CatanState {
|
fun claimIsland(state: CatanState, seat: Int, vertex: Int): CatanState {
|
||||||
val sea = state.sea ?: return state
|
val sea = state.sea ?: return state
|
||||||
val island = state.topo.vertexIsland[vertex]
|
val island = state.topo.vertexIsland[vertex]
|
||||||
if (island < 0 || island == sea.home || sea.islandBonus[island] != NO_PLAYER) return state
|
if (island < 0 || sea.isStart(island) || sea.islandBonus[island] != NO_PLAYER) return state
|
||||||
val bonus = sea.islandBonus.toMutableList().also { it[island] = seat }
|
val bonus = sea.islandBonus.toMutableList().also { it[island] = seat }
|
||||||
return state.copy(
|
return state.copy(
|
||||||
sea = sea.copy(islandBonus = bonus),
|
sea = sea.copy(islandBonus = bonus),
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ import org.prolibertate.games.game.morris.MorrisOptions
|
|||||||
import org.prolibertate.games.game.pirates.PiratesOptions
|
import org.prolibertate.games.game.pirates.PiratesOptions
|
||||||
import org.prolibertate.games.game.president.PresidentOptions
|
import org.prolibertate.games.game.president.PresidentOptions
|
||||||
import org.prolibertate.games.game.catan.CatanOptions
|
import org.prolibertate.games.game.catan.CatanOptions
|
||||||
import org.prolibertate.games.game.catan.CatanRuleSet
|
import org.prolibertate.games.game.catan.CatanExpansion
|
||||||
|
import org.prolibertate.games.game.catan.SeaScenario
|
||||||
import org.prolibertate.games.game.sequence.SequenceOptions
|
import org.prolibertate.games.game.sequence.SequenceOptions
|
||||||
import org.prolibertate.games.game.tayu.TayuLevel
|
import org.prolibertate.games.game.tayu.TayuLevel
|
||||||
import org.prolibertate.games.game.tayu.TayuOptions
|
import org.prolibertate.games.game.tayu.TayuOptions
|
||||||
@@ -373,47 +374,48 @@ fun teamForSeat(gameId: String, seat: Int, seatCount: Int): Int = when (gameId)
|
|||||||
else -> seat
|
else -> seat
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The targets the setup screen offers for a Katan rule set. */
|
/** The targets the setup screen offers for a Katan game with [expansions] on. */
|
||||||
internal fun catanPointsChoices(ruleSet: CatanRuleSet): List<Int> = when (ruleSet) {
|
internal fun catanPointsChoices(expansions: Set<CatanExpansion>): List<Int> = when {
|
||||||
// Five is a short game for trying things out; ten is the published target.
|
|
||||||
CatanRuleSet.BASE -> listOf(5, 8, 10, 12)
|
|
||||||
// Cities & Knights is played to thirteen, which is also why it runs longer.
|
|
||||||
CatanRuleSet.CITIES_AND_KNIGHTS -> listOf(8, 10, 13, 15)
|
|
||||||
// Seafarers adds two points for each new island, so the target is higher.
|
// Seafarers adds two points for each new island, so the target is higher.
|
||||||
CatanRuleSet.SEAFARERS -> listOf(8, 10, 12, 14)
|
CatanExpansion.SEAFARERS in expansions -> listOf(8, 10, 12, 14)
|
||||||
|
// Cities & Knights is played to thirteen, which is also why it runs longer.
|
||||||
|
CatanExpansion.CITIES_AND_KNIGHTS in expansions -> listOf(8, 10, 13, 15)
|
||||||
|
// Five is a short game for trying things out; ten is the published target.
|
||||||
|
else -> listOf(5, 8, 10, 12)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The published target for a rule set. */
|
/** The published target for a game with [expansions] on. */
|
||||||
internal fun catanDefaultPoints(ruleSet: CatanRuleSet): Int = when (ruleSet) {
|
internal fun catanDefaultPoints(expansions: Set<CatanExpansion>): Int = when {
|
||||||
CatanRuleSet.BASE -> 10
|
CatanExpansion.SEAFARERS in expansions -> 12
|
||||||
CatanRuleSet.CITIES_AND_KNIGHTS -> 13
|
CatanExpansion.CITIES_AND_KNIGHTS in expansions -> 13
|
||||||
CatanRuleSet.SEAFARERS -> 12
|
else -> 10
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [options] switched to [ruleSet]. The target moves to the new rule set's own
|
* [options] with [expansion] switched on or off. The target moves to the new combination's own
|
||||||
* default unless the one already chosen is on its menu too.
|
* default unless the one already chosen is on its menu too. Expansions cannot be combined yet,
|
||||||
|
* so switching one on switches the other off.
|
||||||
*/
|
*/
|
||||||
internal fun catanSwitchRules(options: CatanOptions, ruleSet: CatanRuleSet): CatanOptions =
|
internal fun catanToggleExpansion(options: CatanOptions, expansion: CatanExpansion, on: Boolean): CatanOptions {
|
||||||
options.copy(
|
val expansions = if (on) setOf(expansion) else options.expansions - expansion
|
||||||
ruleSet = ruleSet,
|
return options.copy(
|
||||||
pointsToWin = options.pointsToWin.takeIf { it in catanPointsChoices(ruleSet) && it != catanDefaultPoints(options.ruleSet) }
|
expansions = expansions,
|
||||||
?: catanDefaultPoints(ruleSet),
|
pointsToWin = options.pointsToWin.takeIf {
|
||||||
|
it in catanPointsChoices(expansions) && it != catanDefaultPoints(options.expansions)
|
||||||
|
} ?: catanDefaultPoints(expansions),
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun catanRuleSetName(ruleSet: CatanRuleSet): String = when (ruleSet) {
|
|
||||||
CatanRuleSet.BASE -> "Base game"
|
|
||||||
CatanRuleSet.CITIES_AND_KNIGHTS -> "Cities & Knights"
|
|
||||||
CatanRuleSet.SEAFARERS -> "Seafarers"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun catanRuleSetBlurb(ruleSet: CatanRuleSet): String = when (ruleSet) {
|
private fun catanExpansionName(expansion: CatanExpansion): String = when (expansion) {
|
||||||
CatanRuleSet.BASE ->
|
CatanExpansion.CITIES_AND_KNIGHTS -> "Cities & Knights"
|
||||||
"Settle the island, trade, and play development cards. Longest Road and Largest Army score."
|
CatanExpansion.SEAFARERS -> "Seafarers"
|
||||||
CatanRuleSet.CITIES_AND_KNIGHTS ->
|
}
|
||||||
|
|
||||||
|
private fun catanExpansionBlurb(expansion: CatanExpansion): String = when (expansion) {
|
||||||
|
CatanExpansion.CITIES_AND_KNIGHTS ->
|
||||||
"Cities make commodities, knights hold off the barbarians, and improvements earn progress " +
|
"Cities make commodities, knights hold off the barbarians, and improvements earn progress " +
|
||||||
"cards and metropolises. No development cards; the robber sleeps until the first attack."
|
"cards and metropolises. No development cards; the robber sleeps until the first attack."
|
||||||
CatanRuleSet.SEAFARERS ->
|
CatanExpansion.SEAFARERS ->
|
||||||
"Build ships to reach new islands. Gold fields pay any resource, a pirate guards the sea, " +
|
"Build ships to reach new islands. Gold fields pay any resource, a pirate guards the sea, " +
|
||||||
"and the first settlement on each new island scores two extra points."
|
"and the first settlement on each new island scores two extra points."
|
||||||
}
|
}
|
||||||
@@ -421,14 +423,24 @@ private fun catanRuleSetBlurb(ruleSet: CatanRuleSet): String = when (ruleSet) {
|
|||||||
@Composable
|
@Composable
|
||||||
private fun CatanOptionsEditor(options: CatanOptions, onChange: (CatanOptions) -> Unit) {
|
private fun CatanOptionsEditor(options: CatanOptions, onChange: (CatanOptions) -> Unit) {
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
ChipRow(
|
CatanExpansion.entries.forEach { expansion ->
|
||||||
label = "Rules",
|
ToggleRow(
|
||||||
values = CatanRuleSet.entries,
|
title = catanExpansionName(expansion),
|
||||||
selected = options.ruleSet,
|
subtitle = catanExpansionBlurb(expansion),
|
||||||
display = ::catanRuleSetName,
|
checked = expansion in options.expansions,
|
||||||
onSelect = { onChange(catanSwitchRules(options, it)) },
|
onChange = { onChange(catanToggleExpansion(options, expansion, it)) },
|
||||||
)
|
)
|
||||||
Text(catanRuleSetBlurb(options.ruleSet), style = MaterialTheme.typography.bodySmall)
|
}
|
||||||
|
if (options.seafarers) {
|
||||||
|
ChipRow(
|
||||||
|
label = "Map",
|
||||||
|
values = SeaScenario.entries,
|
||||||
|
selected = options.scenario,
|
||||||
|
display = { it.title },
|
||||||
|
onSelect = { onChange(options.copy(scenario = it)) },
|
||||||
|
)
|
||||||
|
Text(options.scenario.blurb, style = MaterialTheme.typography.bodySmall)
|
||||||
|
}
|
||||||
ChipRow(
|
ChipRow(
|
||||||
label = "Players",
|
label = "Players",
|
||||||
values = listOf(3, 4),
|
values = listOf(3, 4),
|
||||||
@@ -438,7 +450,7 @@ private fun CatanOptionsEditor(options: CatanOptions, onChange: (CatanOptions) -
|
|||||||
)
|
)
|
||||||
ChipRow(
|
ChipRow(
|
||||||
label = "Game to",
|
label = "Game to",
|
||||||
values = catanPointsChoices(options.ruleSet),
|
values = catanPointsChoices(options.expansions),
|
||||||
selected = options.pointsToWin,
|
selected = options.pointsToWin,
|
||||||
display = { "$it points" },
|
display = { "$it points" },
|
||||||
onSelect = { onChange(options.copy(pointsToWin = it)) },
|
onSelect = { onChange(options.copy(pointsToWin = it)) },
|
||||||
|
|||||||
@@ -55,15 +55,15 @@ class CatanAiProfilesTest {
|
|||||||
(0 until 3).any { p.of(it).style == style }
|
(0 until 3).any { p.of(it).style == style }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun forEveryProfile(rules: CatanRuleSet, cap: Int) {
|
private fun forEveryProfile(rules: Set<CatanExpansion>, cap: Int) {
|
||||||
val options = CatanOptions(
|
val options = CatanOptions(
|
||||||
playerCount = 3,
|
playerCount = 3,
|
||||||
pointsToWin = when (rules) {
|
pointsToWin = when {
|
||||||
CatanRuleSet.BASE -> 10
|
CatanExpansion.CITIES_AND_KNIGHTS in rules -> 13
|
||||||
CatanRuleSet.CITIES_AND_KNIGHTS -> 13
|
CatanExpansion.SEAFARERS in rules -> 12
|
||||||
else -> 12
|
else -> 10
|
||||||
},
|
},
|
||||||
ruleSet = rules,
|
expansions = rules,
|
||||||
)
|
)
|
||||||
for (difficulty in listOf(AiDifficulty.EASY, AiDifficulty.HARD)) {
|
for (difficulty in listOf(AiDifficulty.EASY, AiDifficulty.HARD)) {
|
||||||
for (style in AiStyle.entries) {
|
for (style in AiStyle.entries) {
|
||||||
@@ -78,14 +78,14 @@ class CatanAiProfilesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `easy and hard seats of every style play the base game`() = forEveryProfile(CatanRuleSet.BASE, 1_500)
|
fun `easy and hard seats of every style play the base game`() = forEveryProfile(emptySet(), 1_500)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `easy and hard seats of every style play Cities and Knights`() =
|
fun `easy and hard seats of every style play Cities and Knights`() =
|
||||||
forEveryProfile(CatanRuleSet.CITIES_AND_KNIGHTS, 1_500)
|
forEveryProfile(setOf(CatanExpansion.CITIES_AND_KNIGHTS), 1_500)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `easy and hard seats of every style play Seafarers`() = forEveryProfile(CatanRuleSet.SEAFARERS, 1_500)
|
fun `easy and hard seats of every style play Seafarers`() = forEveryProfile(setOf(CatanExpansion.SEAFARERS), 1_500)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a mixed table of four finishes a base game`() {
|
fun `a mixed table of four finishes a base game`() {
|
||||||
@@ -95,8 +95,8 @@ class CatanAiProfilesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `the default profile plays exactly as an explicit medium table does`() {
|
fun `the default profile plays exactly as an explicit medium table does`() {
|
||||||
for (rules in listOf(CatanRuleSet.BASE, CatanRuleSet.CITIES_AND_KNIGHTS)) {
|
for (rules in listOf(emptySet(), setOf(CatanExpansion.CITIES_AND_KNIGHTS))) {
|
||||||
val options = CatanOptions(playerCount = 3, pointsToWin = 10, ruleSet = rules)
|
val options = CatanOptions(playerCount = 3, pointsToWin = 10, expansions = rules)
|
||||||
val plain = play(options, 9L, AiProfiles.DEFAULT, 600)
|
val plain = play(options, 9L, AiProfiles.DEFAULT, 600)
|
||||||
val medium = play(options, 9L, AiProfiles(AiDifficulty.MEDIUM, 1234L), 600)
|
val medium = play(options, 9L, AiProfiles(AiDifficulty.MEDIUM, 1234L), 600)
|
||||||
assertEquals("$rules", plain, medium)
|
assertEquals("$rules", plain, medium)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class CatanCkRulesTest {
|
|||||||
CatanOptions(
|
CatanOptions(
|
||||||
playerCount = players,
|
playerCount = players,
|
||||||
pointsToWin = 13,
|
pointsToWin = 13,
|
||||||
ruleSet = if (ck) CatanRuleSet.CITIES_AND_KNIGHTS else CatanRuleSet.BASE,
|
expansions = if (ck) setOf(CatanExpansion.CITIES_AND_KNIGHTS) else emptySet(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
seed = seed,
|
seed = seed,
|
||||||
@@ -138,7 +138,7 @@ class CatanCkRulesTest {
|
|||||||
val base = CatanRules.initialState(config(ck = false))
|
val base = CatanRules.initialState(config(ck = false))
|
||||||
assertNull(base.ck)
|
assertNull(base.ck)
|
||||||
assertEquals(25, base.devDeck.size)
|
assertEquals(25, base.devDeck.size)
|
||||||
assertEquals(CatanRuleSet.BASE, base.options.ruleSet)
|
assertEquals(emptySet<CatanExpansion>(), base.options.expansions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -157,7 +157,21 @@ class CatanCkRulesTest {
|
|||||||
fun `the options without a rule set still read as the base game`() {
|
fun `the options without a rule set still read as the base game`() {
|
||||||
val old = """{"playerCount":4,"pointsToWin":10}"""
|
val old = """{"playerCount":4,"pointsToWin":10}"""
|
||||||
val options = Json { ignoreUnknownKeys = true }.decodeFromString<CatanOptions>(old)
|
val options = Json { ignoreUnknownKeys = true }.decodeFromString<CatanOptions>(old)
|
||||||
assertEquals(CatanRuleSet.BASE, options.ruleSet)
|
assertEquals(emptySet<CatanExpansion>(), options.expansions)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `options saved with a rule set still read as the expansion they named`() {
|
||||||
|
val read = { text: String -> Json { ignoreUnknownKeys = true }.decodeFromString<CatanOptions>(text) }
|
||||||
|
assertEquals(
|
||||||
|
setOf(CatanExpansion.CITIES_AND_KNIGHTS),
|
||||||
|
read("""{"playerCount":3,"pointsToWin":13,"ruleSet":"CITIES_AND_KNIGHTS"}""").expansions,
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
setOf(CatanExpansion.SEAFARERS),
|
||||||
|
read("""{"playerCount":3,"pointsToWin":12,"ruleSet":"SEAFARERS"}""").expansions,
|
||||||
|
)
|
||||||
|
assertEquals(emptySet<CatanExpansion>(), read("""{"ruleSet":"BASE"}""").expansions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ class CatanCkSelfPlayTest {
|
|||||||
fun `three engines play Cities and Knights to a finish`() {
|
fun `three engines play Cities and Knights to a finish`() {
|
||||||
val reports = (1L..12L).map { seed ->
|
val reports = (1L..12L).map { seed ->
|
||||||
val (state, report) = playOut(
|
val (state, report) = playOut(
|
||||||
CatanOptions(playerCount = 3, pointsToWin = 13, ruleSet = CatanRuleSet.CITIES_AND_KNIGHTS),
|
CatanOptions(playerCount = 3, pointsToWin = 13, expansions = setOf(CatanExpansion.CITIES_AND_KNIGHTS)),
|
||||||
seed,
|
seed,
|
||||||
)
|
)
|
||||||
assertEquals("seed $seed", CatanPhase.GAME_OVER, state.phase)
|
assertEquals("seed $seed", CatanPhase.GAME_OVER, state.phase)
|
||||||
@@ -171,7 +171,7 @@ class CatanCkSelfPlayTest {
|
|||||||
fun `four engines play Cities and Knights to a finish`() {
|
fun `four engines play Cities and Knights to a finish`() {
|
||||||
val reports = (101L..108L).map { seed ->
|
val reports = (101L..108L).map { seed ->
|
||||||
val (state, report) = playOut(
|
val (state, report) = playOut(
|
||||||
CatanOptions(playerCount = 4, pointsToWin = 13, ruleSet = CatanRuleSet.CITIES_AND_KNIGHTS),
|
CatanOptions(playerCount = 4, pointsToWin = 13, expansions = setOf(CatanExpansion.CITIES_AND_KNIGHTS)),
|
||||||
seed,
|
seed,
|
||||||
)
|
)
|
||||||
assertEquals("seed $seed", CatanPhase.GAME_OVER, state.phase)
|
assertEquals("seed $seed", CatanPhase.GAME_OVER, state.phase)
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
package org.prolibertate.games.game.catan
|
||||||
|
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
import org.prolibertate.games.game.GameCatalog
|
||||||
|
import org.prolibertate.games.game.engine.PlayerKind
|
||||||
|
import org.prolibertate.games.game.engine.PlayerSlot
|
||||||
|
import org.prolibertate.games.game.engine.TableConfig
|
||||||
|
|
||||||
|
/** What every Seafarers map owes the engine, and the shape of each one. */
|
||||||
|
class CatanSeaScenariosTest {
|
||||||
|
|
||||||
|
private val json = Json { encodeDefaults = true }
|
||||||
|
|
||||||
|
private fun options(scenario: SeaScenario, players: Int = 3) = CatanOptions(
|
||||||
|
playerCount = players,
|
||||||
|
pointsToWin = 12,
|
||||||
|
expansions = setOf(CatanExpansion.SEAFARERS),
|
||||||
|
scenario = scenario,
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun config(options: CatanOptions, seed: Long) = TableConfig(
|
||||||
|
gameId = GameCatalog.CATAN,
|
||||||
|
seats = (0 until options.playerCount).map {
|
||||||
|
PlayerSlot(seat = it, name = "P$it", kind = PlayerKind.AI, team = it)
|
||||||
|
},
|
||||||
|
optionsJson = json.encodeToString(options),
|
||||||
|
seed = seed,
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun sizes(scenario: SeaScenario): List<Int> {
|
||||||
|
val topo = SeaBoards.topology(scenario)
|
||||||
|
return (0 until topo.islandCount).map { i -> topo.islandOf.count { it == i } }.sorted()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `each map has the islands it is named for`() {
|
||||||
|
assertEquals(listOf(2, 3, 3, 21), sizes(SeaScenario.NEW_SHORES))
|
||||||
|
assertEquals(listOf(1, 1, 6, 6, 6, 6), sizes(SeaScenario.FOUR_ISLANDS))
|
||||||
|
assertEquals(listOf(1, 1, 1, 2, 25), sizes(SeaScenario.THROUGH_THE_DESERT))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `every map deals numbers, harbours and a pirate at sea, with the reds apart`() {
|
||||||
|
for (scenario in SeaScenario.entries) {
|
||||||
|
repeat(5) { i ->
|
||||||
|
val s = CatanRules.initialState(config(options(scenario), 300L + i))
|
||||||
|
val topo = s.topo
|
||||||
|
val deserts = s.terrains.count { it == Terrain.DESERT }
|
||||||
|
for (h in 0 until topo.HEX_COUNT) {
|
||||||
|
val land = s.terrains[h] != Terrain.SEA
|
||||||
|
assertEquals("$scenario hex $h", topo.land[h], land)
|
||||||
|
assertEquals("$scenario hex $h", land && s.terrains[h] != Terrain.DESERT, s.numbers[h] != 0)
|
||||||
|
}
|
||||||
|
assertTrue("$scenario has no desert", deserts > 0 || scenario == SeaScenario.FOUR_ISLANDS)
|
||||||
|
assertEquals(Terrain.SEA, s.terrains[s.sea!!.pirate])
|
||||||
|
assertEquals("$scenario harbours", 9, s.ports.size)
|
||||||
|
val reds = (0 until topo.HEX_COUNT).filter { s.numbers[it] == 6 || s.numbers[it] == 8 }
|
||||||
|
for (a in reds) for (b in reds) if (a < b) assertFalse("$scenario reds touch", topo.hexesAdjacent(a, b))
|
||||||
|
assertEquals(scenario, s.sea!!.scenario)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `four islands start on any main island and the islets earn the bonus`() {
|
||||||
|
val s = CatanRules.initialState(config(options(SeaScenario.FOUR_ISLANDS), 5L))
|
||||||
|
val sea = s.sea!!
|
||||||
|
assertEquals(4, sea.starts.size)
|
||||||
|
val moves = CatanRules.legalMoves(s, s.firstSeat).filterIsInstance<SetupPlace>()
|
||||||
|
assertEquals(sea.starts.toSet(), moves.map { s.topo.vertexIsland[it.vertex] }.toSet())
|
||||||
|
for (island in 0 until s.topo.islandCount) assertEquals(island in sea.starts, sea.isStart(island))
|
||||||
|
// A settlement on a starting island scores no first-landing bonus.
|
||||||
|
val onMain = (0 until s.topo.VERTEX_COUNT).first { s.topo.vertexIsland[it] == sea.starts.first() }
|
||||||
|
assertEquals(s, SeaRules.claimIsland(s, 0, onMain))
|
||||||
|
val islet = (0 until s.topo.VERTEX_COUNT).first { s.topo.vertexIsland[it] >= 0 && s.topo.vertexIsland[it] !in sea.starts }
|
||||||
|
assertEquals(0, SeaRules.bonusPoints(s, 0))
|
||||||
|
assertEquals(0, SeaRules.bonusPoints(SeaRules.claimIsland(s, 0, onMain), 0))
|
||||||
|
assertEquals(SeaRules.ISLAND_BONUS, SeaRules.bonusPoints(SeaRules.claimIsland(s, 0, islet), 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `through the desert starts everyone on the one big island`() {
|
||||||
|
val s = CatanRules.initialState(config(options(SeaScenario.THROUGH_THE_DESERT), 5L))
|
||||||
|
assertEquals(listOf(s.sea!!.home), s.sea!!.starts)
|
||||||
|
assertEquals(25, s.topo.islandOf.count { it == s.sea!!.home })
|
||||||
|
assertTrue(s.terrains.count { it == Terrain.DESERT } >= 5)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a save from before there were several starts still starts on the home island`() {
|
||||||
|
val s = CatanRules.initialState(config(options(SeaScenario.NEW_SHORES), 5L))
|
||||||
|
val old = s.copy(sea = s.sea!!.copy(starts = emptyList()))
|
||||||
|
assertTrue(old.sea!!.isStart(old.sea!!.home))
|
||||||
|
val moves = CatanRules.legalMoves(old, old.firstSeat).filterIsInstance<SetupPlace>()
|
||||||
|
assertTrue(moves.all { old.topo.vertexIsland[it.vertex] == old.sea!!.home })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `engines finish a game on every map at three and four players`() {
|
||||||
|
for (scenario in SeaScenario.entries) {
|
||||||
|
for ((players, seed) in listOf(3 to 11L, 4 to 12L, 3 to 13L)) {
|
||||||
|
val opts = options(scenario, players)
|
||||||
|
val ai = CatanAi()
|
||||||
|
var state = CatanRules.initialState(config(opts, seed))
|
||||||
|
var moves = 0
|
||||||
|
while (!CatanRules.isFinished(state)) {
|
||||||
|
assertTrue("$scenario seed $seed ran past the cap; log: ${state.log.takeLast(6)}", moves++ < 20_000)
|
||||||
|
val seat = CatanRules.currentSeat(state) ?: error("$scenario seed $seed: nobody to move in ${state.phase}")
|
||||||
|
val legal = CatanRules.legalMoves(state, seat)
|
||||||
|
assertTrue("$scenario seed $seed: no legal move for $seat in ${state.phase}", legal.isNotEmpty())
|
||||||
|
val move = ai.chooseMove(state, seat, legal)
|
||||||
|
assertTrue("$scenario seed $seed: illegal $move", CatanRules.isLegalMove(state, seat, move))
|
||||||
|
state = CatanRules.applyMove(state, seat, move)
|
||||||
|
}
|
||||||
|
assertEquals("$scenario seed $seed", CatanPhase.GAME_OVER, state.phase)
|
||||||
|
assertEquals(state, CatanRules.decodeState(CatanRules.encodeState(state)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@ class CatanSeafarersTest {
|
|||||||
private val json = Json { encodeDefaults = true }
|
private val json = Json { encodeDefaults = true }
|
||||||
|
|
||||||
private fun options(players: Int = 3) =
|
private fun options(players: Int = 3) =
|
||||||
CatanOptions(playerCount = players, pointsToWin = 12, ruleSet = CatanRuleSet.SEAFARERS)
|
CatanOptions(playerCount = players, pointsToWin = 12, expansions = setOf(CatanExpansion.SEAFARERS))
|
||||||
|
|
||||||
private fun config(options: CatanOptions, seed: Long) = TableConfig(
|
private fun config(options: CatanOptions, seed: Long) = TableConfig(
|
||||||
gameId = GameCatalog.CATAN,
|
gameId = GameCatalog.CATAN,
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ class SaveRoundTripAllGamesTest {
|
|||||||
GameCatalog.CATAN,
|
GameCatalog.CATAN,
|
||||||
CatanRules,
|
CatanRules,
|
||||||
CatanAi(),
|
CatanAi(),
|
||||||
opts(CatanOptions(3, 13, org.prolibertate.games.game.catan.CatanRuleSet.CITIES_AND_KNIGHTS)),
|
opts(CatanOptions(3, 13, setOf(org.prolibertate.games.game.catan.CatanExpansion.CITIES_AND_KNIGHTS))),
|
||||||
steps = 600,
|
steps = 600,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import org.prolibertate.games.game.catan.CatanBoard
|
|||||||
import org.prolibertate.games.game.catan.CatanMove
|
import org.prolibertate.games.game.catan.CatanMove
|
||||||
import org.prolibertate.games.game.catan.CatanOptions
|
import org.prolibertate.games.game.catan.CatanOptions
|
||||||
import org.prolibertate.games.game.catan.CatanPhase
|
import org.prolibertate.games.game.catan.CatanPhase
|
||||||
import org.prolibertate.games.game.catan.CatanRuleSet
|
import org.prolibertate.games.game.catan.CatanExpansion
|
||||||
import org.prolibertate.games.game.catan.CatanRules
|
import org.prolibertate.games.game.catan.CatanRules
|
||||||
import org.prolibertate.games.game.catan.CatanState
|
import org.prolibertate.games.game.catan.CatanState
|
||||||
import org.prolibertate.games.game.catan.ChaseRobber
|
import org.prolibertate.games.game.catan.ChaseRobber
|
||||||
@@ -69,7 +69,7 @@ class CatanCkInteractionTest {
|
|||||||
gameId = GameCatalog.CATAN,
|
gameId = GameCatalog.CATAN,
|
||||||
seats = (0 until players).map { PlayerSlot(seat = it, name = "P$it", kind = PlayerKind.AI, team = it) },
|
seats = (0 until players).map { PlayerSlot(seat = it, name = "P$it", kind = PlayerKind.AI, team = it) },
|
||||||
optionsJson = json.encodeToString(
|
optionsJson = json.encodeToString(
|
||||||
CatanOptions(players, pointsToWin = 13, ruleSet = CatanRuleSet.CITIES_AND_KNIGHTS),
|
CatanOptions(players, pointsToWin = 13, expansions = setOf(CatanExpansion.CITIES_AND_KNIGHTS)),
|
||||||
),
|
),
|
||||||
seed = seed,
|
seed = seed,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.junit.Test
|
|||||||
import org.prolibertate.games.game.GameCatalog
|
import org.prolibertate.games.game.GameCatalog
|
||||||
import org.prolibertate.games.game.catan.CatanAi
|
import org.prolibertate.games.game.catan.CatanAi
|
||||||
import org.prolibertate.games.game.catan.CatanOptions
|
import org.prolibertate.games.game.catan.CatanOptions
|
||||||
import org.prolibertate.games.game.catan.CatanRuleSet
|
import org.prolibertate.games.game.catan.CatanExpansion
|
||||||
import org.prolibertate.games.game.catan.CatanRules
|
import org.prolibertate.games.game.catan.CatanRules
|
||||||
import org.prolibertate.games.game.catan.ProgressType
|
import org.prolibertate.games.game.catan.ProgressType
|
||||||
import org.prolibertate.games.game.engine.PlayerKind
|
import org.prolibertate.games.game.engine.PlayerKind
|
||||||
@@ -16,7 +16,7 @@ import org.prolibertate.games.game.engine.PlayerSlot
|
|||||||
import org.prolibertate.games.game.engine.TableConfig
|
import org.prolibertate.games.game.engine.TableConfig
|
||||||
import org.prolibertate.games.ui.catanDefaultPoints
|
import org.prolibertate.games.ui.catanDefaultPoints
|
||||||
import org.prolibertate.games.ui.catanPointsChoices
|
import org.prolibertate.games.ui.catanPointsChoices
|
||||||
import org.prolibertate.games.ui.catanSwitchRules
|
import org.prolibertate.games.ui.catanToggleExpansion
|
||||||
|
|
||||||
class CatanCkTextTest {
|
class CatanCkTextTest {
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ class CatanCkTextTest {
|
|||||||
gameId = GameCatalog.CATAN,
|
gameId = GameCatalog.CATAN,
|
||||||
seats = (0 until 3).map { PlayerSlot(seat = it, name = "P$it", kind = PlayerKind.AI, team = it) },
|
seats = (0 until 3).map { PlayerSlot(seat = it, name = "P$it", kind = PlayerKind.AI, team = it) },
|
||||||
optionsJson = json.encodeToString(
|
optionsJson = json.encodeToString(
|
||||||
CatanOptions(3, 13, CatanRuleSet.CITIES_AND_KNIGHTS),
|
CatanOptions(3, 13, setOf(CatanExpansion.CITIES_AND_KNIGHTS)),
|
||||||
),
|
),
|
||||||
seed = 31L,
|
seed = 31L,
|
||||||
)
|
)
|
||||||
@@ -56,20 +56,24 @@ class CatanCkTextTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `the setup screen offers each rule set its own targets and switches sensibly`() {
|
fun `the setup screen offers each rule set its own targets and switches sensibly`() {
|
||||||
assertEquals(listOf(5, 8, 10, 12), catanPointsChoices(CatanRuleSet.BASE))
|
assertEquals(listOf(5, 8, 10, 12), catanPointsChoices(emptySet()))
|
||||||
assertEquals(listOf(8, 10, 13, 15), catanPointsChoices(CatanRuleSet.CITIES_AND_KNIGHTS))
|
assertEquals(listOf(8, 10, 13, 15), catanPointsChoices(setOf(CatanExpansion.CITIES_AND_KNIGHTS)))
|
||||||
assertEquals(10, catanDefaultPoints(CatanRuleSet.BASE))
|
assertEquals(10, catanDefaultPoints(emptySet()))
|
||||||
assertEquals(13, catanDefaultPoints(CatanRuleSet.CITIES_AND_KNIGHTS))
|
assertEquals(13, catanDefaultPoints(setOf(CatanExpansion.CITIES_AND_KNIGHTS)))
|
||||||
|
|
||||||
val base = CatanOptions()
|
val base = CatanOptions()
|
||||||
val ck = catanSwitchRules(base, CatanRuleSet.CITIES_AND_KNIGHTS)
|
val ck = catanToggleExpansion(base, CatanExpansion.CITIES_AND_KNIGHTS, true)
|
||||||
assertEquals(CatanRuleSet.CITIES_AND_KNIGHTS, ck.ruleSet)
|
assertEquals(setOf(CatanExpansion.CITIES_AND_KNIGHTS), ck.expansions)
|
||||||
assertEquals("the published target for the new rules", 13, ck.pointsToWin)
|
assertEquals("the published target for the new rules", 13, ck.pointsToWin)
|
||||||
assertEquals(10, catanSwitchRules(ck, CatanRuleSet.BASE).pointsToWin)
|
assertEquals(10, catanToggleExpansion(ck, CatanExpansion.CITIES_AND_KNIGHTS, false).pointsToWin)
|
||||||
|
|
||||||
// A short game picked on purpose is kept when both menus have it.
|
// A short game picked on purpose is kept when both menus have it.
|
||||||
val short = catanSwitchRules(base.copy(pointsToWin = 8), CatanRuleSet.CITIES_AND_KNIGHTS)
|
val short = catanToggleExpansion(base.copy(pointsToWin = 8), CatanExpansion.CITIES_AND_KNIGHTS, true)
|
||||||
assertEquals(8, short.pointsToWin)
|
assertEquals(8, short.pointsToWin)
|
||||||
assertEquals(3, ck.playerCount)
|
assertEquals(3, ck.playerCount)
|
||||||
|
|
||||||
|
// Expansions cannot be combined yet: switching one on switches the other off.
|
||||||
|
val sea = catanToggleExpansion(ck, CatanExpansion.SEAFARERS, true)
|
||||||
|
assertEquals(setOf(CatanExpansion.SEAFARERS), sea.expansions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -12,7 +12,7 @@ import org.prolibertate.games.game.catan.CatanAi
|
|||||||
import org.prolibertate.games.game.catan.CatanBuilding
|
import org.prolibertate.games.game.catan.CatanBuilding
|
||||||
import org.prolibertate.games.game.catan.CatanOptions
|
import org.prolibertate.games.game.catan.CatanOptions
|
||||||
import org.prolibertate.games.game.catan.CatanPhase
|
import org.prolibertate.games.game.catan.CatanPhase
|
||||||
import org.prolibertate.games.game.catan.CatanRuleSet
|
import org.prolibertate.games.game.catan.CatanExpansion
|
||||||
import org.prolibertate.games.game.catan.CatanRules
|
import org.prolibertate.games.game.catan.CatanRules
|
||||||
import org.prolibertate.games.game.catan.CatanState
|
import org.prolibertate.games.game.catan.CatanState
|
||||||
import org.prolibertate.games.game.catan.MovePirate
|
import org.prolibertate.games.game.catan.MovePirate
|
||||||
@@ -29,7 +29,7 @@ import org.prolibertate.games.game.engine.TableConfig
|
|||||||
class CatanSeafarersInteractionTest {
|
class CatanSeafarersInteractionTest {
|
||||||
|
|
||||||
private fun fresh(): CatanState {
|
private fun fresh(): CatanState {
|
||||||
val options = CatanOptions(playerCount = 3, pointsToWin = 12, ruleSet = CatanRuleSet.SEAFARERS)
|
val options = CatanOptions(playerCount = 3, pointsToWin = 12, expansions = setOf(CatanExpansion.SEAFARERS))
|
||||||
return CatanRules.initialState(
|
return CatanRules.initialState(
|
||||||
TableConfig(
|
TableConfig(
|
||||||
gameId = GameCatalog.CATAN,
|
gameId = GameCatalog.CATAN,
|
||||||
|
|||||||
@@ -1,20 +1,30 @@
|
|||||||
# Katan: Seafarers
|
# Katan: Seafarers
|
||||||
|
|
||||||
The Seafarers rule set is chosen at setup next to *Base game* and *Cities & Knights*. It is the base
|
Seafarers is an expansion switched on at setup (`CatanOptions.expansions`; the old single `ruleSet` in saves is still read) and its map is chosen beside it (`CatanOptions.scenario`). It is the base
|
||||||
game ([RULES-catan.md](RULES-catan.md)) with a sea, ships, a pirate, gold fields and islands to
|
game ([RULES-catan.md](RULES-catan.md)) with a sea, ships, a pirate, gold fields and islands to
|
||||||
settle. Code: `game/catan/CatanSeaRules.kt` (the additions), `CatanSeaBoard.kt` (the map),
|
settle. Code: `game/catan/CatanSeaRules.kt` (the additions), `CatanSeaBoard.kt` (the map),
|
||||||
`CatanBoard.kt` (`Topology`, the geometry shared by every map), state behind `CatanState.sea`
|
`CatanBoard.kt` (`Topology`, the geometry shared by every map), state behind `CatanState.sea`
|
||||||
(null in the other rule sets). It cannot be combined with Cities & Knights.
|
(null in the other rule sets). It cannot yet be combined with Cities & Knights; the setup screen switches one off when the other is turned on.
|
||||||
|
|
||||||
Where the published rules leave room, or where this game differs, it says so below.
|
Where the published rules leave room, or where this game differs, it says so below.
|
||||||
|
|
||||||
## The map
|
## The maps
|
||||||
|
|
||||||
One map, *Heading for New Shores*: a large **home island** (21 hexes, one desert) and three small
|
Each map is a fixed arrangement of land and sea; the **resources on the plain hexes, the number tokens
|
||||||
islands (3, 3 and 2 hexes) across the water, inside a ring of sea. Which land hexes are gold, which
|
|
||||||
are the desert and where the sea lies is fixed; the **resources on the other hexes, the number tokens
|
|
||||||
and the nine harbours are shuffled** for each game. The red numbers (6, 8) are never on neighbouring
|
and the nine harbours are shuffled** for each game. The red numbers (6, 8) are never on neighbouring
|
||||||
hexes. Players take three or four seats; the default target is **12 points** (menu: 8, 10, 12, 14).
|
hexes. Players take three or four seats; the default target is **12 points** (menu: 8, 10, 12, 14).
|
||||||
|
Pick the map at setup; each scenario names where the starting settlements may go (`SeaStart`).
|
||||||
|
|
||||||
|
* **Heading for New Shores** (default). A large home island (21 hexes, one desert) and three small islands (3, 3
|
||||||
|
and 2 hexes) across the water, with gold fields on two of the small ones. Start on the home island.
|
||||||
|
* **Four Islands.** Four equal islands (six hexes each) and two one-hex gold islets between them. Each player
|
||||||
|
may start on **any** of the four main islands, so a table can spread out or crowd one; the islets are the
|
||||||
|
prize for the first ship to arrive.
|
||||||
|
* **Through the Desert.** One 25-hex island cut across by a broad desert (seven hexes that pay nothing and
|
||||||
|
hold the robber), with three islets and gold to sail to. Everyone starts on the island. The desert is
|
||||||
|
land, so a road can cross it, but nothing beside it pays, which is what makes the far side a race.
|
||||||
|
|
||||||
|
A *new island* for the bonus is any island that is not a starting island for that map.
|
||||||
|
|
||||||
The geometry is the same lattice as the base island, generalised (`Topology`): a hex is land or sea,
|
The geometry is the same lattice as the base island, generalised (`Topology`): a hex is land or sea,
|
||||||
a crossing can hold a town if any hex touching it is land, an edge can hold a road if any hex touching
|
a crossing can hold a town if any hex touching it is land, an edge can hold a road if any hex touching
|
||||||
@@ -60,8 +70,8 @@ Everything else (development cards, trading, harbours, Largest Army, the discard
|
|||||||
|
|
||||||
The physical expansion has more scenarios and the Catan Universe app adds more still. These are **out of scope here**:
|
The physical expansion has more scenarios and the Catan Universe app adds more still. These are **out of scope here**:
|
||||||
fog islands, treasure islands, the oasis, the great canal, the Explorers & Pirates and Cities & Knights combinations,
|
fog islands, treasure islands, the oasis, the great canal, the Explorers & Pirates and Cities & Knights combinations,
|
||||||
the scenarios after the first, and trade ships. The `SeaScenario` enum and `SeaBoards` are built so a second map
|
the scenarios that need new rules (fog, cloth, wonders, the forgotten tribe, pirate islands) and trade ships.
|
||||||
is a new text map and a new enum entry.
|
A map-only scenario is a new text map and a new `SeaScenario` entry.
|
||||||
|
|
||||||
## How the AI plays it
|
## How the AI plays it
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user