* Never let the Wien discount make garbage free in Central Europe
Both Central Europe rulebooks (Original 2006/2011 and Recharged) give a
player connected to Wien garbage at $1 off "with the stipulation that his
cost per piece may not be 0": from the first space he pays $1. The engine
and the market box subtracted $1 with no floor, so a full market sold
garbage for $0. Engine, available moves and the box now share one price.
Six ended games on the server did buy garbage for $0. A game whose log
already shows such a buy is rebuilt with the old discount
(reconstructionOptions), so history and analysis replay them as played;
no live game has one, so they all get the floor from their next buy.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Say UK & Ireland island jumps need a completely vacant city
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Reword the UK & Ireland jump rule in every language
"An EMPTY spot" read like a free slot in an occupied city; the engine only
allows a jump to a city with no houses at all. Re-keys the 17 catalogues.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Start France and Brazil Recharged with garbage on spaces 6-8
Both Recharged rulebooks fill garbage (biogas in Brazil) on spaces 6-8, i.e.
9 tokens, but the maps' single startingResources array held the Original
count of 6 for both variants. startingResources can now name each variant.
Games created before this keep their original market when rebuilt: setup
records rechargedStartingResources for new games, and replay/reconstructState
treat a missing flag as the old behaviour.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Format PlayerBoard.vue with Prettier
Whitespace only; master's prettier check has failed on this file since 3adad0c.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Add current-round planning and city/powering premoves
* Hide empty premove containers after cancellation
* Simplify premove review and cancellation and fix clean-checkout checks
* Run premove browser checks in CI and serve the preview favicon
* Validate premoves directly and reopen them through Plan
* Show saved premoves in Plan button and use board Undo
* Remove redundant preview label from planning controls
* Rename queue cancellation to Cancel premoves
* Use board Done control to skip simulated plant purchases
* Remove root docs and repository screenshots
The per-player game clock could show one player using nearly the whole
game's elapsed time. Root cause: `move.time` was the acting client's
Date.now(), and `updateClocks` banks a stretch by subtracting one
player's stamp from another's (`ts - clockStartedAt`, where the two come
from different players' moves). Browsers disagree on the wall clock, so a
player whose clock ran fast charged that skew to themselves on every
turn; over a game's many turns it accumulated toward the total elapsed
time (observed in a real game: one player at ~46s of skew reached ~86%
of the game's wall-clock duration, while the player who followed them was
under-charged, clamped to 0 by the existing Math.max guard).
Drive the clocks from a single clock instead. `wrapper.move` — the
authoritative move processor, never reached during a deterministic
replay — now stamps each turn with the server clock as `serverTime`, and
`updateClocks` prefers it over the client `time`. AI turns are already
server-stamped, so human turns now match. The client `time` is kept
untouched: it is the move's identity for reconciling the turn buffer
against the server's echo (viewer turn-buffer helpers), and it still
drives the local preview clock on the acting player's own board.
Determinism is preserved: the server stamp is written into the log and
reused on replay. Added a wrapper test that plays with absurd client
stamps and asserts the timers track the server clock, plus a replay
check; pinned Date.now across the wrapper suite so buffers replay to
byte-identical states.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
The viewer now adopts `data.state` from the gamelog payload instead of always
refetching, so it inherits how that payload was stripped. `GET /gameplay/:id/log`
is not logged-in: it resolves the player with `findIndex`, which yields -1 when
there is no user, and `stripSecret` then blanks EVERY player's availableMoves.
The acting player therefore got a live board with nothing clickable after a page
refresh, recovering only by re-entering the game (which takes the fetchState
path). Measured on a live v10 beta game: the log endpoint reported
currentPlayers [2] with players[2].availableMoves == {}.
The blanking predates the tentative-turn model and was harmless while the viewer
ignored this payload. Offer `state` only when the index actually identifies a
player; without it launch.ts falls back to fetchState, i.e. the old behaviour.
The log itself keeps being served either way.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
* engine!: replace destructive undo with the tentative-turn model
- engine.move computes a per-state committed flag (G.newTurn): committed once
the mover can no longer undo — i.e. the negation of the old undo-availability
rule (last visible log entry is the mover's own move, mover still current,
move not a Pass). Old saves without the flag are treated as committed.
- wrapper.move now accepts the whole current-turn buffer (Move[] or a bare
move) and replays it atomically from the committed state; a buffer that
continues past a turn boundary is rejected (one committed turn per call).
- toSave returns undefined for tentative states, so the platform neither
persists them nor grants a time increment; undo becomes buffer truncation
in the viewer (replaying preserves each move's original time stamp, keeping
the in-engine clocks deterministic across resends).
- MoveName.Undo, Moves.MoveUndo, the manual per-case reversal block, the
isUndo parameter (and its issue-8 DiscardPowerPlant leniency) and the
lastMove-from-log recomputation are gone; the saved log is append-only.
- wrapper.moveAI wraps engine.moveAI to always land on committed states
(capped loop + console.error telemetry); dropPlayer force-commits and no
longer null-derefs availableMoves when dropping a non-current player.
- wrapper.replay replays [...log, ...hiddenLog] so states saved mid-fastBid
auction (bids live in the hidden log) reproduce faithfully.
- logSlice now returns the stripped state, the only channel through which the
acting player's viewer receives tentative states.
BREAKING CHANGE: engine major bump — the Undo move no longer exists and move
payloads are turn buffers.
* tests: cover the tentative-turn wrapper model
Wrapper specs exercising the platform contract end to end: tentative states
never persisted / committed states saved (Auction, Resources, Building via the
Bureaucracy script, color draft, fastBid), undo-by-truncation equivalence,
malformed-buffer atomicity, one-turn-per-call boundary rejection, hidden-log
replay of mid-fastBid saves, deterministic clocks across buffer resends, an
engine-level Bureaucracy rebase (two simultaneous players committing
independently), and moveAI/dropPlayer always landing on committed states.
* viewer!: tentative-turn buffer instead of engine Undo moves
- Game.vue keeps a turnMoves buffer plus the last committed state; every action
is stamped with time ONCE when it enters the buffer, and the WHOLE buffer is
re-sent on each action (the platform replays it from the committed state).
- Undo honors the undoWholeTurn preference locally: pop one move or scrap the
whole tentative turn; the shortened buffer is re-sent (or nothing at all when
it empties — the committed state IS the turn start). No engine Undo exists.
- Incoming states: tentative echoes are applied only when they match exactly
committedState.log + turnMoves (stale-echo guard); committed states clear the
buffer when they contain it (own commit echoed) and REBASE it otherwise —
another player's simultaneous Bureaucracy commit replays our buffer on the
new base, dropping a now-illegal tail gracefully.
- Turn-buffer logic lives in src/util/turn-buffer.ts (pure, unit-tested).
- launch.ts feeds move-response states (the only channel carrying tentative
states) into the app; self-contained.ts mimics the platform: replay the
buffer, echo tentative results, persist + broadcast only committed ones.
- Sidebar log wiring (logReversedSimple / @Watch('G.log') / replaceLog) is
untouched: one line per atomic action, live, removed on undo.
- Replaced the dead example.spec.ts (imported a HelloWorld.vue that no longer
exists — pre-existing test:unit breakage) with turn-buffer unit tests.
BREAKING CHANGE: viewer major bump — move events now carry the whole turn
buffer and require an engine with tentative-turn support.
* chore: prettier formatting
* chore: sort turn-buffer imports; export LogMove from the engine root
Commits the pending cosmetic import reordering in the turn-buffer module
and its spec, and replaces the deep import of LogMove from
powergrid-engine/src/log with a proper re-export from the package root.
* viewer: scrap unreplayable turn-buffer leftovers; guard committing rebase previews
rebaseTurnBuffer now drops any leftover buffer when the mover can no
longer act on the new committed base (not in currentPlayers). This is
how moves whose effects are hidden get cleaned up: a fastBid bid commits
to the engine's hidden log, so a chooser's [choose, bid] buffer echoed
back showed only the choose and left [bid] behind — previously discarded
only by the replay's illegal-move error path (console noise, load-bearing
on an incidental assert). Covered by a new fastBid unit test.
The Game.vue rebase path now only previews a rebased buffer while its
replay stays tentative: a buffer ending in a committing move (e.g.
Bureaucracy [UsePowerPlant, Pass] racing another player's commit) would
replay hidden outcomes on the STRIPPED state (empty deck) and flash
bogus results; show the new committed base instead and let the server
echo land.
* chore: leave the version bumps to the release workflows
Both publish workflows compute `semver.inc(<version in package.json>, <input>)`
and commit the bump themselves, so a pre-written 2.0.0 makes 2.0.0 unreachable:
a `major` run would publish 3.0.0 and a `patch` run 2.0.1. Restoring the current
published versions lets a `major` run land engine 2.0.0 / viewer 2.0.0, which is
what this breaking change wants.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: John Gold <goldjohn6@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
PR #112 re-exported moveAI so the platform could drive bot players with it, and
boardgamers has since switched bots on for Power Grid (the descriptor now reads
meta.bots: true). That promoted moveAI from an internal helper -- reached only
when a player timed out -- to a hot production path. Three things it was not
ready for, all found by reading it from that new seat:
- engine.ts: the Building-phase capacity sum used reduce() with no initial
value, so a player holding no power plants threw "Reduce of empty array with
no initial value" instead of scoring zero capacity.
- engine.ts: picking the cheapest Build / the smallest UsePowerPlant sorted
availableMoves IN PLACE. That array is player.availableMoves -- part of the
game state, and served to clients -- so choosing a move quietly rewrote the
order players are shown. Both now sort a copy.
- engine.ts: a per-move console.log('ai move', ...) shipped to production. Bots
move roughly every 1.5s, so this writes a log line per bot per turn into the
platform's log pipeline. Removed; it was also the only console.log left in the
engine's move path.
- wrapper.ts: dropPlayer auto-plays through moveAI in `while
(G.currentPlayers.includes(playerNum))`, an unbounded loop. A state moveAI
cannot advance would spin a game-server worker forever at 100% CPU with no
request ever returning. Now capped at MAX_AUTO_MOVES (1000, orders of
magnitude above any legitimate turn) and throws a diagnostic instead: a thrown
error is recoverable and greppable, a hung worker is neither. This matters
more now that the platform auto-drops inactive players.
Checked and NOT changed: every availableMoves key moveAI reads is length-guarded
at the source (available-moves.ts Build :576, UsePowerPlant :695,
ChoosePowerPlant :145, DiscardResources :85), so there is no empty-array hazard
there. DiscardPowerPlant :62 is the one unguarded assignment, but it can never
be empty -- countHeldPowerPlants excludes Australia mines, so the >3 threshold
guarantees at least three candidates survive the filter.
Tests: 69 specs (+3), tsc clean, eslint unchanged at 0 errors / 30 warnings.
The two new regression specs were teeth-checked against the pre-fix engine --
the empty-plants one fails with the exact TypeError, the ordering one fails on
"the stored Build list keeps its original order". The ordering spec also asserts
its own setup is not already price-sorted, so it cannot silently lose its teeth.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
* Add chooseColors option: players draft their colors at game start
When the chooseColors game option is set, each player picks their own color (in
seating order, one each) before play begins, instead of colors being assigned by
seat.
Engine changes:
- GameOptions.chooseColors, Phase.ColorSelection, GameState.colorDraft,
Player.color, and a MoveName.ChooseColor move.
- The default palette moves to gamestate.ts as the single source of truth and is
re-exported from engine.ts (engine.playerColors still works). factions() and the
log name coloring now use player.color ?? playerColors[id], so unchosen players
fall back to the default exactly as before.
- setup() starts in ColorSelection when chooseColors is set; finalizeColors() then
hands off to the region draft if chooseRegions is also pending, otherwise to the
auction. Color selection therefore runs before region selection when both are on.
- moveAI auto-picks a color for bots/dropped players.
Behavior is unchanged when the option is off (color stays undefined → default
palette). Adds tests for the draft flow, the default-off path, and the
chooseColors + chooseRegions ordering. All existing tests still pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Viewer: color draft UI for the chooseColors option
During the ColorSelection phase the current player gets a modal of the remaining
color swatches; clicking one drafts that color. The status bar prompts "Choose
your color". playerColors becomes a getter that overrides the default palette with
each player's drafted color (by id), so the board, player boards, and houses all
render in the chosen colors; with the option off it returns the default palette
unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>