Preserve exhausted terrain movement rules; release viewer 228 engine 160

This commit is contained in:
coyotte508 2026-11-19 08:53:42 +00:00
commit 8b3b81e7f8
12 changed files with 352 additions and 12 deletions

View file

@ -176,7 +176,7 @@ pub(crate) fn finish_city_move(game: &mut Game, player: usize, from: Position, t
game.player_mut(player).event_info.remove("Nomads moving");
let origin = EventOrigin::SpecialAdvance(SpecialAdvance::Nomads);
activate_city(from, game, &origin);
let mountain = game.map.get(to) == Some(&Terrain::Mountain);
let mountain = game.map.get(to).map(Terrain::movement_terrain) == Some(&Terrain::Mountain);
let city = game.player_mut(player).get_city_mut(from);
city.position = to;
city.nomad_mountain = mountain;

View file

@ -184,6 +184,16 @@ pub enum Terrain {
}
impl Terrain {
/// Terrain identity for movement rules only. Exhaustion still prevents resource
/// collection and founding; callers of those rules must keep the wrapper.
#[must_use]
pub fn movement_terrain(&self) -> &Self {
match self {
Self::Exhausted(terrain) => terrain.movement_terrain(),
terrain => terrain,
}
}
#[must_use]
pub fn is_water(&self) -> bool {
matches!(self, Terrain::Water)

View file

@ -831,7 +831,7 @@ fn terrain_movement_restriction(
let terrain = map
.get(destination)
.expect("the destination position should exist on the map");
match terrain {
match terrain.movement_terrain() {
Fertile => Some(MovementRestriction::Fertile),
Mountain => Some(MovementRestriction::Mountain),
Forest if unit.is_army_unit() => Some(MovementRestriction::Forest),

View file

@ -199,7 +199,7 @@ fn terrain_notes(
destination: Position,
) -> Vec<&'static str> {
let mut notes = vec![];
match game.map.get(destination) {
match game.map.get(destination).map(Terrain::movement_terrain) {
Some(Terrain::Mountain) => {
if crate::content::civilizations::carthage::ignores_mountains(player, units) {
notes.push("Hannibal with elephants: ignores the mountain movement stop.");
@ -268,7 +268,9 @@ pub fn movement(game: &Game, seat: usize, units: Vec<u32>) -> Result<Value, Stri
&& start.is_neighbor(route.destination)
&& (game.enemy_player(seat, route.destination).is_some()
|| !matches!(
game.map.get(route.destination),
game.map
.get(route.destination)
.map(Terrain::movement_terrain),
Some(Terrain::Mountain | Terrain::Forest)
))
&& routes.iter().any(|ordinary| {

View file

@ -271,3 +271,165 @@ fn test_ship_navigate_explore_not_move() {
)],
);
}
// Rulebook pp.14,25: exhaustion suppresses collection/founding, not terrain movement.
#[test]
fn exhausted_terrain_retains_turn_movement_restrictions() {
use server::action::{execute_action, try_execute_action};
use server::game::GameState;
use server::map::Terrain;
use server::movement::MovementAction;
use server::unit::UnitType;
for terrain in [Terrain::Forest, Terrain::Mountain, Terrain::Fertile] {
for exhausted in [false, true] {
for unit_type in [UnitType::Infantry, UnitType::Settler] {
let mut game = JSON.load_game("movement");
game.state = GameState::Playing;
game.actions_left = 3;
game.player_mut(0)
.advances
.insert(server::advance::Advance::Tactics);
let start = Position::new(0, 0);
let entered = Position::new(1, 0);
let peaceful = Position::new(2, 0);
let enemy = Position::new(1, 1);
game.map.tiles.clear();
for pos in [start, entered, peaceful, enemy] {
game.map.tiles.insert(pos, Terrain::Barren);
}
game.map.tiles.insert(
entered,
if exhausted {
Terrain::Exhausted(Box::new(terrain.clone()))
} else {
terrain.clone()
},
);
for p in &mut game.players {
p.cities.clear();
p.units.clear();
}
game.player_mut(0).units.push(server::unit::Unit::new(
0,
start,
unit_type.clone(),
0,
));
let id = game.player(0).units[0].id;
game.player_mut(0).units.push(server::unit::Unit::new(
0,
entered,
UnitType::Infantry,
1,
));
let fresh = game.player(0).units[1].id;
game.player_mut(1).units.push(server::unit::Unit::new(
1,
enemy,
UnitType::Infantry,
0,
));
// Starting on the terrain is not entering it.
assert!(
possible_move_routes(game.player(0), &game, &[fresh], entered, None)
.unwrap()
.iter()
.any(|r| r.destination == peaceful)
);
game = execute_action(game, move_action(vec![id], entered), 0);
// Same Move action forbids moving the same units, independently of terrain.
assert!(
try_execute_action(game.clone(), move_action(vec![id], peaceful), 0).is_err()
);
game = execute_action(game, Action::Movement(MovementAction::Stop), 0);
let routes = |ids: &[u32]| {
possible_move_routes(game.player(0), &game, ids, entered, None)
.unwrap_or_default()
};
assert_eq!(
routes(&[id]).iter().any(|r| r.destination == peaceful),
terrain != Terrain::Mountain,
"{terrain:?}, exhausted={exhausted}, {unit_type:?}"
);
if unit_type == UnitType::Infantry {
assert_eq!(
routes(&[id]).iter().any(|r| r.destination == enemy),
terrain == Terrain::Fertile
);
}
assert!(routes(&[fresh]).iter().any(|r| r.destination == peaceful));
assert_eq!(
routes(&[id, fresh])
.iter()
.any(|r| r.destination == peaceful),
terrain != Terrain::Mountain
);
if terrain == Terrain::Mountain {
assert!(
try_execute_action(game.clone(), move_action(vec![id], peaceful), 0)
.is_err()
);
} else {
assert!(
try_execute_action(game.clone(), move_action(vec![id], peaceful), 0)
.is_ok()
);
}
if unit_type == UnitType::Infantry && terrain != Terrain::Fertile {
assert!(
try_execute_action(game.clone(), move_action(vec![id], enemy), 0).is_err()
);
}
server::player::end_turn(&mut game, 0);
assert!(game.player(0).get_unit(id).movement_restrictions.is_empty());
assert!(
possible_move_routes(game.player(0), &game, &[id], entered, None)
.unwrap()
.iter()
.any(|r| r.destination == peaceful)
);
}
}
}
}
#[test]
fn exhaustion_still_blocks_collection_and_founding() {
use server::action::try_execute_action;
use server::collect::possible_resource_collections;
use server::events::check_event_origin;
use server::game::GameState;
use server::map::Terrain;
use server::player::CostTrigger;
use server::playing_actions::PlayingAction;
for terrain in [Terrain::Forest, Terrain::Mountain, Terrain::Fertile] {
let mut game = JSON.load_game("movement");
game.state = GameState::Playing;
let city = Position::from_offset("A1");
let site = Position::from_offset("B2");
for pos in [city, site] {
game.map
.tiles
.insert(pos, Terrain::Exhausted(Box::new(terrain.clone())));
}
let options = possible_resource_collections(
&game,
city,
0,
&check_event_origin(),
CostTrigger::NoModifiers,
);
assert!(!options.choices.contains_key(&city));
assert!(!options.choices.contains_key(&site));
assert!(
try_execute_action(
game,
Action::Playing(PlayingAction::FoundCity { settler: 4 }),
0
)
.is_err()
);
}
}

View file

@ -1644,3 +1644,35 @@ is not fixed. Preserve the deployed engine bytes, revision-7 achievement catalog
(46 definitions), all artwork, gallery and unrelated metadata. Require main-branch
Check and Web viewer CI before publishing the tested viewer bundle. No live-game
moves, saved-game migration, history repair, achievement backfill or Fossil refresh.
# Viewer 0.1.228 / engine 0.4.160 — exhausted terrain movement
Exhaustion now retains underlying terrain for movement, matching the official
[rulebook](https://wizkids.com/posters/repository/wizkids/Clash-of-Cultures---Rulebook---WEB---2021-02-05-compressed.pdf),
pp.14 and 25: entered Forest prevents later army attacks that turn (not peaceful
moves); entered Mountain prevents later ordinary moves that turn. This is per
unit and cleared at turn end, not merely at the end of a Move action. Starting on
a tile does not count as entering it. Exhausted Plains also retains the Great
Gardens restriction (p.28); exhaustion changes collection/founding, not terrain.
Only movement classification unwraps Exhausted. Collection, founding and barbarian
spawn rules keep the wrapper. Huns Nomads stops on exhausted Mountains but gains
no resource. Roads paid adjacent routes and ordinary terrain warnings use the
same underlying classification. Roads rules/description text and translations
are unchanged; the viewer-227 terrain display already identifies exhaustion.
Hannibal with elephants and Maya Terracing retain their existing exceptions (the
repository implements Terracing for Maya, not a separate Inca civilization).
Battle and Navigator stops remain non-bypassable.
Native regressions reproduce the exhausted-Forest attack bug before the fix and
exercise separate Move actions, same-action identity, mixed groups, untouched
units, settlers and turn clearing. `scripts/exhausted-movement-check.mjs` runs
real WASM actions/queries for both ordinary and exhausted terrain, leaders,
Great Gardens, paid Roads, Hannibal, Terracing and Nomads. It also accepts
`CLASH_ENGINE=/absolute/path/server.js` for testing the frozen/downloaded engine.
Require green main-commit Check and Web viewer CI before publishing the frozen
matching viewer/engine; independently byte-verify all hosted files and engine.
Preserve revision-7 catalog (46 definitions), all 58 named assets, gallery and
unrelated metadata. No production moves, save migration, history repair, backfill
or Fossil refresh. The exact user game was not provided or verified.

View file

@ -1,12 +1,12 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.227",
"version": "0.1.228",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@boardgamers/clash-web-client",
"version": "0.1.227",
"version": "0.1.228",
"dependencies": {
"@boardgamers/protocol": "0.11.0",
"lucide-svelte": "^0.577.0",

View file

@ -1,13 +1,13 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.227",
"version": "0.1.228",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --host 127.0.0.1 --port 8643",
"build": "vite build",
"check": "svelte-check --tsconfig ./tsconfig.json",
"test": "node --experimental-strip-types --test src/*.test.ts && node --test scripts/publish-gallery.test.mjs && npm run test:achievement-assets && npm run test:locales",
"test": "node --experimental-strip-types --test src/*.test.ts && node --test scripts/publish-gallery.test.mjs && npm run test:achievement-assets && npm run test:locales && node scripts/exhausted-movement-check.mjs",
"test:home-orientation": "npm run build && node scripts/home-orientation-smoke.mjs",
"build:achievement-assets": "node scripts/build-achievement-assets.mjs",
"test:achievement-assets": "node --test scripts/achievement-assets.test.mjs scripts/publish-achievement-assets.test.mjs scripts/publish-achievement-backups.test.mjs",

View file

@ -13,7 +13,7 @@
"web-client/src/civilization-emblems.ts": "01b0cbf3fa77a8466532ccd73d63c1a3ddc9bbc79fc06ce7224b425322a9c9f0",
"web-client/src/civilization-flags.ts": "cd176076bfe05b3059093b80c88596b7ae46b77898695c6c7406cbe1a3a0f78b",
"server/src/content/civilizations.rs": "73602f3db506f3dc2dbc6de43d01179440fd3bb034c997ff209336faaef2a332",
"web-client/package-lock.json": "2cdcaffa337d237e0f0e281251f85ffc15d5f9bce0c12863f29ec46b1f37c719",
"web-client/package-lock.json": "07c2267bd5c9441a6d78bc4ec81e4859ea85654bc6e9d27c8e60511ef657ef7e",
"web-client/node_modules/lucide-svelte/dist/Icon.svelte": "f7b49ab842c143fa680fa8bd9a54a9efdc48c2e2d49fa574bd5ccf8f6cfca5be",
"web-client/node_modules/lucide-svelte/dist/defaultAttributes.js": "5b8981c6e3434ae6538716af9e0403554e7708c4087f18d060950a7bef00d96a",
"web-client/node_modules/lucide-svelte/LICENSE": "668dcc52803480e0a026b31140a4cae668772663cd764e5991d252eef03f98db"

View file

@ -1,6 +1,6 @@
{
"name": "@boardgamers/clash-server",
"version": "0.4.159",
"version": "0.4.160",
"description": "Clash of Cultures: Monumental edition engine for Boardgamers Space",
"license": "MIT",
"type": "commonjs",

View file

@ -0,0 +1,134 @@
// Real production WASM, isolated states only: never submit live-game moves.
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { readFile } from 'node:fs/promises';
const engine = createRequire(import.meta.url)(process.env.CLASH_ENGINE ?? '../.engine/server.js');
const template = JSON.parse(
await readFile(new URL('../../server/tests/test_games/movement/movement.json', import.meta.url)),
);
const query = (state, units = [0]) =>
JSON.parse(engine.webQuery(JSON.stringify(state), 0, JSON.stringify({ kind: 'movement', units })))
.destinations;
const move = (state, action, seat = 0) =>
JSON.parse(engine.move(JSON.stringify(state), JSON.stringify(action), seat));
const action = (destination, units = [0], payment = {}) => ({
Movement: { Move: { units, destination, payment } },
});
function fixture(terrain, exhausted, unitType = 'Infantry') {
const s = structuredClone(template);
s.state = 'Playing';
s.actions_left = 3;
s.map.tiles = [
['A1', 'Barren'],
['B1', exhausted ? { Exhausted: terrain } : terrain],
['C2', 'Barren'],
['B2', 'Barren'],
];
for (const p of s.players) {
p.cities = [];
p.units = [];
}
s.players[0].advances.push('Tactics');
s.players[0].units = [
{ id: 0, position: 'A1', unit_type: unitType },
{ id: 1, position: 'B1', unit_type: 'Infantry' },
];
s.players[1].units = [{ id: 0, position: 'B2', unit_type: 'Infantry' }];
return s;
}
for (const exhausted of [false, true]) {
for (const terrain of ['Forest', 'Mountain', 'Fertile']) {
for (const type of ['Infantry', 'Settler', { Leader: 'Caesar' }]) {
let s = fixture(terrain, exhausted, type);
assert(query(s, [1]).some((d) => d.position === 'C2'));
const entry = query(s).find((d) => d.position === 'B1');
assert(entry);
s = move(s, entry.action);
assert(!query(s).some((d) => d.position === 'C2'), 'same-action unit identity');
s = move(s, { Movement: 'Stop' });
if (terrain === 'Mountain')
assert.throws(() => engine.tryMove(JSON.stringify(s), JSON.stringify(action('C2')), 0));
else assert.doesNotThrow(() => engine.tryMove(JSON.stringify(s), JSON.stringify(action('C2')), 0));
if (type !== 'Settler' && terrain !== 'Fertile')
assert.throws(() => engine.tryMove(JSON.stringify(s), JSON.stringify(action('B2')), 0));
assert.equal(
query(s).some((d) => d.position === 'C2'),
terrain !== 'Mountain',
);
if (type !== 'Settler')
assert.equal(
query(s).some((d) => d.position === 'B2'),
terrain === 'Fertile',
);
if (terrain === 'Mountain') assert(entry.terrainNotes.some((n) => n.includes('cannot move again')));
if (terrain === 'Forest') assert(entry.terrainNotes.length);
assert(
query(s, [1]).some((d) => d.position === 'C2'),
'different units unaffected',
);
assert.equal(
query(s, [0, 1]).some((d) => d.position === 'C2'),
terrain !== 'Mountain',
);
if (terrain === 'Fertile') {
s.players[1].cities = [
{ position: 'B2', mood_state: 'Neutral', city_pieces: { wonders: ['GreatGardens'] } },
];
assert(!query(s).some((d) => d.position === 'B2'), 'exhausted Plains still protects Great Gardens');
}
s = move(s, { Playing: 'EndTurn' });
assert.deepEqual(s.players[0].units[0].movement_restrictions ?? [], []);
}
if (terrain === 'Fertile') continue;
let s = fixture(terrain, exhausted);
s.players[0].cities = [{ position: 'A1', mood_state: 'Happy' }];
s.players[0].advances.push('Roads');
const offers = query(s).filter((d) => d.position === 'B1');
assert(offers.some((d) => !Object.keys(d.payment).length));
const paid = offers.find((d) => d.payment.food === 1 && d.payment.ore === 1);
assert(paid, 'paid adjacent Roads terrain bypass remains available');
s = move(s, paid.action);
s = move(s, { Movement: 'Stop' });
assert(query(s).some((d) => d.position === 'C2'));
assert(query(s).some((d) => d.position === 'B2'));
for (const restriction of ['Battle', 'Navigator']) {
const stopped = structuredClone(s);
stopped.players[0].units[0].movement_restrictions = [restriction];
assert.equal(query(stopped).length, 0, 'Roads cannot bypass battle/navigation');
}
}
for (const type of ['Settler', { Leader: 'Pakal' }, 'Infantry']) {
let s = fixture('Mountain', exhausted, type);
s.players[0].civilization = 'Maya';
s.players[0].advances.push('Irrigation');
s.players[0].special_advances = ['Terracing'];
s = move(s, action('B1'));
s = move(s, { Movement: 'Stop' });
assert.equal(
query(s).some((d) => d.position === 'C2'),
type !== 'Infantry',
);
}
let nomad = fixture('Mountain', exhausted);
nomad.players[0].civilization = 'Huns';
nomad.players[0].advances.push('Storage');
nomad.players[0].cities = [{ position: 'A1', mood_state: 'Happy' }];
nomad.players[0].resources.ore = 0;
nomad = move(nomad, { Movement: { Move: { city: 'A1', units: [], destination: 'B1', payment: {} } } });
assert.equal(nomad.players[0].cities[0].nomad_mountain, true);
assert.equal(nomad.players[0].resources.ore ?? 0, exhausted ? 0 : 1);
nomad = move(nomad, { Movement: 'Stop' });
const cityRoutes = JSON.parse(
engine.webQuery(JSON.stringify(nomad), 0, JSON.stringify({ kind: 'movement', city: 'B1', units: [] })),
);
assert.equal(cityRoutes.destinations.length, 0);
let s = fixture('Mountain', exhausted, { Leader: 'Hannibal' });
s.players[0].civilization = 'Carthage';
s.players[0].units.push({ id: 2, position: 'A1', unit_type: 'Elephant' });
s = move(s, action('B1', [0, 2]));
s = move(s, { Movement: 'Stop' });
assert(query(s, [0, 2]).some((d) => d.position === 'C2'));
}
console.log(
'Exhausted/ordinary terrain: actual WASM moves, turn stops, identity, leaders/settlers, Great Gardens, Roads and exceptions passed',
);

View file

@ -33,11 +33,11 @@ for (const terrain of ['Forest', 'Mountain'])
g.players[0].advances.push('Roads');
assert.match(quote(g).terrainNotes.join(' '), /Roads route/);
});
test('forest settlers and exhausted mountains do not promise restrictions that will not apply', () => {
test('forest settlers remain unrestricted; exhausted mountains retain their warning', () => {
const g = fixture('Forest');
assert.match(quote(g, [5]).terrainNotes.join(' '), /No forest movement restriction/);
const exhausted = fixture({ Exhausted: 'Mountain' });
assert.deepEqual(quote(exhausted).terrainNotes, []);
assert.deepEqual(quote(exhausted).terrainNotes, quote(fixture('Mountain')).terrainNotes);
});
test('Hannibal and Terracing show their mountain exceptions before moving', () => {
const g = fixture('Mountain');