Compare commits

...
18 Commits
Author SHA1 Message Date
devadmin 8b67df7a58 Merge pull request 'Release: Katan scenarios, expansions and portrait zoom' (#42) from dev into main
Build and Release APK / Build APK and publish release (push) Successful in 6m13s
Build and Release APK / Deploy to Cloudflare Pages (push) Successful in 30s
2026-11-12 21:50:29 -06:00
devadmin 3deb764905 Merge pull request 'Katan: zoom the board in portrait' (#41) from feature/catan-portrait-zoom into dev
CI / Build and check (push) Successful in 11m20s
CI / Deploy to Cloudflare Pages (push) Successful in 32s
CI / Build and check (pull_request) Successful in 11m32s
CI / Deploy to Cloudflare Pages (pull_request) Skipped
2026-11-12 19:14:59 -06:00
Claude da772bd326 Katan: pinch-zoom and pan in portrait; max zoom 6x
CI / Build and check (pull_request) Successful in 11m1s
CI / Deploy to Cloudflare Pages (pull_request) Skipped
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TWwLCrXa9aFVg8dZsCdLBZ
2026-11-13 01:03:36 +00:00
devadmin dc73a71993 Merge pull request 'Katan: base-island scenarios (phase 6b)' (#40) from feature/catan-base-scenarios into dev
CI / Build and check (push) Successful in 11m32s
CI / Deploy to Cloudflare Pages (push) Successful in 33s
2026-11-12 12:25:57 -06:00
Claude 42334c3bf8 Katan: base-island scenarios (First Island, The Harbormaster)
CI / Build and check (pull_request) Successful in 11m29s
CI / Deploy to Cloudflare Pages (pull_request) Skipped
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TWwLCrXa9aFVg8dZsCdLBZ
2026-11-12 18:14:00 +00:00
devadmin 421cbd4c70 Merge pull request 'Seafarers: Catan Universe extras (phase 6a)' (#39) from feature/catan-universe-extras into dev
CI / Build and check (push) Successful in 11m2s
CI / Deploy to Cloudflare Pages (push) Successful in 33s
2026-11-12 11:23:46 -06:00
Claude cd220396f9 Seafarers: Treasure Islands, Oases and the Great Canal (inferred rules)
CI / Build and check (pull_request) Successful in 11m3s
CI / Deploy to Cloudflare Pages (pull_request) Skipped
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TWwLCrXa9aFVg8dZsCdLBZ
2026-11-12 17:11:47 +00:00
devadmin af279d3592 Merge pull request 'Seafarers: Pirate Islands and Wonders of Catan (phase 5b)' (#38) from feature/catan-pirates-wonders into dev
CI / Build and check (push) Successful in 11m30s
CI / Deploy to Cloudflare Pages (push) Successful in 32s
2026-11-11 23:33:45 -06:00
Claude 3315790688 Merge origin/dev
CI / Build and check (pull_request) Successful in 11m33s
CI / Deploy to Cloudflare Pages (pull_request) Skipped
2026-11-12 05:21:47 +00:00
Claude 20b6cb4b5f Seafarers: Pirate Islands and Wonders of Catan
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TWwLCrXa9aFVg8dZsCdLBZ
2026-11-12 05:21:46 +00:00
devadmin b8d3d5909c Merge pull request 'Release: non-debuggable production build' (#30) from dev into main
Build and Release APK / Build APK and publish release (push) Successful in 6m6s
Build and Release APK / Deploy to Cloudflare Pages (push) Successful in 27s
2026-11-07 14:40:40 -06:00
devadmin 5a2c8a0d33 Merge pull request 'Release: dev to main' (#28) from dev into main
Build and Release APK / Build APK and publish release (push) Successful in 4m19s
Build and Release APK / Deploy to Cloudflare Pages (push) Successful in 30s
2026-11-07 13:01:33 -06:00
devadmin 5360545398 Merge pull request 'Release: Katan Seafarers' (#25) from dev into main
Build and Release APK / Build APK and publish release (push) Successful in 4m24s
Build and Release APK / Deploy to Cloudflare Pages (push) Successful in 31s
2026-10-28 21:46:17 -06:00
devadmin 6278f472db Merge pull request 'Release: Yahtzee improvements' (#24) from dev into main
Build and Release APK / Build APK and publish release (push) Successful in 4m25s
Build and Release APK / Deploy to Cloudflare Pages (push) Successful in 32s
2026-10-28 20:43:39 -06:00
devadmin 8c89174c21 Merge pull request 'Release Katan and Meowdoku to production' (#20) from dev into main
Build and Release APK / Build APK and publish release (push) Successful in 4m17s
Build and Release APK / Deploy to Cloudflare Pages (push) Successful in 33s
2026-10-26 12:41:15 -06:00
devadmin ee8a4f27d3 Merge pull request 'Release: Meowdoku refinements and Scorekeeper name memory' (#18) from dev into main
Build and Release APK / Build APK and publish release (push) Successful in 4m27s
Build and Release APK / Deploy to Cloudflare Pages (push) Successful in 39s
2026-10-26 10:55:04 -06:00
devadmin 518f80b998 Merge pull request 'Release: dev to main (Cities & Knights)' (#9) from dev into main
Build and Release APK / Build APK and publish release (push) Successful in 4m2s
Build and Release APK / Deploy to Cloudflare Pages (push) Successful in 32s
2026-10-17 12:43:30 -06:00
devadmin 5fdb70cae0 Merge pull request 'Release: dev to main' (#7) from dev into main
Build and Release APK / Build APK and publish release (push) Successful in 4m1s
Build and Release APK / Deploy to Cloudflare Pages (push) Successful in 33s
2026-10-15 18:01:36 -06:00
22 changed files with 975 additions and 26 deletions
@@ -277,6 +277,11 @@ class CatanAi(private val profiles: AiProfiles = AiProfiles.DEFAULT) : GameAi<Ca
pickBest(settlements, profile) { spotValue(state, it.vertex) }?.let { return it }
}
// A raid on a fortress, or the next stage of a wonder, beats a card.
legal.filterIsInstance<RaidFortress>().firstOrNull()?.let { return it }
legal.filterIsInstance<DigCanal>().firstOrNull()?.let { return it }
legal.filterIsInstance<BuildWonder>().firstOrNull()?.let { return it }
// Seafarers: a ship toward an island nobody has landed on is worth more than a card.
legal.filterIsInstance<BuildShip>()
.filter { shipValue(state, seat, it.edge) > 0.5 }
@@ -594,6 +599,10 @@ class CatanAi(private val profiles: AiProfiles = AiProfiles.DEFAULT) : GameAi<Ca
/** What a seat would think of building on [vertex]: production and ports. */
/** What a spot beside a cloth village or an unclaimed tribe chip is worth beyond its cards. */
private fun scenarioLure(state: CatanState, vertex: Int): Double {
// The Harbormaster: a town on a harbour is a point toward a title worth two.
if (CatanRules.harbormasterGame(state) &&
state.topo.VERTEX_EDGES[vertex].any { e -> state.ports.any { it.edge == e } }
) return HARBOR_LURE
val sea = state.sea ?: return 0.0
var lure = 0.0
for (h in state.topo.VERTEX_HEXES[vertex]) {
@@ -601,6 +610,8 @@ class CatanAi(private val profiles: AiProfiles = AiProfiles.DEFAULT) : GameAi<Ca
if (state.terrains[h] == Terrain.VILLAGE && sea.villageCloth.getOrElse(h) { 0 } > 0) {
lure += CatanBoard.numberOdds(state.numbers[h]) / 36.0 * CLOTH_WORTH
}
// An unfinished canal tile is a place to dig: points now, grain land later.
if (sea.canalNumbers.getOrElse(h) { 0 } != 0 && state.terrains[h] == Terrain.DESERT) lure += CANAL_LURE
if (sea.chips.getOrNull(h).let { it != null && it != TribeChip.NONE }) lure += CHIP_LURE
}
return lure
@@ -661,6 +672,11 @@ class CatanAi(private val profiles: AiProfiles = AiProfiles.DEFAULT) : GameAi<Ca
if (!seen.add(v)) continue
// Fog is worth a look: a card on arrival, and land to settle that nobody has seen.
if (topo.VERTEX_HEXES[v].any { state.terrains[it] == Terrain.FOG }) best = maxOf(best, FOG_LURE * Math.pow(0.85, depth.toDouble()))
// A fortress is worth a raid once a ship lies beside it.
if (sea.fortress.isNotEmpty() && topo.VERTEX_EDGES[v].any { e ->
topo.edgeSea[e] && topo.EDGE_HEXES[e].any { sea.fortress.getOrElse(it) { 0 } > 0 }
}
) best = maxOf(best, FORT_LURE * Math.pow(0.85, depth.toDouble()))
if (CatanRules.vertexOpenForSettlement(state, v)) {
val island = topo.vertexIsland[v]
val fresh = island >= 0 && !sea.isStart(island) && sea.islandBonus[island] == NO_PLAYER
@@ -693,7 +709,10 @@ class CatanAi(private val profiles: AiProfiles = AiProfiles.DEFAULT) : GameAi<Ca
/** What a ship end beside undiscovered land is worth, on the scale of [spotValue]. */
const val FOG_LURE = 0.6
const val FORT_LURE = 1.2
const val CLOTH_WORTH = 2.5
const val CHIP_LURE = 0.5
const val CANAL_LURE = 0.6
const val HARBOR_LURE = 0.5
}
}
@@ -429,6 +429,9 @@ object CatanBoard {
* tokens go to four of the six board-corner hexes, which are pairwise
* non-adjacent, and at most one corner can be desert.
*/
/** The seed of the First Island scenario's fixed layout. */
const val FIRST_ISLAND_SEED = 1L
fun generate(seed: Long): Generated {
val random = Random(seed)
val terrains = TERRAIN_TILES.shuffled(random)
@@ -255,6 +255,7 @@ object CatanCk {
points[seat] += ck.defenderVp[seat] + ck.progressVp[seat]
}
ck.merchant?.let { points[it.seat] += 1 }
state.harbormaster?.let { points[it] += CatanRules.HARBORMASTER_POINTS }
if (state.isSea) for (seat in points.indices) points[seat] += SeaRules.bonusPoints(state, seat)
return points.toList()
}
@@ -351,6 +352,7 @@ object CatanCk {
if (state.isSea) {
if (affordable(state, seat, SeaRules.SHIP_COST)) moves += SeaRules.buildShipMoves(state, seat)
moves += SeaRules.moveShipMoves(state, seat)
moves += SeaRules.scenarioMoves(state, seat)
}
if (affordable(state, seat, CatanRules.SETTLEMENT_COST)) {
moves += CatanRules.settlementVertices(state, seat).map { BuildSettlement(it) }
@@ -214,6 +214,10 @@ internal class CatanCkAi(
settlements.maxByOrNull { ai.spotValue(state, it.vertex) }?.let { return it }
}
legal.filterIsInstance<RaidFortress>().firstOrNull()?.let { return it }
legal.filterIsInstance<DigCanal>().firstOrNull()?.let { return it }
legal.filterIsInstance<BuildWonder>().firstOrNull()?.let { return it }
// Seafarers: a ship toward land nobody has settled is worth more than a card.
legal.filterIsInstance<BuildShip>()
.filter { ai.shipValue(state, seat, it.edge) > 0.5 }
@@ -63,6 +63,27 @@ enum class Terrain(val produces: Resource?) {
/** Seafarers, Cloth for Catan: a village. It pays cloth, not cards, to the settlements around it when its number rolls. */
VILLAGE(null),
/**
* Seafarers, Pirate Islands: a pirate fortress. It stands until ships raid it (`SeaState.fortress`), and
* nobody settles its island meanwhile. Once taken it becomes desert.
*/
FORTRESS(null),
}
/** Base-island scenarios: the board and goals of a game without Seafarers. Seafarers games choose a [SeaScenario] instead. */
@Serializable
enum class BaseScenario(val title: String, val blurb: String) {
RANDOM_MAP("Random map", "The usual island, its tiles and numbers shuffled for every game."),
FIRST_ISLAND(
"First Island",
"The same fixed island every game, so the set-up is not a surprise: good for a first game or a rematch.",
),
HARBORMASTER(
"The Harbormaster",
"Harbours matter. A settlement on a harbour counts a point and a city two; the first to three has the " +
"Harbormaster title, worth 2 victory points, and whoever gets more takes it.",
),
}
/** Axial coordinate of one hex on the board. See [CatanBoard]. */
@@ -191,6 +212,7 @@ data class CatanOptions(
val pointsToWin: Int = 10,
val expansions: Set<CatanExpansion> = emptySet(),
val scenario: SeaScenario = SeaScenario.NEW_SHORES,
val baseScenario: BaseScenario = BaseScenario.RANDOM_MAP,
) {
init {
require(playerCount in 3..4) { "The island seats three or four players" }
@@ -208,6 +230,7 @@ private class CatanOptionsWire(
val pointsToWin: Int = 10,
val expansions: Set<CatanExpansion> = emptySet(),
val scenario: SeaScenario = SeaScenario.NEW_SHORES,
val baseScenario: BaseScenario = BaseScenario.RANDOM_MAP,
)
/** Reads the legacy single `ruleSet` field as an expansion set. */
@@ -216,7 +239,7 @@ object CatanOptionsSerializer : KSerializer<CatanOptions> {
override fun serialize(encoder: Encoder, value: CatanOptions) = encoder.encodeSerializableValue(
CatanOptionsWire.serializer(),
CatanOptionsWire(value.playerCount, value.pointsToWin, value.expansions, value.scenario),
CatanOptionsWire(value.playerCount, value.pointsToWin, value.expansions, value.scenario, value.baseScenario),
)
override fun deserialize(decoder: Decoder): CatanOptions {
@@ -228,7 +251,7 @@ object CatanOptionsSerializer : KSerializer<CatanOptions> {
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)
return CatanOptions(wire.playerCount, wire.pointsToWin, wire.expansions, wire.scenario, wire.baseScenario)
}
}
@@ -300,6 +323,8 @@ data class CatanState(
val log: List<String>,
/** Everything Cities & Knights adds; null in the base game. */
val ck: CkState? = null,
/** The Harbormaster scenario: the seat holding the title, or null. */
val harbormaster: Int? = null,
/** Everything Seafarers adds (ships, the pirate, islands); null in the other rule sets. */
val sea: SeaState? = null,
) {
@@ -495,8 +520,40 @@ data class SeaState(
val harbourSeats: List<Int> = emptyList(),
/** Victory points each seat holds from tribe chips; empty until one is taken. */
val chipPoints: List<Int> = emptyList(),
/** Strength still left in each hex's pirate fortress, by hex (Pirate Islands); empty when the map has none. */
val fortress: List<Int> = emptyList(),
/** Victory points each seat holds for taking fortresses; empty until one falls. */
val raidPoints: List<Int> = emptyList(),
/** Wonder stages each seat has built (Wonders of Catan), by seat; empty when the scenario has none. */
val wonders: List<Int> = emptyList(),
/** The chest under each hex of fog, by hex (Treasure Islands, Oases); found when the hex is. Hidden from other views. */
val treasures: List<Treasure> = emptyList(),
/** Units dug so far into each canal tile, by hex (Great Canal); empty when the map has none. */
val canalUnits: List<Int> = emptyList(),
/** The number token waiting under each canal tile, by hex; it shows when the tile is finished. */
val canalNumbers: List<Int> = emptyList(),
/** Canal units each seat has dug; every two are a victory point. */
val canalDug: List<Int> = emptyList(),
)
/** What a treasure chest holds (Treasure Islands). */
@Serializable
enum class Treasure {
NONE,
/** One brick, one wool and one grain. */
BRICK_WOOL_GRAIN,
/** One resource of the finder's choice. */
CHOICE,
/** A development card (a resource of choice in Cities & Knights, which has none). */
DEV_CARD,
/** Two roads' worth of cards: two lumber and two brick. */
ROADS,
}
/** What the first settler beside a tribe hex takes (Forgotten Tribe). */
@Serializable
enum class TribeChip {
@@ -541,3 +598,18 @@ data class MovePirate(val hex: HexCoord, val victim: Int? = null) : CatanMove
@Serializable
@SerialName("gold")
data class PickGold(val cards: List<Resource>) : CatanMove
/** Raid the pirate fortress on [hex] from a ship beside it: 1 ore, 1 wool and 1 grain take one point of its strength. */
@Serializable
@SerialName("raid")
data class RaidFortress(val hex: HexCoord) : CatanMove
/** Build the next stage of your wonder, which needs a city of yours; the stage's cost is in `SeaRules.WONDER_STAGES`. */
@Serializable
@SerialName("wonder")
data object BuildWonder : CatanMove
/** Dig one unit of the canal tile on [hex]: 1 brick and 1 ore, from a seat with a settlement or city beside it. */
@Serializable
@SerialName("dig")
data class DigCanal(val hex: HexCoord) : CatanMove
@@ -59,7 +59,9 @@ object CatanRules : GameRules<CatanState, CatanMove> {
val seaBoard = if (sea) SeaBoards.generate(scenario, config.seed) else null
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) }
?: CatanBoard.generate(config.seed)
?: CatanBoard.generate(
if (options.baseScenario == BaseScenario.FIRST_ISLAND) CatanBoard.FIRST_ISLAND_SEED else config.seed,
)
// A different random stream than the island, so the same seed still
// produces both a fixed island and a fixed deck.
val ck = options.citiesAndKnights
@@ -124,6 +126,12 @@ object CatanRules : GameRules<CatanState, CatanMove> {
cloth = if (it.villageCloth.isEmpty()) emptyList() else List(options.playerCount) { 0 },
villageCloth = it.villageCloth,
chips = it.chips,
fortress = it.fortress,
treasures = it.treasures,
canalUnits = if (it.canalNumbers.isEmpty()) emptyList() else List(topo.HEX_COUNT) { 0 },
canalNumbers = it.canalNumbers,
canalDug = if (it.canalNumbers.isEmpty()) emptyList() else List(options.playerCount) { 0 },
wonders = if (scenario == SeaScenario.WONDERS_OF_CATAN) List(options.playerCount) { 0 } else emptyList(),
)
},
)
@@ -251,7 +259,7 @@ object CatanRules : GameRules<CatanState, CatanMove> {
private fun robberMoves(state: CatanState, seat: Int): List<MoveRobber> {
val moves = mutableListOf<MoveRobber>()
for (h in 0 until state.topo.HEX_COUNT) {
if (h == state.robber || !state.topo.land[h] || state.terrains[h] == Terrain.FOG) continue
if (h == state.robber || !state.topo.land[h] || state.terrains[h] == Terrain.FOG || state.terrains[h] == Terrain.FORTRESS) continue
val victims = state.topo.HEX_CORNERS[h]
.mapNotNull { state.buildings[it] }
.map { it.owner }
@@ -283,6 +291,7 @@ object CatanRules : GameRules<CatanState, CatanMove> {
if (state.isSea) {
if (affordable(state, seat, SeaRules.SHIP_COST)) moves += SeaRules.buildShipMoves(state, seat)
moves += SeaRules.moveShipMoves(state, seat)
moves += SeaRules.scenarioMoves(state, seat)
}
if (!state.devCardPlayedThisTurn) {
@@ -417,6 +426,7 @@ object CatanRules : GameRules<CatanState, CatanMove> {
/** An empty vertex with no building on it or one edge away. */
internal fun vertexOpenForSettlement(state: CatanState, v: Int): Boolean =
state.buildings[v] == null && !hasKnight(state, v) && state.topo.vertexLand[v] &&
!SeaRules.fortressHolds(state, v) &&
state.topo.VERTEX_NEIGHBORS[v].all { state.buildings[it] == null }
/**
@@ -470,6 +480,9 @@ object CatanRules : GameRules<CatanState, CatanMove> {
is MoveShip -> applyMoveShip(state, seat, move)
is MovePirate -> applyMovePirate(state, seat, move)
is PickGold -> applyPickGold(state, seat, move)
is RaidFortress -> SeaRules.applyRaid(state, seat, move)
is DigCanal -> SeaRules.applyDig(state, seat, move)
BuildWonder -> SeaRules.applyWonder(state, seat)
is BuildRoad -> applyBuildRoad(state, seat, move)
is BuildSettlement -> applyBuildSettlement(state, seat, move)
is BuildCity -> applyBuildCity(state, seat, move)
@@ -521,7 +534,7 @@ object CatanRules : GameRules<CatanState, CatanMove> {
}
val newIndex = state.setupIndex + 1
s = s.copy(setupIndex = newIndex)
s = refreshHarbormaster(s.copy(setupIndex = newIndex))
return when {
newIndex >= 2 * n -> s.copy(
phase = CatanPhase.AWAIT_ROLL,
@@ -1012,16 +1025,64 @@ object CatanRules : GameRules<CatanState, CatanMove> {
}
state.longestRoadOwner?.let { points[it] += 5 }
state.largestArmyOwner?.let { points[it] += 5 }
state.harbormaster?.let { points[it] += HARBORMASTER_POINTS }
if (state.isSea) for (seat in points.indices) points[seat] += SeaRules.bonusPoints(state, seat)
return points.toList()
}
// -----------------------------------------------------------------------
// The Harbormaster
// -----------------------------------------------------------------------
/** The scenario's title: points for a harbour town and for the Harbormaster. */
const val HARBORMASTER_MINIMUM = 3
const val HARBORMASTER_POINTS = 2
/** Whether this table plays the Harbormaster (never in a Seafarers game, which has its own maps). */
internal fun harbormasterGame(state: CatanState): Boolean =
state.options.baseScenario == BaseScenario.HARBORMASTER && !state.isSea
/** Harbour points: a settlement on a harbour counts 1, a city 2, for each harbour it touches. */
fun harbourPoints(state: CatanState, seat: Int): Int {
var total = 0
for (port in state.ports) {
val (a, b) = state.topo.EDGE_VERTICES[port.edge]
val own = listOfNotNull(state.buildings[a], state.buildings[b]).firstOrNull { it.owner == seat }
if (own != null) total += if (own.type == BuildingType.CITY) 2 else 1
}
return total
}
/** Gives the title to the first seat with three harbour points, and to a seat with strictly more than the holder. */
internal fun refreshHarbormaster(state: CatanState): CatanState {
if (!harbormasterGame(state)) return state
val points = List(state.playerCount) { harbourPoints(state, it) }
val holder = state.harbormaster
val best = points.max()
val leaders = points.indices.filter { points[it] == best }
val next = when {
holder == null -> leaders.singleOrNull()?.takeIf { best >= HARBORMASTER_MINIMUM }
best > points[holder] -> leaders.singleOrNull() ?: holder
else -> holder
}
if (next == holder) return state
return state.copy(
harbormaster = next,
log = state.log + if (holder == null) {
"Seat $next is now harbormaster."
} else {
"Seat $next has taken the title harbormaster from seat $holder."
},
)
}
fun victoryPoints(state: CatanState, seat: Int): Int =
publicVictoryPoints(state)[seat] +
state.devHands[seat].count { it.type == DevCardType.VICTORY_POINT }
internal fun checkWin(state: CatanState): CatanState {
if (state.phase == CatanPhase.GAME_OVER) return state
internal fun checkWin(settled: CatanState): CatanState {
if (settled.phase == CatanPhase.GAME_OVER) return settled
val state = refreshHarbormaster(settled)
val seat = state.turn
val points = victoryPoints(state, seat)
if (points < state.options.pointsToWin) return state
@@ -1220,7 +1281,7 @@ object CatanRules : GameRules<CatanState, CatanMove> {
state.copy(
// Hidden information stays with the holder and the host.
devDeck = emptyList(),
sea = state.sea?.copy(fogDeck = emptyList()),
sea = state.sea?.copy(fogDeck = emptyList(), treasures = emptyList()),
devHands = state.devHands.mapIndexed { index, hand ->
if (index == seat) hand else emptyList()
},
@@ -24,6 +24,31 @@ enum class SeaScenario(val title: String, val blurb: String, val start: SeaStart
"A home island, an islet, and a bank of fog. Land in the fog is face down until a road or ship reaches it; " +
"the finder takes a card of what lies there.",
),
TREASURE_ISLANDS(
"The Treasure Islands",
"Chests lie hidden on the fog-covered isles beside a home island. Whoever uncovers one opens it: " +
"cards, a resource of choice, a development card or a road's worth of materials.",
),
OASES(
"The Oases",
"An enormous desert, with fertile oases hidden inside it. Roads that reach an oasis uncover it " +
"and whatever treasure is buried there.",
),
GREAT_CANAL(
"The Great Canal",
"A desert strip splits the island. Dig the canal tile by tile (a brick and an ore a unit) and each finished " +
"tile becomes grain land; every two units dug are a victory point.",
),
PIRATE_ISLANDS(
"Pirate Islands",
"Two isles are held by pirate fortresses. Sail ships beside one and raid it with ore, wool and grain; " +
"nobody may settle the isle until the fortress falls, and the one who takes it earns two points.",
),
WONDERS_OF_CATAN(
"Wonders of Catan",
"Two big islands and room to grow. Raise a city, then build a wonder in four stages; each stage is a " +
"victory point and the first to finish all four wins.",
),
CLOTH_FOR_CATAN(
"Cloth for Catan",
"Four villages weave cloth. Settle beside one and it pays you a cloth token whenever its number rolls; " +
@@ -126,11 +151,72 @@ object SeaBoards {
"............",
)
private val TREASURE_ISLANDS_MAP = listOf(
"............",
"..###..FF...",
"..####..FF..",
"..#####.....",
"..###...F...",
".......FF...",
"..F.........",
"............",
)
private val OASES_MAP = listOf(
"............",
"..###DD###..",
"..#DDFDD#...",
"..#DDDFD#...",
"..#DFDDD#...",
"..###DD###..",
"............",
)
/** `C` is a canal tile: desert with a number hidden under it until it is dug out. */
private val GREAT_CANAL_MAP = listOf(
"............",
"..#####.....",
"..#####.....",
"..CCCCC.....",
"..#####.....",
"..#####.....",
"........$$..",
"............",
)
/** `P` is a pirate fortress. */
private val PIRATE_ISLANDS_MAP = listOf(
"............",
"..####.P##..",
"..####..##..",
"..####......",
"..####..P#..",
"...##...##..",
"............",
"............",
)
private val WONDERS_OF_CATAN_MAP = listOf(
"............",
"..####.###..",
".#####.####.",
"..###D.###..",
".......##...",
"..$......$..",
"...##.......",
"............",
)
private fun rows(scenario: SeaScenario): List<String> = when (scenario) {
SeaScenario.NEW_SHORES -> NEW_SHORES_MAP
SeaScenario.FOUR_ISLANDS -> FOUR_ISLANDS_MAP
SeaScenario.THROUGH_THE_DESERT -> THROUGH_THE_DESERT_MAP
SeaScenario.FOG_ISLANDS -> FOG_ISLANDS_MAP
SeaScenario.TREASURE_ISLANDS -> TREASURE_ISLANDS_MAP
SeaScenario.OASES -> OASES_MAP
SeaScenario.GREAT_CANAL -> GREAT_CANAL_MAP
SeaScenario.PIRATE_ISLANDS -> PIRATE_ISLANDS_MAP
SeaScenario.WONDERS_OF_CATAN -> WONDERS_OF_CATAN_MAP
SeaScenario.CLOTH_FOR_CATAN -> CLOTH_FOR_CATAN_MAP
SeaScenario.FORGOTTEN_TRIBE -> FORGOTTEN_TRIBE_MAP
}
@@ -178,6 +264,12 @@ object SeaBoards {
val chips: List<TribeChip> = emptyList(),
/** Cloth waiting on each village, by hex; empty when the map has none. */
val villageCloth: List<Int> = emptyList(),
/** Strength of the fortress on each hex, by hex; empty when the map has none. */
val fortress: List<Int> = emptyList(),
/** The chest under each hex, by hex; empty when the map has none. */
val treasures: List<Treasure> = emptyList(),
/** The number under each canal tile, by hex; empty when the map has none. */
val canalNumbers: List<Int> = emptyList(),
)
/** An island of this many land hexes or more can be started on. */
@@ -186,6 +278,12 @@ object SeaBoards {
/** Cloth each village starts with. */
const val VILLAGE_CLOTH = 6
/** Ships' raids a pirate fortress takes to fall. */
const val FORTRESS_STRENGTH = 3
/** Chests dealt to the fog, at most. */
private const val CHESTS = 5
private val RESOURCE_TILES = listOf(
Terrain.FOREST, Terrain.PASTURE, Terrain.FIELDS, Terrain.HILLS, Terrain.MOUNTAINS,
)
@@ -209,13 +307,15 @@ object SeaBoards {
'D' -> Terrain.DESERT
'#', 't' -> pool[plain.indexOf(h)]
'V' -> Terrain.VILLAGE
'P' -> Terrain.FORTRESS
'C' -> Terrain.DESERT
'F' -> Terrain.FOG
else -> Terrain.SEA
}
}
// The fog hexes take part as slots, so the tokens they hide are dealt from the same pile.
val numbered = terrains.indices.filter { terrains[it] != Terrain.SEA && terrains[it] != Terrain.DESERT }
val numbered = terrains.indices.filter { terrains[it] != Terrain.SEA && (terrains[it] != Terrain.DESERT && terrains[it] != Terrain.FORTRESS || kinds[it] == 'C') }
check(numbered.size <= TOKENS.size) { "Not enough number tokens for ${numbered.size} hexes" }
val tokens = TOKENS.take(numbered.size).shuffled(random)
val numbers = IntArray(terrains.size)
@@ -253,7 +353,9 @@ object SeaBoards {
val desert = terrains.indexOf(Terrain.DESERT).takeIf { it >= 0 }
?: numbered.first()
// Home is the largest island that is not under the fog: nobody starts on land they cannot see.
val fogged = fogHexes.map { topo.islandOf[it] }.toSet()
val fogged = (0 until topo.islandCount).filter { island ->
topo.islandOf.indices.filter { topo.islandOf[it] == island }.all { terrains[it] == Terrain.FOG }
}.toSet()
val home = (0 until topo.islandCount).filter { it !in fogged }
.maxByOrNull { island -> topo.islandOf.count { it == island } } ?: 0
// The pirate starts in the open sea: the sea hex farthest from every shore.
@@ -287,6 +389,30 @@ object SeaBoards {
List(terrains.size) { h -> if (terrains[h] == Terrain.VILLAGE) VILLAGE_CLOTH else 0 }
}
return Generated(terrains, numbers.toList(), desert, pirate, ports, home, starts, fogDeck, chips, villages)
val fortress = if (kinds.none { it == 'P' }) {
emptyList()
} else {
List(terrains.size) { h -> if (terrains[h] == Terrain.FORTRESS) FORTRESS_STRENGTH else 0 }
}
// Chests under the fog: the four rewards in turn, on hexes picked at random.
val chestKinds = listOf(Treasure.BRICK_WOOL_GRAIN, Treasure.CHOICE, Treasure.DEV_CARD, Treasure.ROADS)
val chestHexes = if (scenario == SeaScenario.TREASURE_ISLANDS || scenario == SeaScenario.OASES) {
fogHexes.shuffled(random).take(CHESTS)
} else {
emptyList()
}
val treasures = if (chestHexes.isEmpty()) {
emptyList()
} else {
List(terrains.size) { h -> chestHexes.indexOf(h).let { if (it < 0) Treasure.NONE else chestKinds[it % chestKinds.size] } }
}
// Canal tiles keep their number under the tile until it is dug out.
val canalHexes = kinds.indices.filter { kinds[it] == 'C' }
val canalNumbers = if (canalHexes.isEmpty()) emptyList() else List(terrains.size) { h -> if (h in canalHexes) numbers[h] else 0 }
canalHexes.forEach { numbers[it] = 0 }
return Generated(terrains, numbers.toList(), desert, pirate, ports, home, starts, fogDeck, chips, villages, fortress, treasures, canalNumbers)
}
}
@@ -182,11 +182,55 @@ internal object SeaRules {
} else if (tile.terrain == Terrain.GOLD) {
owed += GoldOwed(seat, 1)
}
val chest = s.sea!!.treasures.getOrNull(hex) ?: Treasure.NONE
if (chest != Treasure.NONE) {
val (opened, choose) = openChest(s, seat, chest)
s = opened
if (choose > 0) owed += GoldOwed(seat, choose)
}
}
if (owed.isEmpty()) return s
return owe(s, seat, owed.sumOf { it.count })
}
/**
* [seat] opens [chest]: the state after what it pays directly, and the number of cards of the seat's own
* choice still owed. Cards the bank cannot cover are simply not paid.
*/
private fun openChest(state: CatanState, seat: Int, chest: Treasure): Pair<CatanState, Int> {
var s = state
fun pay(cards: Map<Resource, Int>) {
val real = cards.filter { (r, n) -> CatanRules.bankSupply(s, r) >= n }
if (real.isNotEmpty()) s = s.copy(resources = CatanRules.withCounts(s.resources, seat, real, 1))
}
var choose = 0
val said = when (chest) {
Treasure.BRICK_WOOL_GRAIN -> {
pay(mapOf(Resource.BRICK to 1, Resource.WOOL to 1, Resource.GRAIN to 1))
"a brick, a wool and a grain"
}
Treasure.ROADS -> {
pay(mapOf(Resource.LUMBER to 2, Resource.BRICK to 2))
"materials for two roads"
}
Treasure.DEV_CARD -> if (!s.isCk && s.devDeck.isNotEmpty()) {
val card = s.devDeck.first().copy(boughtTurn = s.turnNumber)
val hands = s.devHands.toMutableList().also { it[seat] = it[seat] + card }
s = s.copy(devDeck = s.devDeck.drop(1), devHands = hands, devHandCounts = hands.map { it.size })
"a development card"
} else {
choose = 1
"a resource of its choice"
}
else -> {
choose = 1
"a resource of its choice"
}
}
s = s.copy(log = s.log + "Seat $seat opens a treasure chest: $said.")
return s to choose
}
/** Queues [count] cards of [seat]'s choice, to be taken before play resumes where it left off. */
private fun owe(state: CatanState, seat: Int, count: Int): CatanState {
val sea = state.sea!!
@@ -205,8 +249,54 @@ internal object SeaRules {
fun bonusPoints(state: CatanState, seat: Int): Int {
val sea = state.sea ?: return 0
return sea.islandBonus.count { it == seat } * ISLAND_BONUS +
(sea.raidPoints.getOrNull(seat) ?: 0) +
(sea.wonders.getOrNull(seat) ?: 0) +
clothOf(state, seat) / CLOTH_PER_POINT +
(sea.chipPoints.getOrNull(seat) ?: 0)
(sea.chipPoints.getOrNull(seat) ?: 0) +
(sea.canalDug.getOrNull(seat) ?: 0) / CANAL_UNITS_PER_POINT
}
// -----------------------------------------------------------------------
// The Great Canal
// -----------------------------------------------------------------------
val DIG_COST: Map<Resource, Int> = mapOf(Resource.BRICK to 1, Resource.ORE to 1)
/** Units that finish a canal tile. */
const val CANAL_TILE_UNITS = 3
/** Two units dug are a victory point. */
const val CANAL_UNITS_PER_POINT = 2
/** Tiles [seat] may dig a unit of: unfinished, with a settlement or city of the seat's on a corner. */
private fun digTargets(state: CatanState, seat: Int): List<Int> {
val sea = state.sea!!
if (sea.canalUnits.isEmpty()) return emptyList()
return sea.canalUnits.indices.filter { h ->
sea.canalNumbers[h] != 0 && sea.canalUnits[h] in 0 until CANAL_TILE_UNITS &&
state.terrains[h] == Terrain.DESERT &&
state.topo.HEX_CORNERS[h].any { state.buildings[it]?.owner == seat }
}
}
fun applyDig(state: CatanState, seat: Int, move: DigCanal): CatanState {
val sea = state.sea!!
val hex = state.topo.hexIndex.getValue(move.hex)
val units = sea.canalUnits[hex] + 1
val dug = sea.canalDug.toMutableList().also { it[seat] += 1 }
var s = state.copy(
resources = CatanRules.withCounts(state.resources, seat, DIG_COST, -1),
sea = sea.copy(canalUnits = sea.canalUnits.toMutableList().also { it[hex] = units }, canalDug = dug),
log = state.log + "Seat $seat digs the canal at (${move.hex.q},${move.hex.r}): $units of $CANAL_TILE_UNITS.",
)
if (units == CANAL_TILE_UNITS) {
s = s.copy(
terrains = s.terrains.toMutableList().also { it[hex] = Terrain.FIELDS },
numbers = s.numbers.toMutableList().also { it[hex] = sea.canalNumbers[hex] },
log = s.log + "The tile is dug out: it is fields now, with a ${sea.canalNumbers[hex]}.",
)
}
return CatanRules.checkWin(s)
}
// -----------------------------------------------------------------------
@@ -252,6 +342,104 @@ internal object SeaRules {
return s
}
// -----------------------------------------------------------------------
// Pirate Islands
// -----------------------------------------------------------------------
val RAID_COST: Map<Resource, Int> = mapOf(Resource.ORE to 1, Resource.WOOL to 1, Resource.GRAIN to 1)
const val FORTRESS_POINTS = 2
/** Whether a pirate fortress still stands on the island [vertex] is part of, so nobody may settle there. */
fun fortressHolds(state: CatanState, vertex: Int): Boolean {
val sea = state.sea ?: return false
if (sea.fortress.isEmpty()) return false
val island = state.topo.vertexIsland[vertex]
return island >= 0 && sea.fortress.indices.any { sea.fortress[it] > 0 && state.topo.islandOf[it] == island }
}
/** Fortress hexes [seat] has a ship beside. */
private fun raidTargets(state: CatanState, seat: Int): List<Int> {
val sea = state.sea!!
if (sea.fortress.isEmpty()) return emptyList()
val topo = state.topo
return sea.fortress.indices.filter { h ->
sea.fortress[h] > 0 && (0 until topo.EDGE_COUNT).any { h in topo.EDGE_HEXES[it] && sea.ships[it] == seat }
}
}
fun applyRaid(state: CatanState, seat: Int, move: RaidFortress): CatanState {
val sea = state.sea!!
val hex = state.topo.hexIndex.getValue(move.hex)
val left = sea.fortress[hex] - 1
var s = state.copy(resources = CatanRules.withCounts(state.resources, seat, RAID_COST, -1))
val strength = sea.fortress.toMutableList().also { it[hex] = left }
if (left > 0) {
return s.copy(
sea = sea.copy(fortress = strength),
log = s.log + "Seat $seat raids the fortress at (${move.hex.q},${move.hex.r}); $left strength left.",
)
}
val points = sea.raidPoints.ifEmpty { List(state.playerCount) { 0 } }.toMutableList().also { it[seat] += FORTRESS_POINTS }
s = s.copy(
terrains = s.terrains.toMutableList().also { it[hex] = Terrain.DESERT },
sea = sea.copy(fortress = strength, raidPoints = points),
log = s.log + "Seat $seat takes the fortress at (${move.hex.q},${move.hex.r}): +$FORTRESS_POINTS victory points, " +
"and the island is open.",
)
return CatanRules.checkWin(s)
}
// -----------------------------------------------------------------------
// Wonders of Catan
// -----------------------------------------------------------------------
/** What each of the four stages of a wonder costs. */
val WONDER_STAGES: List<Map<Resource, Int>> = listOf(
mapOf(Resource.BRICK to 2, Resource.LUMBER to 1, Resource.GRAIN to 1),
mapOf(Resource.BRICK to 1, Resource.ORE to 2, Resource.WOOL to 1),
mapOf(Resource.ORE to 3, Resource.GRAIN to 1, Resource.LUMBER to 1),
mapOf(Resource.ORE to 3, Resource.GRAIN to 2, Resource.BRICK to 1),
)
/** The next stage [seat] could build, if the scenario has wonders and the seat has a city to raise it in. */
private fun nextStage(state: CatanState, seat: Int): Map<Resource, Int>? {
val stage = state.sea?.wonders?.getOrNull(seat) ?: return null
if (stage >= WONDER_STAGES.size) return null
if (state.buildings.none { it?.owner == seat && it.type == BuildingType.CITY }) return null
return WONDER_STAGES[stage]
}
/** The extra moves a scenario offers during play: raids and wonder stages. */
fun scenarioMoves(state: CatanState, seat: Int): List<CatanMove> {
val moves = mutableListOf<CatanMove>()
if (CatanRules.affordable(state, seat, RAID_COST)) {
raidTargets(state, seat).forEach { moves += RaidFortress(state.topo.HEXES[it]) }
}
if (CatanRules.affordable(state, seat, DIG_COST)) {
digTargets(state, seat).forEach { moves += DigCanal(state.topo.HEXES[it]) }
}
nextStage(state, seat)?.let { if (CatanRules.affordable(state, seat, it)) moves += BuildWonder }
return moves
}
fun applyWonder(state: CatanState, seat: Int): CatanState {
val sea = state.sea!!
val stage = sea.wonders[seat] + 1
val built = sea.wonders.toMutableList().also { it[seat] = stage }
val s = state.copy(
resources = CatanRules.withCounts(state.resources, seat, WONDER_STAGES[stage - 1], -1),
sea = sea.copy(wonders = built),
log = state.log + "Seat $seat builds stage $stage of a wonder.",
)
if (stage < WONDER_STAGES.size) return CatanRules.checkWin(s)
return s.copy(
phase = CatanPhase.GAME_OVER,
winner = seat,
log = s.log + "Seat $seat completes a wonder of Catan and wins.",
)
}
// -----------------------------------------------------------------------
// The Forgotten Tribe
// -----------------------------------------------------------------------
@@ -61,6 +61,7 @@ import org.prolibertate.games.game.president.PresidentOptions
import org.prolibertate.games.game.catan.CatanOptions
import org.prolibertate.games.game.catan.CatanExpansion
import org.prolibertate.games.game.catan.SeaScenario
import org.prolibertate.games.game.catan.BaseScenario
import org.prolibertate.games.game.sequence.SequenceOptions
import org.prolibertate.games.game.tayu.TayuLevel
import org.prolibertate.games.game.tayu.TayuOptions
@@ -442,6 +443,15 @@ private fun CatanOptionsEditor(options: CatanOptions, onChange: (CatanOptions) -
onSelect = { onChange(options.copy(scenario = it)) },
)
Text(options.scenario.blurb, style = MaterialTheme.typography.bodySmall)
} else {
ChipRow(
label = "Island",
values = BaseScenario.entries,
selected = options.baseScenario,
display = { it.title },
onSelect = { onChange(options.copy(baseScenario = it)) },
)
Text(options.baseScenario.blurb, style = MaterialTheme.typography.bodySmall)
}
ChipRow(
label = "Players",
@@ -33,6 +33,7 @@ import org.prolibertate.games.game.catan.CatanBoard
import org.prolibertate.games.game.catan.CatanState
import org.prolibertate.games.game.catan.NO_PLAYER
import org.prolibertate.games.game.catan.Resource
import org.prolibertate.games.game.catan.SeaRules
import org.prolibertate.games.game.catan.Terrain
import org.prolibertate.games.game.catan.TribeChip
@@ -170,6 +171,9 @@ private fun DrawScope.drawHexes(
val sea = state.sea
val note = when {
state.terrains[hex] == Terrain.VILLAGE && sea != null -> "${sea.villageCloth.getOrElse(hex) { 0 }} cloth"
sea != null && sea.canalNumbers.getOrElse(hex) { 0 } != 0 && state.terrains[hex] == Terrain.DESERT ->
"dug ${sea.canalUnits.getOrElse(hex) { 0 }}/${SeaRules.CANAL_TILE_UNITS}"
state.terrains[hex] == Terrain.FORTRESS && sea != null -> "fort ${sea.fortress.getOrElse(hex) { 0 }}"
else -> when (sea?.chips?.getOrNull(hex)) {
TribeChip.POINT -> "+1 VP"
TribeChip.HARBOUR -> "3:1"
@@ -173,6 +173,9 @@ object CatanHudGlyphs {
BuildKind.WALL -> "▦"
BuildKind.KNIGHT -> "♞"
BuildKind.SHIP -> "⛵"
BuildKind.RAID -> "⚔"
BuildKind.DIG -> "⛏"
BuildKind.WONDER -> "✦"
}
fun label(kind: BuildKind): String = when (kind) {
@@ -182,6 +185,9 @@ object CatanHudGlyphs {
BuildKind.WALL -> CatanText.WALL
BuildKind.KNIGHT -> CatanText.KNIGHT
BuildKind.SHIP -> CatanText.SHIP
BuildKind.RAID -> CatanText.RAID
BuildKind.DIG -> CatanText.DIG
BuildKind.WONDER -> CatanText.WONDER
}
}
@@ -208,7 +214,7 @@ fun HudConfirmButtons(
fun ZoomPanBox(
modifier: Modifier = Modifier,
minScale: Float = 1f,
maxScale: Float = 3f,
maxScale: Float = 6f,
content: @Composable () -> Unit,
) {
var scale by remember { mutableFloatStateOf(1f) }
@@ -6,7 +6,10 @@ import org.prolibertate.games.game.catan.ActivateKnight
import org.prolibertate.games.game.catan.BuildCity
import org.prolibertate.games.game.catan.BuildRoad
import org.prolibertate.games.game.catan.BuildShip
import org.prolibertate.games.game.catan.BuildWonder
import org.prolibertate.games.game.catan.DigCanal
import org.prolibertate.games.game.catan.MovePirate
import org.prolibertate.games.game.catan.RaidFortress
import org.prolibertate.games.game.catan.MoveShip
import org.prolibertate.games.game.catan.Topology
import org.prolibertate.games.game.catan.BuildSettlement
@@ -67,13 +70,38 @@ enum class BuildKind {
ROAD, SETTLEMENT, CITY, WALL, KNIGHT,
/** Seafarers: a ship, laid on a sea edge. */
SHIP;
SHIP,
/** Pirate Islands: raid a fortress; the target is the fortress hex. */
RAID,
/** Great Canal: dig a canal tile; the target is the tile. */
DIG,
/** Wonders of Catan: the next stage of the wonder, which needs no tap on the board. */
WONDER;
companion object {
val BASE: List<BuildKind> = listOf(ROAD, SETTLEMENT, CITY)
/** Seafarers adds the ship, listed after the road it sails beside. */
val SEAFARERS: List<BuildKind> = listOf(ROAD, SHIP, SETTLEMENT, CITY)
/** The kinds a table's build menu lists: the scenario's own raid or wonder follows the usual ones. */
fun of(state: CatanState): List<BuildKind> {
val sea = state.sea
val extras = buildList {
if (sea != null && sea.fortress.isNotEmpty()) add(RAID)
if (sea != null && sea.canalUnits.isNotEmpty()) add(DIG)
if (sea != null && sea.wonders.isNotEmpty()) add(WONDER)
}
val usual = when {
state.isCk -> entries.filter { it != SHIP || state.isSea } - listOf(RAID, DIG, WONDER)
state.isSea -> SEAFARERS
else -> BASE
}
return usual + extras
}
}
}
@@ -252,6 +280,13 @@ object CatanInteraction {
return when (building) {
BuildKind.ROAD -> BoardTargets(edges = roads)
BuildKind.SHIP -> BoardTargets(edges = ships)
BuildKind.RAID -> BoardTargets(
hexes = legal.filterIsInstance<RaidFortress>().mapNotNull { state.topo.hexIndex[it.hex] }.toSet(),
)
BuildKind.DIG -> BoardTargets(
hexes = legal.filterIsInstance<DigCanal>().mapNotNull { state.topo.hexIndex[it.hex] }.toSet(),
)
BuildKind.WONDER -> BoardTargets()
BuildKind.SETTLEMENT ->
BoardTargets(vertices = legal.filterIsInstance<BuildSettlement>().map { it.vertex }.toSet())
@@ -519,6 +554,7 @@ object CatanInteraction {
val coord = topo.HEXES.getOrNull(hex) ?: return TapOutcome.Ignored
val moves = legal.filterIsInstance<MoveRobber>().filter { it.hex == coord }
val pirates = legal.filterIsInstance<MovePirate>().filter { it.hex == coord }
legal.firstOrNull { (it is RaidFortress && it.hex == coord) || (it is DigCanal && it.hex == coord) }?.let { return TapOutcome.Submit(it) }
return when {
moves.isNotEmpty() -> if (moves.size == 1) {
TapOutcome.Submit(moves.first())
@@ -586,6 +622,9 @@ object CatanInteraction {
if (legal.any { it is BuildShip }) add(BuildKind.SHIP)
if (legal.any { it is BuildSettlement }) add(BuildKind.SETTLEMENT)
if (legal.any { it is BuildCity }) add(BuildKind.CITY)
if (legal.any { it is RaidFortress }) add(BuildKind.RAID)
if (legal.any { it is DigCanal }) add(BuildKind.DIG)
if (legal.any { it is BuildWonder }) add(BuildKind.WONDER)
if (legal.any { it is BuildWall }) add(BuildKind.WALL)
if (legal.any { it is HireKnight }) add(BuildKind.KNIGHT)
}
@@ -256,6 +256,7 @@ fun CatanPlayerCard(
if (at.seat == seat) add(if (compact) track.name.first().toString() else "${CatanText.track(track)} metropolis")
}
if (ck.merchant?.seat == seat) add("Merchant")
if (state.harbormaster == seat) add(if (compact) "Harbor" else "Harbormaster")
addAll(seaAwards(state, seat, compact))
}
CardLine(
@@ -281,6 +282,7 @@ fun CatanPlayerCard(
val awards = buildList {
if (state.longestRoadOwner == seat) add(if (compact) "Road" else "Longest road")
if (state.largestArmyOwner == seat) add(if (compact) "Army" else "Largest army")
if (state.harbormaster == seat) add(if (compact) "Harbor" else "Harbormaster")
addAll(seaAwards(state, seat, compact))
}
// Always drawn, so the card does not grow when somebody takes an award.
@@ -600,6 +602,9 @@ private fun buildLabel(kind: BuildKind): String = when (kind) {
BuildKind.WALL -> CatanText.WALL
BuildKind.KNIGHT -> CatanText.KNIGHT
BuildKind.SHIP -> CatanText.SHIP
BuildKind.RAID -> CatanText.RAID
BuildKind.DIG -> CatanText.DIG
BuildKind.WONDER -> CatanText.WONDER
}
private fun buildCost(kind: BuildKind): String = when (kind) {
@@ -609,6 +614,9 @@ private fun buildCost(kind: BuildKind): String = when (kind) {
BuildKind.WALL -> CatanText.WALL_COST
BuildKind.KNIGHT -> CatanText.KNIGHT_COST
BuildKind.SHIP -> CatanText.SHIP_COST_TEXT
BuildKind.RAID -> CatanText.RAID_COST
BuildKind.DIG -> CatanText.DIG_COST
BuildKind.WONDER -> CatanText.WONDER_COST
}
@Composable
@@ -642,6 +650,8 @@ private fun seaAwards(state: CatanState, seat: Int, compact: Boolean): List<Stri
val sea = state.sea ?: return emptyList()
return buildList {
if (sea.cloth.isNotEmpty()) add(if (compact) "${sea.cloth[seat]}c" else "Cloth ${sea.cloth[seat]}")
if (sea.canalDug.isNotEmpty()) add(if (compact) "${sea.canalDug[seat]}⛏" else "Dug ${sea.canalDug[seat]}")
if (sea.wonders.isNotEmpty()) add(if (compact) "W${sea.wonders[seat]}" else "Wonder ${sea.wonders[seat]}/4")
if (seat in sea.harbourSeats) add(if (compact) "3:1" else "Harbour 3:1")
}
}
@@ -39,6 +39,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import org.prolibertate.games.game.catan.AcceptTrade
import org.prolibertate.games.game.catan.AqueductChore
import org.prolibertate.games.game.catan.BuildWonder
import org.prolibertate.games.game.catan.BuyDevCard
import org.prolibertate.games.game.catan.CatanCk
import org.prolibertate.games.game.catan.CatanMove
@@ -159,6 +160,14 @@ fun CatanScreen(
}
}
// A wonder stage needs no tap on the board: choosing it from the menu builds it.
LaunchedEffect(building) {
if (building == BuildKind.WONDER) {
legal.firstOrNull { it is BuildWonder }?.let { controller.submit(it) }
building = null
}
}
val submit: (CatanMove) -> Unit = { move ->
controller.submit(move)
building = null
@@ -197,11 +206,7 @@ fun CatanScreen(
val progressHand = CatanInteraction.progressHand(current, localSeat, legal)
val playing = current.phase == CatanPhase.PLAYING && legal.isNotEmpty()
val actions = CatanActions(
buildKinds = when {
current.isCk -> BuildKind.entries.filter { it != BuildKind.SHIP || current.isSea }
current.isSea -> BuildKind.SEAFARERS
else -> BuildKind.BASE
},
buildKinds = BuildKind.of(current),
ck = current.isCk,
canImprove = CatanInteraction.improvable(legal).isNotEmpty(),
canPlayProgress = progressHand.any { it.playable },
@@ -374,7 +379,8 @@ fun CatanScreen(
players(false)
if (current.isCk) CatanBarbarians(current, style = style)
promptRow()
Box(Modifier.weight(1f).fillMaxWidth(), contentAlignment = Alignment.Center) {
// Pinch to zoom and drag to pan, as in landscape: a wide Seafarers map is small at fit.
ZoomPanBox(Modifier.weight(1f).fillMaxWidth()) {
board(Modifier)
}
handAndActions()
@@ -128,6 +128,8 @@ private val LightStyle = CatanStyle(
Terrain.FOG to Color(0xFFB9C2C9),
// Cloth villages: a dyed-cloth purple.
Terrain.VILLAGE to Color(0xFF9B6BB5),
// A pirate fortress: dark stone.
Terrain.FORTRESS to Color(0xFF4A4F57),
),
hexEdge = Color(0x55000000),
token = Color(0xFFF7EFD9),
@@ -76,6 +76,7 @@ object CatanText {
Terrain.GOLD -> "Gold field"
Terrain.FOG -> "Fog"
Terrain.VILLAGE -> "Village"
Terrain.FORTRESS -> "Pirate fortress"
}
fun devCard(type: DevCardType): String = when (type) {
@@ -115,6 +116,12 @@ object CatanText {
const val SEA_ROBBER = "Move the robber (tap a land hex) or the pirate (tap a sea hex)."
const val SHIP = "Ship"
const val SHIP_COST_TEXT = "1 lumber + 1 wool"
const val RAID = "Raid"
const val RAID_COST = "1 ore + 1 wool + 1 grain"
const val DIG = "Dig"
const val DIG_COST = "1 brick + 1 ore"
const val WONDER = "Wonder"
const val WONDER_COST = "next stage"
const val GOLD_TITLE = "Gold field"
const val GOLD_TAKE = "Take"
const val ROLL = "Roll dice"
@@ -248,6 +255,8 @@ object CatanText {
!mine -> "$turn is playing…"
movingShip -> "Tap the sea edge to sail the ship to."
building == BuildKind.SHIP -> "Tap a sea edge beside your fleet or a harbour town to launch a ship."
building == BuildKind.RAID -> "Tap a pirate fortress your ship lies beside to raid it."
building == BuildKind.DIG -> "Tap a canal tile beside one of your towns to dig a unit."
building == BuildKind.ROAD -> "Tap an edge to build a road."
building == BuildKind.SETTLEMENT -> "Tap an empty crossing to build a settlement."
building == BuildKind.CITY -> "Tap one of your settlements to upgrade it."
@@ -452,6 +461,8 @@ object CatanText {
movingKnight -> "Tap where the knight should go."
movingShip -> "Tap the sea edge to sail the ship to."
building == BuildKind.SHIP -> "Tap a sea edge beside your fleet or a harbour town to launch a ship."
building == BuildKind.RAID -> "Tap a pirate fortress your ship lies beside to raid it."
building == BuildKind.DIG -> "Tap a canal tile beside one of your towns to dig a unit."
building == BuildKind.ROAD -> "Tap an edge to build a road."
building == BuildKind.SETTLEMENT -> "Tap an empty crossing to build a settlement."
building == BuildKind.CITY -> "Tap one of your settlements to upgrade it."
@@ -0,0 +1,115 @@
package org.prolibertate.games.game.catan
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNull
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
/** The base-island scenarios: First Island's fixed board and the Harbormaster. */
class CatanBaseScenarioTest {
private val json = Json { encodeDefaults = true }
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 game(
scenario: BaseScenario,
seed: Long = 5L,
expansions: Set<CatanExpansion> = emptySet(),
players: Int = 3,
) = CatanRules.initialState(config(CatanOptions(players, 10, expansions, baseScenario = scenario), seed))
@Test
fun `first island is the same board for every seed and the random map is not`() {
val a = game(BaseScenario.FIRST_ISLAND, 1L)
val b = game(BaseScenario.FIRST_ISLAND, 99L)
assertEquals(a.terrains, b.terrains)
assertEquals(a.numbers, b.numbers)
assertEquals(a.ports, b.ports)
assertNotEquals(game(BaseScenario.RANDOM_MAP, 1L).terrains, game(BaseScenario.RANDOM_MAP, 99L).terrains)
// The deck and the seating still follow the table's own seed.
assertNotEquals(a.devDeck, b.devDeck)
}
@Test
fun `a save from before base scenarios reads as a random map`() {
val old = """{"playerCount":3,"pointsToWin":10,"expansions":[],"scenario":"NEW_SHORES"}"""
assertEquals(BaseScenario.RANDOM_MAP, json.decodeFromString<CatanOptions>(old).baseScenario)
val options = CatanOptions(3, 10, baseScenario = BaseScenario.HARBORMASTER)
assertEquals(options, json.decodeFromString<CatanOptions>(json.encodeToString(options)))
}
/** Vertices of the harbours, one per harbour, in board order. */
private fun CatanState.harbourVertices(): List<Int> = ports.map { topo.EDGE_VERTICES[it.edge].first }
private fun CatanState.with(seat: Int, vertex: Int, type: BuildingType) =
copy(buildings = buildings.toMutableList().also { it[vertex] = CatanBuilding(type, seat) })
@Test
fun `three harbour points make a harbormaster and more takes the title`() {
var s = game(BaseScenario.HARBORMASTER).copy(phase = CatanPhase.PLAYING, turn = 0, turnNumber = 1)
val v = s.harbourVertices()
s = s.with(0, v[0], BuildingType.SETTLEMENT).with(0, v[1], BuildingType.SETTLEMENT)
assertEquals(2, CatanRules.harbourPoints(s, 0))
assertNull(CatanRules.refreshHarbormaster(s).harbormaster)
// A city counts two: 1 + 2 = 3.
s = CatanRules.refreshHarbormaster(s.with(0, v[1], BuildingType.CITY))
assertEquals(3, CatanRules.harbourPoints(s, 0))
assertEquals(0, s.harbormaster)
assertEquals(CatanRules.publicVictoryPoints(s.copy(harbormaster = null))[0] + 2, CatanRules.publicVictoryPoints(s)[0])
// Equal points do not take it; strictly more does.
s = CatanRules.refreshHarbormaster(
s.with(1, v[2], BuildingType.SETTLEMENT).with(1, v[3], BuildingType.SETTLEMENT).with(1, v[4], BuildingType.SETTLEMENT),
)
assertEquals(0, s.harbormaster)
s = CatanRules.refreshHarbormaster(s.with(1, v[5], BuildingType.SETTLEMENT))
assertEquals(1, s.harbormaster)
assertTrue(s.log.any { "taken the title harbormaster from seat 0" in it })
}
@Test
fun `the title does not exist in other scenarios or in a Seafarers game`() {
var s = game(BaseScenario.RANDOM_MAP).copy(phase = CatanPhase.PLAYING)
val v = s.harbourVertices()
for (i in 0..3) s = s.with(0, v[i], BuildingType.SETTLEMENT)
assertNull(CatanRules.refreshHarbormaster(s).harbormaster)
}
@Test
fun `engines finish games on the base scenarios, with and without Cities and Knights`() {
var titles = 0
for (scenario in listOf(BaseScenario.FIRST_ISLAND, BaseScenario.HARBORMASTER)) {
for (expansions in listOf(emptySet(), setOf(CatanExpansion.CITIES_AND_KNIGHTS))) {
for ((players, seed) in listOf(3 to 31L, 4 to 32L)) {
val opts = CatanOptions(players, if (expansions.isEmpty()) 10 else 13, expansions, baseScenario = scenario)
var state = CatanRules.initialState(config(opts, seed))
val ai = CatanAi()
var moves = 0
while (!CatanRules.isFinished(state)) {
assertTrue("$scenario $expansions seed $seed ran long", moves++ < 20_000)
val seat = CatanRules.currentSeat(state)!!
val legal = CatanRules.legalMoves(state, seat)
state = CatanRules.applyMove(state, seat, ai.chooseMove(state, seat, legal))
}
if (state.harbormaster != null) titles++
assertEquals(state, CatanRules.decodeState(CatanRules.encodeState(state)))
}
}
}
assertTrue("nobody ever became harbormaster", titles > 0)
}
}
@@ -165,4 +165,172 @@ class CatanSeaExtrasTest {
val done = CatanRules.applyMove(after, 0, CatanRules.legalMoves(after, 0).first())
assertEquals(CatanPhase.PLAYING, done.phase)
}
// ---- Pirate Islands ----
private fun fortGame(): Triple<CatanState, Int, Int> {
val s = start(SeaScenario.PIRATE_ISLANDS).copy(
phase = CatanPhase.PLAYING,
resources = List(3) { Resource.entries.associateWith { 6 } },
)
val fort = s.terrains.indexOf(Terrain.FORTRESS)
val edge = (0 until s.topo.EDGE_COUNT).first { s.topo.edgeSea[it] && fort in s.topo.EDGE_HEXES[it] }
return Triple(s, fort, edge)
}
@Test
fun `nobody settles a fortress island until the fortress falls`() {
val (s, fort, _) = fortGame()
val corner = s.topo.HEX_CORNERS[fort].first()
assertTrue(SeaRules.fortressHolds(s, corner))
assertTrue(!CatanRules.vertexOpenForSettlement(s, corner))
val fort2 = s.terrains.indices.first { s.terrains[it] == Terrain.FORTRESS && it != fort }
assertTrue(s.topo.islandOf[fort] != s.topo.islandOf[fort2])
}
@Test
fun `a raid needs a ship beside the fortress and three cards, and three raids take it`() {
val (s, fort, edge) = fortGame()
val coord = s.topo.HEXES[fort]
assertTrue(CatanRules.legalMoves(s, 0).none { it is RaidFortress })
var state = s.copy(sea = s.sea!!.copy(ships = s.sea!!.ships.toMutableList().also { it[edge] = 0 }))
assertTrue(RaidFortress(coord) in CatanRules.legalMoves(state, 0))
val before = state.resources[0].getValue(Resource.ORE)
repeat(3) { state = CatanRules.applyMove(state, 0, RaidFortress(coord)) }
assertEquals(before - 3, state.resources[0].getValue(Resource.ORE))
assertEquals(Terrain.DESERT, state.terrains[fort])
assertEquals(2, state.sea!!.raidPoints[0])
assertTrue(!SeaRules.fortressHolds(state, s.topo.HEX_CORNERS[fort].first()))
assertTrue(CatanRules.legalMoves(state, 0).none { it is RaidFortress })
// Seat 1 has no ship there and cannot raid.
assertTrue(CatanRules.legalMoves(state.copy(turn = 1), 1).none { it is RaidFortress })
}
// ---- Wonders of Catan ----
private fun wonderGame(city: Boolean = true): CatanState {
val s = start(SeaScenario.WONDERS_OF_CATAN).copy(
phase = CatanPhase.PLAYING,
resources = List(3) { Resource.entries.associateWith { 9 } },
)
return if (!city) s else s.copy(
buildings = s.buildings.toMutableList().also { it[0] = CatanBuilding(BuildingType.CITY, 0) },
)
}
@Test
fun `a wonder needs a city, each stage is a point, and the fourth stage wins`() {
assertTrue(CatanRules.legalMoves(wonderGame(city = false), 0).none { it is BuildWonder })
var s = wonderGame()
val base = CatanRules.publicVictoryPoints(s)[0]
for (stage in 1..3) {
assertTrue(BuildWonder in CatanRules.legalMoves(s, 0))
s = CatanRules.applyMove(s, 0, BuildWonder)
assertEquals(stage, s.sea!!.wonders[0])
assertEquals(base + stage, CatanRules.publicVictoryPoints(s)[0])
assertEquals(CatanPhase.PLAYING, s.phase)
}
s = CatanRules.applyMove(s, 0, BuildWonder)
assertEquals(CatanPhase.GAME_OVER, s.phase)
assertEquals(0, s.winner)
assertEquals(s, CatanRules.decodeState(CatanRules.encodeState(s)))
}
@Test
fun `a wonder stage is not offered without the cards`() {
val s = wonderGame().copy(resources = List(3) { Resource.entries.associateWith { 0 } })
assertTrue(CatanRules.legalMoves(s, 0).none { it is BuildWonder })
}
// ---- Treasure Islands, Oases ----
@Test
fun `chests lie under the fog and are hidden from other views`() {
for (scenario in listOf(SeaScenario.TREASURE_ISLANDS, SeaScenario.OASES)) {
val s = start(scenario)
val chests = s.sea!!.treasures.indices.filter { s.sea!!.treasures[it] != Treasure.NONE }
assertEquals(minOf(5, s.terrains.count { it == Terrain.FOG }), chests.size)
assertTrue(chests.all { s.terrains[it] == Terrain.FOG })
assertTrue(CatanRules.viewFor(s, 1).sea!!.treasures.isEmpty())
}
}
@Test
fun `an oasis map starts everyone on the desert island, never beside an oasis`() {
val s = start(SeaScenario.OASES)
assertEquals(37, s.topo.islandOf.count { it == s.sea!!.home })
val moves = CatanRules.legalMoves(s.copy(phase = CatanPhase.SETUP_FIRST), s.firstSeat).filterIsInstance<SetupPlace>()
assertTrue(moves.isNotEmpty())
assertTrue(moves.all { m -> s.topo.VERTEX_HEXES[m.vertex].none { s.terrains[it] == Terrain.FOG } })
}
/** A chest of [kind] under the first fog hex, with a road of seat 0's laid up to the edge that will reveal it. */
private fun chestGame(kind: Treasure): Triple<CatanState, Int, Int> {
val s = start(SeaScenario.OASES).copy(phase = CatanPhase.PLAYING)
val topo = s.topo
val hex = s.terrains.indexOf(Terrain.FOG)
val chests = List(topo.HEX_COUNT) { if (it == hex) kind else Treasure.NONE }
// Seat 0 owns the town beside a road that reaches the oasis; building the road finds it.
val edge = topo.EDGE_VERTICES.indices.first { e -> hex in topo.EDGE_HEXES[e] && topo.edgeLand[e] }
val staged = s.copy(
resources = List(3) { Resource.entries.associateWith { 5 } },
sea = s.sea!!.copy(treasures = chests),
)
return Triple(staged, hex, edge)
}
@Test
fun `opening a chest pays its reward`() {
val kinds = listOf(Treasure.BRICK_WOOL_GRAIN, Treasure.ROADS, Treasure.DEV_CARD, Treasure.CHOICE)
for (kind in kinds) {
val (s, _, _) = chestGame(kind)
// Stage the find directly: reveal as if a road had just reached the hex.
val topo = s.topo
val hex = s.terrains.indexOf(Terrain.FOG)
val edge = (0 until topo.EDGE_COUNT).first { hex in topo.EDGE_HEXES[it] && topo.edgeLand[it] }
val after = SeaRules.reveal(s, 0, edge)
assertTrue("$kind: the chest is announced", after.log.any { "treasure chest" in it })
when (kind) {
Treasure.DEV_CARD -> assertEquals(1, after.devHands[0].size)
Treasure.CHOICE -> assertTrue(after.phase == CatanPhase.GOLD || after.log.any { "uncovers" in it })
Treasure.ROADS -> assertTrue(after.resources[0].getValue(Resource.LUMBER) >= 7)
else -> assertTrue(after.resources[0].getValue(Resource.WOOL) >= 6)
}
}
}
// ---- The Great Canal ----
private fun canalGame(): Triple<CatanState, Int, CatanState> {
val s = start(SeaScenario.GREAT_CANAL).copy(
phase = CatanPhase.PLAYING,
resources = List(3) { Resource.entries.associateWith { 9 } },
)
val tile = s.sea!!.canalNumbers.indexOfFirst { it != 0 }
val staged = s.copy(
buildings = s.buildings.toMutableList().also {
it[s.topo.HEX_CORNERS[tile][0]] = CatanBuilding(BuildingType.SETTLEMENT, 0)
},
)
return Triple(staged, tile, s)
}
@Test
fun `a canal tile hides its number, and three digs turn it into fields`() {
var (s, tile, _) = canalGame()
assertEquals(0, s.numbers[tile])
assertEquals(Terrain.DESERT, s.terrains[tile])
val number = s.sea!!.canalNumbers[tile]
val dig = DigCanal(s.topo.HEXES[tile])
assertTrue(dig in CatanRules.legalMoves(s, 0))
assertTrue(CatanRules.legalMoves(s.copy(turn = 1), 1).none { it is DigCanal })
val before = CatanRules.publicVictoryPoints(s)[0]
repeat(2) { s = CatanRules.applyMove(s, 0, dig) }
assertEquals(Terrain.DESERT, s.terrains[tile])
assertEquals(before + 1, CatanRules.publicVictoryPoints(s)[0])
s = CatanRules.applyMove(s, 0, dig)
assertEquals(Terrain.FIELDS, s.terrains[tile])
assertEquals(number, s.numbers[tile])
assertTrue(CatanRules.legalMoves(s, 0).none { it is DigCanal && it.hex == dig.hex })
}
}
@@ -43,6 +43,11 @@ class CatanSeaScenariosTest {
assertEquals(listOf(1, 1, 6, 6, 6, 6), sizes(SeaScenario.FOUR_ISLANDS))
assertEquals(listOf(1, 1, 1, 2, 25), sizes(SeaScenario.THROUGH_THE_DESERT))
assertEquals(listOf(2, 13, 14), sizes(SeaScenario.FOG_ISLANDS))
assertEquals(listOf(1, 3, 4, 15), sizes(SeaScenario.TREASURE_ISLANDS))
assertEquals(listOf(37), sizes(SeaScenario.OASES))
assertEquals(listOf(2, 25), sizes(SeaScenario.GREAT_CANAL))
assertEquals(listOf(4, 5, 18), sizes(SeaScenario.PIRATE_ISLANDS))
assertEquals(listOf(1, 3, 12, 13), sizes(SeaScenario.WONDERS_OF_CATAN))
assertEquals(listOf(2, 3, 6, 17), sizes(SeaScenario.CLOTH_FOR_CATAN))
assertEquals(listOf(2, 3, 5, 17), sizes(SeaScenario.FORGOTTEN_TRIBE))
}
@@ -57,11 +62,13 @@ class CatanSeaScenariosTest {
for (h in 0 until topo.HEX_COUNT) {
val land = s.terrains[h] != Terrain.SEA
assertEquals("$scenario hex $h", topo.land[h], land)
val unnumbered = s.terrains[h] == Terrain.DESERT || s.terrains[h] == Terrain.FOG
val unnumbered = s.terrains[h] == Terrain.DESERT || s.terrains[h] == Terrain.FOG ||
s.terrains[h] == Terrain.FORTRESS
assertEquals("$scenario hex $h", land && !unnumbered, s.numbers[h] != 0)
}
val deserted = scenario != SeaScenario.FOUR_ISLANDS && scenario != SeaScenario.CLOTH_FOR_CATAN &&
scenario != SeaScenario.FORGOTTEN_TRIBE
scenario != SeaScenario.FORGOTTEN_TRIBE && scenario != SeaScenario.PIRATE_ISLANDS &&
scenario != SeaScenario.TREASURE_ISLANDS
assertTrue("$scenario has no desert", deserts > 0 || !deserted)
// Under fog every hex is face down with no number; the tiles are in the pile.
val fog = s.terrains.indices.filter { s.terrains[it] == Terrain.FOG }
@@ -214,6 +221,10 @@ class CatanSeaScenariosTest {
var fogFound = 0
var clothPaid = 0
var chipsTaken = 0
var fortsTaken = 0
var wonderStages = 0
var chestsOpened = 0
var canalDug = 0
for (scenario in SeaScenario.entries) {
for ((players, seed) in listOf(3 to 11L, 4 to 12L, 3 to 13L)) {
val opts = options(scenario, players)
@@ -232,6 +243,12 @@ class CatanSeaScenariosTest {
assertEquals("$scenario seed $seed", CatanPhase.GAME_OVER, state.phase)
if (scenario == SeaScenario.FOG_ISLANDS) fogFound += 14 - state.sea!!.fogDeck.size
if (scenario == SeaScenario.CLOTH_FOR_CATAN) clothPaid += state.sea!!.cloth.sum()
if (scenario == SeaScenario.PIRATE_ISLANDS) fortsTaken += state.sea!!.raidPoints.sum() / 2
if (scenario == SeaScenario.TREASURE_ISLANDS || scenario == SeaScenario.OASES) {
chestsOpened += state.log.count { "treasure chest" in it }
}
if (scenario == SeaScenario.GREAT_CANAL) canalDug += state.sea!!.canalDug.sum()
if (scenario == SeaScenario.WONDERS_OF_CATAN) wonderStages += state.sea!!.wonders.sum()
if (scenario == SeaScenario.FORGOTTEN_TRIBE) {
chipsTaken += 4 - state.sea!!.chips.count { it != TribeChip.NONE }
}
@@ -241,5 +258,9 @@ class CatanSeaScenariosTest {
assertTrue("no engine ever uncovered a fog hex", fogFound > 0)
assertTrue("no village ever paid cloth", clothPaid > 0)
assertTrue("no tribe chip was ever taken", chipsTaken > 0)
assertTrue("no fortress ever fell", fortsTaken > 0)
assertTrue("no chest was ever opened", chestsOpened > 0)
assertTrue("no canal unit was ever dug", canalDug > 0)
assertTrue("no wonder stage was ever built", wonderStages > 0)
}
}
+7 -1
View File
@@ -66,7 +66,13 @@ A full-width panel that slides up over the bottom of the screen (`Animator`, col
* **Fog islands:** `Check_FogField`, `DistributeFogField` (hidden hex revealed when a
road/ship reaches it, the player takes the resource), `Shuffle_Islands`, `Shuffle_TileValueList`.
* **Treasure islands / Oasis / Great Canal** are Catan Universe scenario extras and are
**not** part of the physical Seafarers rules; they are out of scope here.
**not** part of the physical Seafarers rules. Names and texts only (rule values are compiled code):
`TreasureRule` with chest outcomes (bricks, wool, grain; a resource; a development card; two roads),
`SeafarerOasis` (no rule class of its own, base-game rules), and `GreatCanalRule` with `BuildCanal`,
`CanalVictoryPoints`, "The canal was completely dug. Now grain can be grown." and a target of 21 / 18 points.
The base-game scenario `baseharbormaster`: "2 victory points. This card goes to the first player to acquire at
least 3 harbors. If another player acquires more, he will immediately receive this card."
Implemented as inferred rules; see `docs/RULES-catan-seafarers.md`.
* **Setup:** `StartPhase_BuildSettlement`, `StartPhase_BuildRoadShip`, `PlaceValueChip`
(number tokens placed per scenario), `Shuffle_Harbors`.
* **Island bonus:** special victory points for the first settlement on a new island
+59 -3
View File
@@ -32,6 +32,15 @@ Pick the map at setup; each scenario names where the starting settlements may go
* **The Forgotten Tribe.** A 17-hex home island and three isles carrying four tribe chips. See *The Forgotten
Tribe* below.
* **Pirate Islands.** An 18-hex home island and two isles (five and four hexes) each held by a pirate
fortress. See *Pirate Islands* below.
* **Wonders of Catan.** A 13-hex island with a desert, a 12-hex island, and gold islets. See *Wonders* below.
* **The Treasure Islands** *(Catan Universe extra)*. A 15-hex home island and four fog isles, eight hexes of fog in
all. See *Catan Universe extras* below.
* **The Oases** *(Catan Universe extra)*. One 37-hex island that is mostly desert, with three oases hidden in it.
* **The Great Canal** *(Catan Universe extra)*. A 25-hex island split by a row of five canal tiles, and gold islets.
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,
@@ -115,6 +124,50 @@ board). The chips are dealt at the start of the game, one of each kind in turn:
A **gold** chip pays two resources of the settler's choice, taken at once like gold.
* The chips come on top of the island bonus for being first to a new island.
## Pirate Islands
The author's reading of the scenario; the printed one uses knights and a roaming pirate fleet, which this does not.
* A **fortress** is a land hex with no number and a strength of 3. Nobody may build a settlement on any crossing of
an island that still has a standing fortress. Roads and ships may go there.
* A seat with a **ship beside** a fortress may **raid** it in its turn for 1 ore, 1 wool and 1 grain, as many times as
it can pay. Each raid takes one point of strength.
* The raid that takes the last point **takes the fortress**: the hex becomes desert (no number, robber may sit there),
the island is open to settle for everyone, and the taker gets **2 victory points**. The robber never sits on a
standing fortress.
* The island still counts as a new island for the first-landing bonus.
## Wonders
Also the author's reading. Every seat may build one wonder in four stages, once it has a **city** anywhere on the
board. Each stage is one move costing cards (stage 1: 2 brick, 1 lumber, 1 grain; 2: 1 brick, 2 ore, 1 wool; 3: 3 ore,
1 grain, 1 lumber; 4: 3 ore, 2 grain, 1 brick). Each stage built is **one victory point**, and the seat that
builds the fourth stage **wins at once**, whatever the point target. Wonders are not shared: each seat has its own.
## Catan Universe extras (inferred)
These three exist in the Catan Universe app but not in the physical set. Only their names, menu texts and log
lines could be read (`docs/RE-catan-universe.md`); the rule values are compiled code that was not recovered. **Every
rule below is inferred from those names and texts**, not copied.
* **Treasure Islands.** The app's text: "Treasures await the Catanians on neighboring, fog-covered islands.
Discoveries are rewarded!" Its chest rewards (log texts and action names) are bricks, wool and grain; a resource of
choice; a development card; two roads. Here: up to five chests are dealt face down to random fog hexes at the
start. A seat that uncovers the hex (the fog rules) opens the chest at once and takes: *a brick, a wool and a grain*;
*one resource of its choice* (a gold pick); *a development card* (a resource of choice if the deck is empty or it is
Cities & Knights, which has no deck); or *two lumber and two brick* standing in for two free roads (the free-roads
phase would have to nest inside a ship move). The app's Cities & Knights version gives a progress card; that is
not modelled. The app's fixed treasure bonus (`SEAFARER_TREASURE_BONUS`) is not modelled either.
* **The Oases.** The app's text: an enormous desert with rumoured oases and treasures, base-game rules. Here: the
oases are fog hexes inside the desert, uncovered by a road reaching them, and hold the same chests as above.
There is no ship rule on the map itself.
* **The Great Canal.** The app's text, for Cities & Knights plus Seafarers: build a canal; first to 21 (3 players) or
18 (4 players) wins; the canal's parts earn victory points; when a tile is dug out, grain grows there. Its knights dig
in the app; here digging is cheaper to implement and play without Cities & Knights: a canal tile is a desert hex with
its number token hidden. A seat with a settlement or city on a corner of the tile digs one **unit** for 1 brick and
1 ore; **three units** finish the tile, which becomes **fields** with the hidden number. Every **two units** a seat
has dug are a **victory point**. The app's gold river, harbour changes and target scores are not modelled.
## With Cities & Knights
Switching both expansions on plays [Cities & Knights](RULES-catan-ck.md) on any Seafarers map
@@ -137,8 +190,10 @@ Where the two meet, this game decides as follows:
## Not included
The physical expansion has more scenarios and the Catan Universe app adds more still. These are **out of scope here**:
treasure islands, the oasis, the great canal, the Explorers & Pirates combination,
the scenarios that need new rules (wonders, pirate islands) and trade ships.
the Explorers & Pirates combination,
the printed rules of the wonders and pirate-islands scenarios (the versions here are simplified) and trade ships.
Drought and the app's other scenarios (Six Islands, Oceania, Great Catan, Enchanted Land, the Inka and Big Game sets)
are not built.
A map-only scenario is a new text map and a new `SeaScenario` entry.
## How the AI plays it
@@ -146,5 +201,6 @@ A map-only scenario is a new text map and a new `SeaScenario` entry.
It settles first and sails second. A ship is built when a settlement spot reachable by sea (up to five steps from its
open end) is worth having, with a bonus for an island nobody has landed on, and ahead of a development card when that
bonus is in play. A spot beside a village that still has cloth, or beside a tribe chip nobody has taken, is
worth more (`CatanAi.scenarioLure`). It chooses the resource it values most from gold, always moves the robber (never the pirate) and does
worth more (`CatanAi.scenarioLure`), a ship that heads for a standing fortress is worth building, and it raids and builds
wonder stages whenever it can pay (`CatanAi.FORT_LURE`). It chooses the resource it values most from gold, always moves the robber (never the pirate) and does
not sail ships it has already launched. See `CatanAi.shipValue`.
+20
View File
@@ -23,6 +23,26 @@ A table plays one of two rule sets, chosen on the setup screen
building, robber and trade rules and changes or replaces the rest; its state lives
behind `CatanState.ck`, which is `null` in the base game.
## Base-island scenarios
Without Seafarers the setup screen offers an **Island** choice (`CatanOptions.baseScenario`; it works with Cities &
Knights too). Both extras are the author's reading, not transcriptions of the printed scenarios:
- **Random map** (default) — the usual shuffled island.
- **First Island** — the same island every game: one fixed shuffle (`CatanBoard.FIRST_ISLAND_SEED`) of the standard
tiles, numbers and harbours, so a first game or a rematch has no surprise set-up. It is not the printed beginner
layout. The development deck and the seating still follow the table's own seed.
- **The Harbormaster** — the Catan Universe menu text is "Because trade becomes more and more important, harbours
have an ever increasing significance." Its card: 2 victory points to the first player with at least three harbour
points; another player with more takes it at once. What a harbour point is was not in the app's texts, so it is
inferred: a settlement on a harbour counts **1**, a city **2**, for each harbour it touches. The title is checked after
every settlement, city and set-up placement; **equal points do not take it**, only strictly more (like Longest
Road); it is **+2 victory points** to the holder (`CatanState.harbormaster`). The AI values a harbour spot a
little more here (`CatanAi.HARBOR_LURE`).
Seafarers games choose a map instead (see [RULES-catan-seafarers.md](RULES-catan-seafarers.md)); the Harbormaster does not apply there.
The app's other base scenario, Ore for Wool, is not built: its rules are not in the texts that could be read.
## Table
- **Rules — *toggle*.** Base game or Cities & Knights (`CatanOptions.ruleSet`).