Scope Mercenaries payment recommendations; prepare viewer 0.1.236 and engine 0.4.167

This commit is contained in:
coyotte508 2026-11-22 18:26:50 +00:00
commit 7101b6d6dc
12 changed files with 374 additions and 35 deletions

View file

@ -28,7 +28,7 @@ jobs:
working-directory: web-client
- run: npm run test:boarding && node scripts/embark-smoke.mjs && node scripts/ship-landing-smoke.mjs
working-directory: web-client
- run: node scripts/horse-master-smoke.mjs
- run: node scripts/horse-master-smoke.mjs && node scripts/carthage-recruit-smoke.mjs && node scripts/payment-defaults-smoke.mjs && node scripts/wonder-payment-perf.mjs
working-directory: web-client
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:

View file

@ -0,0 +1,53 @@
# Mercenaries payment recommendations
This is a product preference, not a rules change. Eligible Carthaginian
Mercenaries recruitment costs carry an explicit `Mercenaries` recommendation
policy. Other payments retain their existing gold-first recommendation.
Missing metadata deserializes as the native policy, and native metadata is
omitted from serialization.
The scoped policy minimizes affordable total units paid (including mood,
culture and captives), then gold, then uses the existing deterministic native
search order. The regular printed cost stays `default`: it still defines the
same legality and mandatory Warbeasts replacement. Manual regular payments
remain valid. The picker uses the same ordering, without moving empty/decline
slots or changing rewards.
For Elephant + Ship without Market, competing food/wood/gold stock now chooses
1 food + 2 gold over 1 food + 1 gold + 2 wood. With mood available it prefers
1 food + 1 gold + 1 mood. Ship alone prefers 1 gold over 2 wood. Civil Liberties
makes Draft cost two items, so a rich Ship payment keeps native 2 wood rather
than gratuitously spending two tokens.
Native conversion-order ties are deliberately not an additional token-conservation
objective: with abundant culture the current search can choose 2 culture +
1 mood rather than 1 food + 1 culture + 1 mood. Both have three items and zero
gold. This preserves native deterministic conversion traversal rather than
introducing a global (or hidden third) resource preference.
Recommendation uses binary feasibility searches for quantity and gold, with
quantity passed through alternative and separate-fee branches into the existing
conversion bounds. No payment enumeration cap is used to find the recommendation.
The scoped gold search starts at zero, since Warbeasts' printed gold can legally
be replaced with culture; the generic printed-gold floor is unchanged.
Web selected-payment queries, action payloads, per-unit previews and the legacy
payment UI already consume the shared engine helper. No UI-only override or new
interaction is needed. Tests use synthetic/local states only; no game backfill.
## Release 0.1.236 / engine 0.4.167
Publish the matching bridge and engine together, after the exact source commit's
Check and Web viewer workflows pass. The Web viewer workflow includes the
Carthage recruitment, native research/manual-gold, and wonder-payment performance
regressions. Native tests include the small-input exhaustive conversion oracle,
separate-fee quantity budgeting, legacy metadata defaults and omitted native
serialization. The WASM suite verifies quantity/gold ordering and still executes
all legal offered payments, including an explicitly selected regular Ship cost.
Desktop (1400px) and mobile (390px) checks cover automatic discounted recruitment,
manual regular recruitment, and the disclosed abundant-token tie. Other research
recommendations and manual gold choices remain unchanged. No achievement catalog,
artwork, gallery, preferences, settings or Standard-option changes are included;
the artwork source manifest's lockfile pin changes only for the viewer version.

View file

@ -236,6 +236,7 @@ fn mercenaries() -> SpecialAdvanceInfo {
alternative += ResourcePile::mood_tokens(draft - gold) + ResourcePile::gold(gold);
if !cost.cost.alternatives.contains(&alternative) {
cost.cost.alternatives.push(alternative);
cost.cost.recommendation = crate::payment::PaymentRecommendation::Mercenaries;
}
}
}

View file

@ -72,8 +72,25 @@ impl PaymentConversion {
}
}
/// Recommendation policy only; never changes printed costs or legal payments.
#[derive(Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Debug, Hash)]
pub enum PaymentRecommendation {
#[default]
Native,
Mercenaries,
}
impl PaymentRecommendation {
#[allow(clippy::trivially_copy_pass_by_ref)] // serde's skip predicate takes a reference
fn is_native(&self) -> bool {
*self == Self::Native
}
}
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, Hash)]
pub struct PaymentOptions {
#[serde(default, skip_serializing_if = "PaymentRecommendation::is_native")]
pub recommendation: PaymentRecommendation,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub alternatives: Vec<ResourcePile>,
pub default: ResourcePile,
@ -100,6 +117,7 @@ impl PaymentOptions {
origin: EventOrigin,
) -> Self {
PaymentOptions {
recommendation: PaymentRecommendation::Native,
alternatives: Vec::new(),
default,
separate_fee: Vec::new(),
@ -112,17 +130,37 @@ impl PaymentOptions {
#[must_use]
pub fn first_valid_payment(&self, available: &ResourcePile) -> Option<ResourcePile> {
let mut payment = self.find_payment(available, false)?;
let scoped = self.recommendation == PaymentRecommendation::Mercenaries;
let mut budget = u16::MAX;
if scoped {
let mut lower = 0;
let mut upper = payment_amounts(&payment)[8];
while lower < upper {
let mid = lower + (upper - lower) / 2;
if let Some(candidate) = self.find_payment_bounded(available, false, mid) {
upper = payment_amounts(&candidate)[8];
payment = candidate;
} else {
lower = mid + 1;
}
}
budget = upper;
}
// The conversion search proves legality, but its first route may mix in
// gold even when more of the ordinary resources are available (research
// can take one food, then one gold, before trying two food). Recommend
// conserving wildcard gold without changing that search's exact-payment
// semantics or enumerating every possible payment. Keep printed gold.
let mut lower = self.default.gold.min(payment.gold);
let mut lower = if scoped {
0
} else {
self.default.gold.min(payment.gold)
};
let mut upper = payment.gold;
let mut limited = available.clone();
while lower < upper {
limited.gold = lower + (upper - lower) / 2;
if let Some(candidate) = self.find_payment(&limited, false) {
if let Some(candidate) = self.find_payment_bounded(&limited, false, budget) {
upper = candidate.gold;
payment = candidate;
} else {
@ -133,7 +171,8 @@ impl PaymentOptions {
}
/// Order already-enumerated paid choices without changing their membership.
/// Conserve gold, then prefer the engine's native recommendation; keep other
/// Apply the scoped quantity policy if present, conserve gold, then prefer
/// the engine's native recommendation; keep other
/// ties stable. Empty choices (including optional declines) stay in place.
/// Callers presenting rewards must retain their original enumeration order.
pub fn order_paid_choices(&self, choices: &mut [ResourcePile], available: &ResourcePile) {
@ -143,13 +182,32 @@ impl PaymentOptions {
.filter(|p| !p.is_empty())
.cloned()
.collect::<Vec<_>>();
paid.sort_by_key(|payment| (payment.gold, Some(payment) != recommended.as_ref()));
paid.sort_by_key(|payment| {
(
if self.recommendation == PaymentRecommendation::Mercenaries {
payment_amounts(payment)[8]
} else {
0
},
payment.gold,
Some(payment) != recommended.as_ref(),
)
});
for (choice, payment) in choices.iter_mut().filter(|p| !p.is_empty()).zip(paid) {
*choice = payment;
}
}
fn find_payment(&self, available: &ResourcePile, exact: bool) -> Option<ResourcePile> {
self.find_payment_bounded(available, exact, u16::MAX)
}
fn find_payment_bounded(
&self,
available: &ResourcePile,
exact: bool,
budget: u16,
) -> Option<ResourcePile> {
if let Some(default_fee) = self.separate_fee.first() {
let mut remainder = self.clone();
remainder.default -= default_fee.clone();
@ -164,7 +222,11 @@ impl PaymentOptions {
let mut remaining = available.clone();
remaining -= fee.clone();
remainder
.find_payment(&remaining, exact)
.find_payment_bounded(
&remaining,
exact,
budget.checked_sub(payment_amounts(fee)[8])?,
)
.map(|payment| payment + fee.clone())
});
}
@ -175,7 +237,7 @@ impl PaymentOptions {
.chain(self.alternatives.iter())
.find_map(|cost| {
option.default = cost.clone();
option.find_payment(available, exact)
option.find_payment_bounded(available, exact, budget)
});
}
let discount_left = self
@ -193,7 +255,8 @@ impl PaymentOptions {
}
})
.sum::<u8>();
if discount_left == 0
if payment_amounts(&self.default)[8] <= budget
&& discount_left == 0
&& if exact {
available == &self.default
} else {
@ -213,7 +276,7 @@ impl PaymentOptions {
.iter()
.permutations(self.conversions.len())
.find_map(|conversions| {
find_conversion(
find_conversion_bounded(
available,
&self.default,
&conversions,
@ -221,6 +284,7 @@ impl PaymentOptions {
discount_left,
may_overpay,
exact,
budget,
)
})
}
@ -570,6 +634,29 @@ fn find_conversion(
discount_left: u8,
may_overpay: bool,
exact: bool,
) -> Option<ResourcePile> {
find_conversion_bounded(
available,
current,
conversions,
skip_from,
discount_left,
may_overpay,
exact,
u16::MAX,
)
}
#[allow(clippy::too_many_arguments)]
fn find_conversion_bounded(
available: &ResourcePile,
current: &ResourcePile,
conversions: &[&PaymentConversion],
skip_from: usize,
discount_left: u8,
may_overpay: bool,
exact: bool,
budget: u16,
) -> Option<ResourcePile> {
// Flatten in exactly the old traversal order. Bounds for each suffix are
// built once, instead of rescanning conversions at every search node.
@ -600,9 +687,11 @@ fn find_conversion(
}
step.bounds = bounds;
}
let mut available_amounts = payment_amounts(available);
available_amounts[8] = available_amounts[8].min(budget);
find_payment_steps(
available,
&payment_amounts(available),
&available_amounts,
current,
&steps,
discount_left,
@ -620,11 +709,13 @@ fn find_payment_steps(
may_overpay: bool,
exact: bool,
) -> Option<ResourcePile> {
if (if exact {
available == current
} else {
available.has_at_least(current)
}) && (discount_left == 0 || may_overpay)
if payment_amounts(current)[8] <= available_amounts[8]
&& (if exact {
available == current
} else {
available.has_at_least(current)
})
&& (discount_left == 0 || may_overpay)
{
return Some(current.clone());
}
@ -705,6 +796,46 @@ pub(crate) fn base_resources() -> Vec<ResourcePile> {
#[cfg(test)]
mod tests {
#[test]
fn scoped_quantity_budget_covers_conversions_and_separate_fees() {
let mut cost = PaymentOptions::fixed_resources(
ResourcePile::food(4) + ResourcePile::mood_tokens(1),
check_event_origin(),
);
cost.recommendation = PaymentRecommendation::Mercenaries;
cost.separate_fee = vec![
ResourcePile::mood_tokens(1),
ResourcePile::culture_tokens(1),
];
cost.conversions.push(PaymentConversion::limited(
ResourcePile::food(2),
ResourcePile::gold(1),
2,
));
let stock = ResourcePile::food(4) + ResourcePile::gold(4) + ResourcePile::culture_tokens(1);
assert_eq!(
cost.first_valid_payment(&stock),
Some(ResourcePile::gold(2) + ResourcePile::culture_tokens(1))
);
assert!(cost.is_valid_payment(&(ResourcePile::food(4) + ResourcePile::culture_tokens(1))));
// The recommendation is not derived from a bounded enumerated choice list.
// Exhaust the small exact-payment space independently and compare its optimum.
let mut optimum = None;
for food in 0..=4 {
for gold in 0..=4 {
let payment = ResourcePile::food(food)
+ ResourcePile::gold(gold)
+ ResourcePile::culture_tokens(1);
if cost.is_valid_payment(&payment) {
let key = (payment_amounts(&payment)[8], gold);
optimum = Some(optimum.map_or(key, |old| std::cmp::min(old, key)));
}
}
}
let chosen = cost.first_valid_payment(&stock).unwrap();
assert_eq!(optimum, Some((payment_amounts(&chosen)[8], chosen.gold)));
}
#[test]
fn paid_choice_order_preserves_empty_slots_and_native_research_preference() {
let cost = payment_options_sum(

View file

@ -19,6 +19,18 @@ fn cost(
market: bool,
liberties: bool,
leader: bool,
) -> PaymentOptions {
cost_without_advances(elephants, ships, infantry, market, liberties, leader, &[])
}
fn cost_without_advances(
elephants: u8,
ships: u8,
infantry: u8,
market: bool,
liberties: bool,
leader: bool,
omitted: &[&str],
) -> PaymentOptions {
let mut data: serde_json::Value = serde_json::from_str(include_str!(
"test_games/civilizations/greece/sparta_draft.json"
@ -39,6 +51,10 @@ fn cost(
if market {
p["cities"][0]["city_pieces"]["market"] = 0.into();
}
p["advances"]
.as_array_mut()
.unwrap()
.retain(|advance| !omitted.contains(&advance.as_str().unwrap()));
let data: GameData = serde_json::from_value(data).unwrap();
let cache = Cache::new(&data.options);
let game = Game::from_data(data, cache, GameContext::Play);
@ -147,14 +163,14 @@ fn warbeasts_keeps_civil_liberties_mixed_tokens_and_reserved_leader_mood() {
}
#[test]
fn ship_only_regular_default_and_elephant_only_remain_unchanged() {
fn ship_recommends_discount_but_regular_default_and_elephant_only_remain_unchanged() {
let ship = cost(0, 1, 0, false, false, false);
assert_eq!(ship.default, R::wood(2));
legal(&ship, R::gold(1));
legal(&ship, R::mood_tokens(1));
assert_eq!(
ship.first_valid_payment(&(R::wood(2) + R::gold(2))),
Some(R::wood(2))
Some(R::gold(1))
);
let elephant = cost(1, 0, 0, false, false, false);
assert_eq!(elephant.default, R::food(1) + R::gold(1));
@ -162,3 +178,114 @@ fn ship_only_regular_default_and_elephant_only_remain_unchanged() {
legal(&elephant, R::food(1) + R::culture_tokens(1));
assert!(!elephant.is_valid_payment(&R::food(2)));
}
#[test]
fn rich_stocks_recommend_fewer_items_then_gold_then_native_order() {
for market in [false, true] {
let cost = cost(1, 1, 0, market, false, false);
let regular = cost.default.clone();
for (stock, expected) in [
(
R::food(3) + R::wood(2) + R::gold(3),
if market {
R::food(2) + R::gold(1)
} else {
R::food(1) + R::gold(2)
},
),
(
R::food(3) + R::wood(2) + R::gold(3) + R::mood_tokens(2),
if market {
R::food(2) + R::mood_tokens(1)
} else {
R::food(1) + R::gold(1) + R::mood_tokens(1)
},
),
(
R::food(3) + R::wood(2) + R::gold(3) + R::mood_tokens(2) + R::culture_tokens(2),
if market {
R::food(2) + R::mood_tokens(1)
} else {
R::culture_tokens(2) + R::mood_tokens(1)
},
),
] {
assert_eq!(cost.first_valid_payment(&stock), Some(expected.clone()));
assert!(cost.is_valid_payment(&expected));
assert!(
cost.is_valid_payment(&regular),
"manual regular remains legal"
);
assert_eq!(cost.default, regular);
let mut choices = vec![R::empty(), regular.clone(), expected.clone(), R::empty()];
cost.order_paid_choices(&mut choices, &stock);
assert_eq!(
choices,
vec![R::empty(), expected, regular.clone(), R::empty()]
);
let once = choices.clone();
cost.order_paid_choices(&mut choices, &stock);
assert_eq!(choices, once);
}
}
}
#[test]
fn liberties_equal_quantity_keeps_native_resources_and_leader_mood_reserved() {
let ship = cost(0, 1, 0, false, true, false);
let stock = R::wood(2) + R::gold(3) + R::mood_tokens(3) + R::culture_tokens(3);
assert_eq!(ship.first_valid_payment(&stock), Some(R::wood(2)));
let with_leader = cost(1, 1, 0, false, false, true);
let stock = R::food(2) + R::wood(2) + R::gold(4) + R::mood_tokens(3) + R::culture_tokens(3);
let chosen = with_leader.first_valid_payment(&stock).unwrap();
assert!(with_leader.is_valid_payment(&chosen));
assert_eq!(chosen, R::culture_tokens(3) + R::mood_tokens(2));
assert_eq!(ship.first_valid_payment(&R::wood(2)), Some(R::wood(2)));
assert_eq!(ship.first_valid_payment(&R::food(1)), None);
}
#[test]
fn recommendation_metadata_round_trips_and_legacy_defaults_to_native() {
use server::payment::PaymentRecommendation;
let scoped = cost(0, 1, 0, false, false, false);
assert_eq!(scoped.recommendation, PaymentRecommendation::Mercenaries);
let mut json = serde_json::to_value(&scoped).unwrap();
assert_eq!(
serde_json::from_value::<PaymentOptions>(json.clone()).unwrap(),
scoped
);
json.as_object_mut().unwrap().remove("recommendation");
let legacy: PaymentOptions = serde_json::from_value(json).unwrap();
assert_eq!(legacy.recommendation, PaymentRecommendation::Native);
assert!(
serde_json::to_value(&legacy)
.unwrap()
.get("recommendation")
.is_none()
);
assert_eq!(
legacy.first_valid_payment(&(R::wood(2) + R::gold(2))),
Some(R::wood(2))
);
assert_eq!(
cost(1, 0, 0, false, false, false).recommendation,
PaymentRecommendation::Native
);
}
#[test]
fn absent_mercenaries_keeps_regular_ship_and_tactics_does_not_change_draft_pricing() {
use server::payment::PaymentRecommendation;
let ship = cost_without_advances(0, 1, 0, false, false, false, &["Draft"]);
assert_eq!(ship.recommendation, PaymentRecommendation::Native);
assert_eq!(
ship.first_valid_payment(&(R::wood(2) + R::gold(3))),
Some(R::wood(2))
);
let infantry = cost_without_advances(0, 0, 1, false, false, false, &["Tactics"]);
assert_eq!(infantry, cost(0, 0, 1, false, false, false));
assert_eq!(
infantry.first_valid_payment(&(R::food(1) + R::ore(1) + R::gold(2))),
Some(R::gold(1))
);
}

View file

@ -1776,3 +1776,14 @@ adopt finalized timing only for new battles. See `docs/combat-round-finalization
for the listener audit and regression coverage. Publish matching viewer and engine
only after the source push and green CI. Achievement catalog 8 / 46 entries,
nonfaction art revision 4 and the 60 registered assets are unchanged.
# Viewer 0.1.236 / engine 0.4.167 — Mercenaries payment recommendations
Eligible Carthaginian Mercenaries recruitment recommends the fewest total items,
then least gold, then native deterministic conversion order. Printed costs and
manual legal payments remain unchanged; all other payments retain native policy.
Old costs without recommendation metadata default to Native. Abundant-token ties
can recommend 2 culture + 1 mood; no extra token-conservation policy is introduced.
See `docs/mercenaries-payment-recommendation.md`. Publish matching viewer and engine
only after both exact-commit Check and Web viewer workflows succeed. No saved-game
migration, backfill, or live-game writes are required. Catalog and art are unchanged.

View file

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

View file

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

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": "3a429d2fbd77daee7ce454ffc9d57f969cb21177a7c48404f6dd252ceb7e732e",
"web-client/package-lock.json": "fc9a2cf3b38935a23842fc66c3e29f17700436258ed9a7e6bfbfa3b837ddfa31",
"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.166",
"version": "0.4.167",
"description": "Clash of Cultures: Monumental edition engine for Boardgamers Space",
"license": "MIT",
"type": "commonjs",

View file

@ -15,19 +15,29 @@ for (const tile of initial.map.tiles) tile[1] = tile[0] === 'D2' ? 'Fertile' : '
const browser = await chromium.launch({ headless: true, args: ['--use-gl=angle', '--use-angle=swiftshader'] });
try {
for (const width of [1400, 390]) {
for (const payment of [
{ food: 1, gold: 2 },
{ food: 1, gold: 1, mood_tokens: 1 },
{ food: 1, gold: 1, culture_tokens: 1 },
for (const [payment, manual, stock] of [
[{ food: 1, gold: 2 }, false],
[{ food: 1, gold: 1, mood_tokens: 1 }, false],
[{ food: 1, gold: 1, culture_tokens: 1 }, false],
[{ food: 1, wood: 2, gold: 1 }, true],
[{ culture_tokens: 2, mood_tokens: 1 }, false,
{ food: 3, wood: 2, gold: 3, culture_tokens: 2, mood_tokens: 2 }],
]) {
const state = structuredClone(initial);
// Keep the regular payment available too, so the picker must be used.
state.players[seat].resources = { wood: 2, ...payment };
// Rich competing stock: regular remains legal, discounted is recommended.
state.players[seat].resources = stock ?? { ...payment, wood: 2, gold: 3 };
const stripped = engine.stripSecret(JSON.stringify(state), seat);
const offer = JSON.parse(engine.webQuery(stripped, seat, JSON.stringify({
kind: 'recruit', city: 'D2', units: { elephants: 1, ships: 1 }, replaced: [], payment,
})));
assert.deepEqual(offer.payment, payment);
const recommended = JSON.parse(engine.webQuery(stripped, seat, JSON.stringify({
kind: 'recruit', city: 'D2', units: { elephants: 1, ships: 1 }, replaced: [], includePayments: true,
})));
const expected = manual ? { food: 1, gold: 2 } : payment;
assert.deepEqual(recommended.payment, expected);
assert.deepEqual(recommended.action.Playing.Recruit.payment, expected);
assert.deepEqual(recommended.payments[0], expected);
const page = await browser.newPage({ viewport: { width, height: 900 } });
const errors = [];
page.on('pageerror', (error) => errors.push(error.message));
@ -55,15 +65,15 @@ try {
await city.getByRole('button', { name: 'Add Ship', exact: true }).click();
const picker = city.getByRole('group', { name: 'Recruitment payment', exact: true });
await picker.waitFor();
if (await picker.locator('select').count()) {
await picker.getByLabel('Wood amount for Recruitment payment', { exact: true }).selectOption('0');
if (manual && await picker.locator('select').count()) {
await picker.getByLabel('Wood amount for Recruitment payment', { exact: true }).selectOption('2');
if (payment.culture_tokens)
await picker.getByLabel('Culture amount for Recruitment payment', { exact: true }).selectOption('1');
if (payment.mood_tokens)
await picker.getByLabel('Mood amount for Recruitment payment', { exact: true }).selectOption('1');
await picker.getByLabel('Food amount for Recruitment payment', { exact: true }).selectOption('1');
await picker.getByLabel('Gold amount for Recruitment payment', { exact: true }).selectOption(String(payment.gold));
} else {
} else if (manual) {
const name = 'Pay ' + Object.entries(offer.payment).map(([key, value]) =>
`${value} ${key === 'mood_tokens' ? 'mood' : key === 'culture_tokens' ? 'culture' : key}`).join(' + ');
await picker.getByRole('button', { name, exact: true }).click();
@ -80,7 +90,7 @@ try {
for (const [key, amount] of Object.entries(payment))
assert.equal(after.players[seat].resources[key] ?? 0, state.players[seat].resources[key] - amount);
assert.deepEqual(errors, []);
console.log(`${width}px: combined Elephant + Ship ${JSON.stringify(payment)} selected, retained and executed`);
console.log(`${width}px: combined Elephant + Ship ${JSON.stringify(payment)} ${manual ? "manual regular" : "automatic discounted"}, retained and executed`);
await page.close();
}
}

View file

@ -1187,8 +1187,11 @@ test('Warbeasts and Mercenaries offer and execute combined Elephant and Ship pay
if (market) p.cities[0].city_pieces.market = index;
const units = { elephants: 1, ships: 1 };
const offer = query(g, { kind: 'recruit', city: 'D2', units, replaced: [] });
assert.deepEqual(offer.payments.map((p: any) => p.gold ?? 0),
offer.payments.map((p: any) => p.gold ?? 0).sort((a: number, b: number) => a - b));
const ranks = offer.payments.map((payment: Record<string, number>) => [
Object.values(payment).reduce((total, amount) => total + amount, 0), payment.gold ?? 0,
]);
assert.deepEqual(ranks, [...ranks].sort((a: number[], b: number[]) => a[0] - b[0] || a[1] - b[1]));
assert.deepEqual(offer.payments[0], offer.payment, 'Native recommendation wins equal-rank ties');
for (const payment of offer.payments) {
const selected = query(g, { kind: 'recruit', city: 'D2', units, replaced: [], payment });
assert.deepEqual(selected.payment, payment);
@ -1215,7 +1218,10 @@ test('Warbeasts and Mercenaries offer and execute combined Elephant and Ship pay
assert.throws(() => query(g, { kind: 'recruit', city: 'D2', units, replaced: [], payment }));
}
const ship = query(g, { kind: 'recruit', city: 'D2', units: { ships: 1 }, replaced: [] });
assert.deepEqual(ship.payment, { wood: 2 }, 'Do not broaden default-payment discount policy');
assert.deepEqual(ship.payment, { mood_tokens: 1 }, 'Mercenaries minimizes items, then gold');
const regular = query(g, { kind: 'recruit', city: 'D2', units: { ships: 1 }, replaced: [], payment: { wood: 2 } });
assert.deepEqual(regular.payment, { wood: 2 }, 'Explicit regular payment remains unchanged');
assert.doesNotThrow(() => move(g, regular.action));
}
});
test('Warbeasts and Mercenaries retain Sanitation for a separately recruited Settler', async () => {