Avoid status-phase battle movement restrictions; release viewer 230 engine 162
This commit is contained in:
parent
01b99b81e1
commit
18bddbc456
9 changed files with 214 additions and 10 deletions
2
.github/workflows/web-viewer.yml
vendored
2
.github/workflows/web-viewer.yml
vendored
|
|
@ -1,7 +1,7 @@
|
|||
name: Web viewer
|
||||
on:
|
||||
pull_request:
|
||||
paths: ['web-client/**', 'server/**', 'Cargo.*', '.github/workflows/web-viewer.yml']
|
||||
paths: ['web-client/**', 'server/**', 'scripts/status-phase-battle.test.cjs', 'Cargo.*', '.github/workflows/web-viewer.yml']
|
||||
push:
|
||||
branches: [main, feat/3d-web-viewer]
|
||||
jobs:
|
||||
|
|
|
|||
26
docs/status-phase-battle.md
Normal file
26
docs/status-phase-battle.md
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Status-phase battle restrictions — viewer 0.1.230 / engine 0.4.162
|
||||
|
||||
Defenders receive the battle movement restriction only during their own regular
|
||||
turn, not during a status-phase incident. The enclosing status-phase event is
|
||||
checked across the nested event stack: the retained current-player index alone
|
||||
cannot identify a regular turn while combat resolves.
|
||||
|
||||
The rules distinguish the same-turn battle restriction (page 14) from the
|
||||
status-phase free advance and its possible event (page 18). Regular-turn incident
|
||||
defenders still remain restricted for the rest of that turn; unrelated groups
|
||||
can move normally.
|
||||
|
||||
Two synthetic native regressions cover a Free Advance → Famine → barbarian battle
|
||||
and the corresponding paid-advance incident. The former finishes the status
|
||||
phase and moves the survivor next age; the latter checks that fighters remain
|
||||
blocked across actions while another group moves freely. Two serialized WASM
|
||||
regressions run in `web-client`'s `npm test` (and therefore Web viewer CI).
|
||||
They can also run against an extracted release package:
|
||||
|
||||
```sh
|
||||
CLASH_WASM=/absolute/path/package/server.js node --test scripts/status-phase-battle.test.cjs
|
||||
```
|
||||
|
||||
No save migration, historical repair, turn-start cleanup, live-game writes or
|
||||
achievement changes are included. Catalog revision 8 (46 definitions), artwork
|
||||
revision 4 and all 60 named assets are preserved.
|
||||
48
scripts/status-phase-battle.test.cjs
Normal file
48
scripts/status-phase-battle.test.cjs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// Build the Node WASM package first; optionally point CLASH_WASM at a local build.
|
||||
// Run: CLASH_WASM=/tmp/clash-status-wasm/server.js node --test scripts/status-phase-battle.test.cjs
|
||||
const assert = require('node:assert/strict');
|
||||
const { test } = require('node:test');
|
||||
const { readFileSync } = require('node:fs');
|
||||
const { resolve } = require('node:path');
|
||||
const engine = require(process.env.CLASH_WASM || '../server/pkg/server.js');
|
||||
|
||||
function fixture() {
|
||||
const game = JSON.parse(readFileSync(resolve(__dirname,
|
||||
'../server/tests/test_games/incidents/barbarians_attack.json')));
|
||||
game.incidents_left = [3]; // Famine, including barbarian movement.
|
||||
game.players[0].units.forEach(unit => { unit.unit_type = 'Infantry'; });
|
||||
game.dice_roll_outcomes = Array(40).fill(10);
|
||||
return game;
|
||||
}
|
||||
|
||||
// Each call crosses the actual serialized production WASM API boundary.
|
||||
function move(game, action, player) {
|
||||
return JSON.parse(engine.move(JSON.stringify(game), JSON.stringify(action), player));
|
||||
}
|
||||
|
||||
const hasBattle = unit => (unit.movement_restrictions || []).includes('Battle');
|
||||
const infantryMove = { Movement: { Move: { units: [7], destination: 'B1', payment: {} } } };
|
||||
|
||||
test('status-phase Famine defense allows movement next age', () => {
|
||||
let game = move(fixture(), { Response: { SelectAdvance: 'Storage' } }, 0);
|
||||
assert.equal(game.players[0].units.length, 1);
|
||||
assert.equal(hasBattle(game.players[0].units[0]), false);
|
||||
game = move(game, { Response: { SelectAdvance: 'Storage' } }, 1);
|
||||
game = move(game, { Response: { SelectPositions: [] } }, 0);
|
||||
game = move(game, { Response: { SelectPositions: [] } }, 1);
|
||||
game = move(game, { Response: { SelectPlayer: 0 } }, 0);
|
||||
assert.equal(game.age, 2);
|
||||
game = move(game, infantryMove, 0);
|
||||
assert.equal(game.players[0].units[0].position, 'B1');
|
||||
});
|
||||
|
||||
test('paid-advance Famine defense still stops the fighters for this turn', () => {
|
||||
let game = fixture();
|
||||
game.events = [];
|
||||
game = move(game, { Playing: { Advance: { advance: 'Storage', payment: { ideas: 2 } } } }, 0);
|
||||
assert.equal(hasBattle(game.players[0].units[0]), true);
|
||||
assert.throws(
|
||||
() => engine.tryMove(JSON.stringify(game), JSON.stringify(infantryMove), 0),
|
||||
error => /battle movement restriction/.test(String(error)),
|
||||
);
|
||||
});
|
||||
|
|
@ -487,11 +487,16 @@ fn end_combat_and_store_stats(game: &mut Game, e: CombatEnd) {
|
|||
}
|
||||
|
||||
fn restrict_defenders_after_battle(game: &mut Game, s: &CombatStats) {
|
||||
// An event can make the turn owner defend. Battle restrictions expire at
|
||||
// the owner's turn end, so out-of-turn defenders must not receive them.
|
||||
// An incident can make the turn owner defend, but status-phase incidents
|
||||
// are not part of that player's turn. current_player_index still points at
|
||||
// the last turn owner then; inspect the enclosing event, not GameState or
|
||||
// just the top (combat) event. Otherwise these flags survive into next age.
|
||||
// Do this before combat-end rewards: newly gained units did not fight.
|
||||
let defender = s.defender.player;
|
||||
if defender == game.current_player_index && game.player(defender).is_human() {
|
||||
if defender == game.current_player_index
|
||||
&& game.player(defender).is_human()
|
||||
&& crate::status_phase::get_status_phase(game).is_none()
|
||||
{
|
||||
let longships = game
|
||||
.player(defender)
|
||||
.has_special_advance(SpecialAdvance::Longships);
|
||||
|
|
|
|||
|
|
@ -858,3 +858,128 @@ fn splendid_year_17_grants_three_food_to_active_player() {
|
|||
assert_eq!(game.player(0).resources.food, before + 3);
|
||||
assert_eq!(game.player(1).resources.food, other);
|
||||
}
|
||||
|
||||
// Synthetic fixture only: no production history or player information.
|
||||
fn famine_defense_game() -> server::game::Game {
|
||||
let mut game = JSON.load_game("barbarians_attack");
|
||||
game.incidents_left = vec![3]; // Famine: barbarian movement.
|
||||
for unit in &mut game.player_mut(0).units {
|
||||
unit.unit_type = UnitType::Infantry;
|
||||
}
|
||||
// Barbarian attack on C2 leaves one surviving infantry (id 7).
|
||||
game.dice_roll_outcomes = vec![10; 40];
|
||||
game
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status_phase_barbarian_defense_does_not_restrict_next_turn() {
|
||||
use server::game_api::execute;
|
||||
use server::movement::MovementRestriction;
|
||||
let game = execute(
|
||||
famine_defense_game(),
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Storage)),
|
||||
0,
|
||||
);
|
||||
assert_eq!(game.current_player_index, 0);
|
||||
assert!(server::status_phase::get_status_phase(&game).is_some());
|
||||
assert_eq!(game.player(0).units.len(), 1);
|
||||
assert!(
|
||||
!game
|
||||
.player(0)
|
||||
.get_unit(7)
|
||||
.movement_restrictions
|
||||
.contains(&MovementRestriction::Battle)
|
||||
);
|
||||
|
||||
// Finish the actual status phase and start next age, without manual cleanup.
|
||||
let game = execute(
|
||||
game,
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Storage)),
|
||||
1,
|
||||
);
|
||||
let game = execute(
|
||||
game,
|
||||
Action::Response(EventResponse::SelectPositions(vec![])),
|
||||
0,
|
||||
);
|
||||
let game = execute(
|
||||
game,
|
||||
Action::Response(EventResponse::SelectPositions(vec![])),
|
||||
1,
|
||||
);
|
||||
let game = execute(game, Action::Response(EventResponse::SelectPlayer(0)), 0);
|
||||
assert_eq!(game.age, 2);
|
||||
assert!(game.events.is_empty());
|
||||
let destination = server::movement::possible_move_routes(
|
||||
game.player(0),
|
||||
&game,
|
||||
&[7],
|
||||
Position::from_offset("C2"),
|
||||
None,
|
||||
)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.find(|r| game.enemy_player(0, r.destination).is_none())
|
||||
.unwrap()
|
||||
.destination;
|
||||
let game = execute(game, move_action(vec![7], destination), 0);
|
||||
assert_eq!(game.player(0).get_unit(7).position, destination);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn regular_turn_barbarian_defenders_remain_restricted_across_actions() {
|
||||
use server::game_api::execute;
|
||||
use server::movement::{MovementAction, MovementRestriction};
|
||||
let mut game = famine_defense_game();
|
||||
// The same incident now originates in a paid advance during a player turn.
|
||||
game.events.clear();
|
||||
let mut separate = game.player(0).get_unit(7).clone();
|
||||
separate.id = 8;
|
||||
separate.position = Position::from_offset("A1");
|
||||
game.player_mut(0).units.push(separate);
|
||||
game.player_mut(0).next_unit_id = 9;
|
||||
let game = execute(
|
||||
game,
|
||||
advance_action(Advance::Storage, ResourcePile::ideas(2)),
|
||||
0,
|
||||
);
|
||||
assert!(game.events.is_empty());
|
||||
assert!(
|
||||
game.player(0)
|
||||
.get_unit(7)
|
||||
.movement_restrictions
|
||||
.contains(&MovementRestriction::Battle)
|
||||
);
|
||||
assert!(game.player(0).get_unit(8).movement_restrictions.is_empty());
|
||||
let destination = server::movement::possible_move_routes(
|
||||
game.player(0),
|
||||
&game,
|
||||
&[8],
|
||||
Position::from_offset("A1"),
|
||||
None,
|
||||
)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.find(|r| game.enemy_player(0, r.destination).is_none())
|
||||
.unwrap()
|
||||
.destination;
|
||||
let game = execute(game, move_action(vec![8], destination), 0);
|
||||
let game = execute(game, Action::Movement(MovementAction::Stop), 0);
|
||||
assert!(
|
||||
game.player(0)
|
||||
.get_unit(7)
|
||||
.movement_restrictions
|
||||
.contains(&MovementRestriction::Battle)
|
||||
);
|
||||
assert!(
|
||||
server::movement::possible_move_routes(
|
||||
game.player(0),
|
||||
&game,
|
||||
&[7],
|
||||
Position::from_offset("C2"),
|
||||
None,
|
||||
)
|
||||
.unwrap_or_default()
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
|
|
|
|||
4
web-client/package-lock.json
generated
4
web-client/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.229",
|
||||
"version": "0.1.230",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.229",
|
||||
"version": "0.1.230",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.11.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.229",
|
||||
"version": "0.1.230",
|
||||
"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 && node scripts/exhausted-movement-check.mjs",
|
||||
"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 && CLASH_WASM=\"$PWD/.engine/server.js\" node --test ../scripts/status-phase-battle.test.cjs",
|
||||
"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",
|
||||
|
|
|
|||
|
|
@ -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": "1b5ec545c3405e98d3526979a07316534b43e8ef7946e25cacfab6026c832f0b",
|
||||
"web-client/package-lock.json": "6d78d2f12bbd8bda1d1ad2854ae359a2bd07d4a95efadd0287759c707ba5af47",
|
||||
"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"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-server",
|
||||
"version": "0.4.161",
|
||||
"version": "0.4.162",
|
||||
"description": "Clash of Cultures: Monumental edition engine for Boardgamers Space",
|
||||
"license": "MIT",
|
||||
"type": "commonjs",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue