Commit graph

6 commits

Author SHA1 Message Date
9dbb0df766 feat: allow revising sealed bids and powered plants 2026-10-05 01:36:01 +02:00
Eliott C.
b90b5c63bf
Tentative-turn model: per-turn time increments, free undo, append-only log (engine+viewer 2.0.0) (#119)
* 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>
2026-08-17 09:20:50 -07:00
Eliott C.
f34947d509
feat: export moveAI for bot players (#112) 2026-08-12 22:07:44 +02:00
Lucas Mello
e8f062415d v1 2021-10-21 21:07:26 -03:00
Lucas Mello
43a4d371a1 full game 2021-10-19 10:49:02 -03:00
Lucas Mello
ed72398736 Initial 2021-10-13 00:09:21 -03:00