Hide redundant one-step Roads payment options

This commit is contained in:
coyotte508 2026-11-04 13:55:14 +00:00
commit 09ce6fc578
6 changed files with 95 additions and 4 deletions

View file

@ -258,7 +258,26 @@ pub fn movement(game: &Game, seat: usize, units: Vec<u32>) -> Result<Value, Stri
);
let mut destinations = vec![];
for carrier in carriers {
for route in possible_move_routes(p, game, &units, start, carrier).unwrap_or_default() {
let routes = possible_move_routes(p, game, &units, start, carrier).unwrap_or_default();
for route in &routes {
// A paid one-step Roads route is redundant when ordinary movement
// reaches the same hex and no terrain stop needs bypassing. Keep
// Roads for Mountains/Forests and for routes only Roads makes legal.
// Combat always imposes its own stop, even on a Mountain or Forest.
if route.ignore_terrain_movement_restrictions
&& start.is_neighbor(route.destination)
&& (game.enemy_player(seat, route.destination).is_some()
|| !matches!(
game.map.get(route.destination),
Some(Terrain::Mountain | Terrain::Forest)
))
&& routes.iter().any(|ordinary| {
ordinary.destination == route.destination
&& !ordinary.ignore_terrain_movement_restrictions
})
{
continue;
}
let payments =
super::decisions::payment_choices(&route.cost, &p.resources, false, false)
.unwrap_or_else(|| {

View file

@ -865,6 +865,17 @@ waste remains possible only when all eligible opponents are full. The active
player and NPC Barbarians/Pirates do not count as recipients. Fixed rewards for
all players are unchanged.
## Viewer 0.1.198 / engine 0.4.133: avoid redundant one-step Roads payments
The movement preview omits a paid Roads route when a legal ordinary route
reaches the same adjacent hex without a useful terrain benefit. This includes
one-step attacks, where battle stops movement regardless of the terrain, and
non-Mountain/non-Forest destinations. One-step Roads still appears when it alone
makes the move legal (for example, bypassing an existing Mountain restriction),
or when entering a Mountain or Forest without combat can avoid that terrain's
future movement restriction. Two-space Roads routes, alternative payment
methods, and the server's validation of saved actions are unchanged.
## Viewer 0.1.197 / engine 0.4.132: benefit-aware cultural-influence sources
Reselecting the same influence destination—through the map or its building

View file

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

View file

@ -1,6 +1,6 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.197",
"version": "0.1.198",
"private": true,
"type": "module",
"scripts": {

View file

@ -2729,6 +2729,27 @@ test('triggered event rules appear live and replay pauses on their historical fr
} finally {app.close();}
});
test('adjacent battle with Roads chooses the free route without a payment picker', async () => {
const app = paymentController(), c = app.controller;
try {
const g = JSON.parse(fixture('movement/movement'));
g.current_player_index = 0;
g.players[0].advances.push('Tactics', 'Roads');
g.players[0].resources = { food: 7, ore: 7, gold: 7 };
c.setPlayer(0);
await c.load(engine.stripSecret(JSON.stringify(g), 0));
c.openUnits([0]);
const offers = app.session().moveDestinations.filter(d => d.position === 'C1');
assert.equal(offers.length, 1, 'no paid Roads routes for a one-step battle');
assert.deepEqual(offers[0].payment, {});
c.chooseMoveDestination('C1');
assert.equal(app.session().moveDestination, app.session().moveDestinations.indexOf(offers[0]), 'the only route is selected immediately');
assert.deepEqual(app.sent, [], 'the battle still needs its normal preview');
c.chooseMoveDestination('C1');
assert.deepEqual(app.sent.map(a => JSON.parse(a)), [offers[0].action]);
} finally { app.close(); }
});
test('Roads offers food/gold choices before an attack and submits the selected payment', async () => {
const app = paymentController(), c = app.controller;
try {

View file

@ -162,6 +162,46 @@ test('paid Roads ignore both crossed and destination terrain, then allow a new M
}
});
test('one-step Roads choices appear only when they change the outcome', () => {
const g = fixture('Barren');
g.players[1].units = [{ id: 0, position: 'C1', unit_type: 'Infantry' }];
g.players[0].advances.push('Roads');
g.players[0].resources = { food: 7, ore: 7, gold: 7 };
const choices = (target: string) => JSON.parse(engine.webQuery(
engine.stripSecret(JSON.stringify(g), 0), 0,
JSON.stringify({ kind: 'movement', units: [0] }),
)).destinations.filter((d: any) => d.position === target);
const free = (d: any) => !Object.values(d.payment).some(Boolean);
const paid = (d: any) => d.payment.food === 1 && d.payment.ore === 1;
assert.equal(choices('C1').length, 1, 'an adjacent battle has only the ordinary route');
assert(choices('C1')[0].attack && free(choices('C1')[0]));
g.map.tiles.find((t: any) => t[0] === 'C1')[1] = 'Mountain';
assert.equal(choices('C1').length, 1, 'battle still stops movement on a Mountain');
assert(free(choices('C1')[0]));
g.map.tiles.find((t: any) => t[0] === 'C1')[1] = 'Forest';
assert.equal(choices('C1').length, 1, 'battle still stops movement in a Forest');
assert(free(choices('C1')[0]));
g.players[1].units = [];
g.map.tiles.find((t: any) => t[0] === 'B2')[1] = 'Fertile';
assert.equal(choices('B2').length, 1, 'an adjacent ordinary tile needs no Roads payment');
assert(free(choices('B2')[0]));
g.map.tiles.find((t: any) => t[0] === 'B2')[1] = 'Forest';
assert(choices('B2').some(free) && choices('B2').some(paid), 'Roads still avoids a Forest attack restriction');
assert(choices('B1').some(free) && choices('B1').some(paid), 'Roads still avoids a Mountain stop');
assert(choices('A1').some(paid) && !choices('A1').some(free), 'a two-space Roads move remains available');
// When Mountain restrictions make ordinary movement illegal, an adjacent
// Roads route is still the only available choice, even to an ordinary hex.
g.players[0].units[0].movement_restrictions = ['Mountain'];
assert(choices('B2').some(paid));
g.map.tiles.find((t: any) => t[0] === 'B2')[1] = 'Fertile';
assert(choices('B2').some(paid) && !choices('B2').some(free));
g.players[1].units = [{ id: 0, position: 'C1', unit_type: 'Infantry' }];
assert(choices('C1').some(paid) && !choices('C1').some(free), 'Roads may still make a one-step attack legal');
});
test('one-space Roads entry into a mountain city permits regrouping in a new Move action', () => {
const g = fixture('Mountain');
g.actions_left = 3;