Enforce Free Education once per turn

This commit is contained in:
coyotte508 2026-10-12 15:50:49 +02:00
commit 96f235fe28
8 changed files with 40 additions and 9 deletions

View file

@ -119,14 +119,16 @@ fn free_education() -> AdvanceBuilder {
AdvanceInfo::builder(
Advance::FreeEducation,
"Free Education",
"After buying another advance with at least 1 gold or 1 idea, you may pay 1 extra idea to gain 1 mood token. This does not apply when buying Free Education itself.",
"Once per turn, after buying another advance with at least 1 gold or 1 idea, you may pay 1 extra idea to gain 1 mood token. This does not apply when buying Free Education itself.",
)
.with_advance_bonus(MoodToken)
.add_payment_request_listener(
|e| &mut e.advance,
1,
|game, p, i| {
if i.advance == Advance::FreeEducation {
if i.advance == Advance::FreeEducation
|| p.get(game).event_info.contains_key(&p.origin.id())
{
None
} else if i.payment.has_at_least(&ResourcePile::gold(1))
|| i.payment.has_at_least(&ResourcePile::ideas(1))
@ -145,8 +147,9 @@ fn free_education() -> AdvanceBuilder {
if payment.is_empty() {
return;
}
s.player()
.gain_resources(game, ResourcePile::mood_tokens(1));
let player = s.player();
player.get_mut(game).event_info.insert(player.origin.id(), "used".to_string());
player.gain_resources(game, ResourcePile::mood_tokens(1));
},
)
}

View file

@ -853,6 +853,7 @@ fn research_plan(game: &Game, seat: usize, input: &Value) -> Result<Value, Strin
};
let p = game.player(seat);
let eligible = p.can_use_advance(Advance::FreeEducation)
&& !p.event_info.contains_key(&crate::events::EventOrigin::Advance(Advance::FreeEducation).id())
&& a.advance != Advance::FreeEducation
&& (a.payment.ideas > 0 || a.payment.gold > 0);
if !eligible {

View file

@ -122,7 +122,10 @@
"wonder_cards": [
"GreatGardens"
],
"next_unit_id": 10
"next_unit_id": 10,
"event_info": {
"FreeEducation": "used"
}
},
{
"id": 1,

View file

@ -210,3 +210,5 @@ Map geometry and permanent labels now depend only on visible map content, owners
# Viewer 0.1.71 / engine 0.4.65
Read-only WASM view/preview queries retain one parsed game keyed by the exact serialized snapshot, avoiding repeated deserialization and rule initialization while selecting units, resources or payments. Move execution stays isolated. Regression checks cover seat changes, changed snapshots, returning to old states, fresh-query equivalence and non-mutation by queries or moves. Prediction's canonical comparison traverses JSON once without a stringify replacer, and its verified fingerprint is reused for server reconciliation instead of computed again. Hidden-information checks, array ordering, Undo and server validation are retained. Desktop/mobile Theaters/payment/Undo smoke passes without server acknowledgements.
Viewer 0.1.72 / engine 0.4.66 enforces Free Education once per turn, as marked on the player board. Paying consumes the allowance; declining does not. The allowance resets at end of turn, and research previews and descriptions show the same restriction. Publish the matching viewer and engine together.

View file

@ -1,12 +1,12 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.71",
"version": "0.1.72",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@boardgamers/clash-web-client",
"version": "0.1.71",
"version": "0.1.72",
"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.71",
"version": "0.1.72",
"private": true,
"type": "module",
"scripts": {

View file

@ -107,3 +107,25 @@ test('Free Education can spend the Philosophy idea from each purchased Science a
assert.deepEqual(query(foodOnly, foodAction), { eligible: false, affordable: false }, 'bonus idea does not make a food-only purchase eligible');
}
});
test('Free Education is consumed only when paid and resets after ending the turn', () => {
const g = fixture('advances/free_education');
g.actions_left = 3;
g.players[0].resources.ideas = 7;
g.players[0].incident_tokens = 3;
const move = (state: any, action: any) => JSON.parse(engine.tryMove(JSON.stringify(state), JSON.stringify(action), 0));
const first = view(g, 0).advances.find((a: any) => a.id === 'Irrigation').action;
const prompted = move(g, first);
const paid = move(prompted, { Response: { Payment: [{ ideas: 1 }] } });
const skipped = move(prompted, { Response: { Payment: [{}] } });
assert.equal(paid.players[0].event_info?.FreeEducation, 'used');
assert.equal(skipped.players[0].event_info?.FreeEducation, undefined);
for (const [state, eligible] of [[paid, false], [skipped, true]] as const) {
const second = view(state, 0).advances.find((a: any) => a.id === 'Philosophy').action;
assert.equal(query(state, second).eligible, eligible);
const after = move(state, second);
assert.equal(view(after, 0).decision?.origin?.Advance === 'FreeEducation', eligible);
}
const ended = move(paid, { Playing: 'EndTurn' });
assert.equal(ended.players[0].event_info?.FreeEducation, undefined);
});

View file

@ -84,7 +84,7 @@ const advances = {
],
FreeEducation: [
GraduationCap,
'After buying another advance with at least 1 gold or idea, you may pay 1 extra idea to gain 1 mood token.',
'Once per turn, after buying another advance with at least 1 gold or idea, you may pay 1 extra idea to gain 1 mood token.',
],
Philosophy: [Brain, 'Gain 1 idea immediately, then 1 idea each time you gain a Science advance.'],
Tactics: [