From 2027044feda2d3eddebde073f09398a31d0ae46a Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Thu, 29 Oct 2026 15:03:31 +0100 Subject: [PATCH] fix: keep passed-player plans in the next round after charging --- old-ui/package.json | 2 +- viewer/package.json | 2 +- viewer/src/components/Game.spec.ts | 37 +++++++++++++++++++++++++++++ viewer/src/logic/analysis.spec.ts | 30 ++++++++++++++++++++++- viewer/src/logic/analysis.ts | 20 ++++++++++++---- viewer/src/testing/passed-charge.ts | 30 +++++++++++++++++++++++ 6 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 viewer/src/testing/passed-charge.ts diff --git a/old-ui/package.json b/old-ui/package.json index 7bc5fe72..a324e551 100644 --- a/old-ui/package.json +++ b/old-ui/package.json @@ -1,6 +1,6 @@ { "name": "@gaia-project/old-ui", - "version": "1.2.10", + "version": "1.2.11", "scripts": { "serve": "vite --port 5193", "build": "vite build", diff --git a/viewer/package.json b/viewer/package.json index 0448ab05..fde3f63a 100644 --- a/viewer/package.json +++ b/viewer/package.json @@ -1,6 +1,6 @@ { "name": "@gaia-project/viewer", - "version": "5.22.10", + "version": "5.22.11", "description": "Functions to visualize the map and boards for gaia project inside html canvas", "contributors": [ "coyotte508", diff --git a/viewer/src/components/Game.spec.ts b/viewer/src/components/Game.spec.ts index 8429c385..d38ce58c 100644 --- a/viewer/src/components/Game.spec.ts +++ b/viewer/src/components/Game.spec.ts @@ -6,6 +6,7 @@ import { expect } from "chai"; import Vue from "vue"; import { MAX_ANALYSIS_LINES } from "../logic/analysis"; import { makeStore } from "../store"; +import { passedChargeGame } from "../testing/passed-charge"; import Game from "./Game.vue"; Vue.use(BootstrapVue); @@ -943,6 +944,42 @@ describe("Game", () => { vm.$destroy(); }); + it("keeps next-round planning after a passed player accepts power while another decision is pending", async () => { + const real = passedChargeGame(); + const vm = mountAsSeat(2, Engine.fromData(stripSecret(real, 2))); + vm.$store.commit("hosted", true); + vm.enterAnalysisMode(); + expect(vm.engine.round).to.equal(2); + vm.applyAnalysisMove("firaks up nav."); + expect(vm.analysisEntries).to.have.length(1); + + real.move("firaks charge 1pw"); + expect(real.phase).to.equal(Phase.RoundLeech); + expect(real.playerToMove).to.equal(0); + const charged = JSON.stringify(real); + await vm.$store.dispatch("externalData", stripSecret(real, 2)); + + expect(vm.analysisMode).to.equal(true); + expect(vm.analysisRolledForward).to.equal(true); + expect(vm.engine.round).to.equal(2); + expect(vm.analysisBaseRound).to.equal(2); + expect(vm.engine.playerToMove).to.equal(2); + expect(vm.analysisEntries).to.deep.equal([{ kind: "move", move: "firaks up nav." }]); + expect(vm.analysisCommitPlan.live).to.equal(null); + expect(vm.analysisCommitPlan.queued).to.deep.equal(["firaks up nav."]); + expect(vm.analysisCommitPlan.timings).to.deep.equal([{ round: 2, phase: Phase.RoundMove }]); + const power = JSON.parse(JSON.stringify(vm.engine.players[2].data.power)); + + vm.exitAnalysisMode(); + expect(vm.engine.round).to.equal(1); + expect(vm.engine.passedPlayers).to.include(2); + vm.enterAnalysisMode(); + expect(vm.engine.round).to.equal(2); + expect(vm.engine.players[2].data.power).to.deep.equal(power); + expect(JSON.stringify(real)).to.equal(charged); + vm.$destroy(); + }); + it("keeps planning usable after next-round income when the opponent has manual income enabled", async () => { const engine = new Engine([ "init 2 Gaudy-plow-4506", diff --git a/viewer/src/logic/analysis.spec.ts b/viewer/src/logic/analysis.spec.ts index 90f6b5a0..58ea967c 100644 --- a/viewer/src/logic/analysis.spec.ts +++ b/viewer/src/logic/analysis.spec.ts @@ -1,5 +1,6 @@ import Engine, { AuctionVariant, Command, Faction, Phase, Planet, Resource, Round } from "@gaia-project/engine"; import { expect } from "chai"; +import { passedChargeGame } from "../testing/passed-charge"; import type { AnalysisEntry, MoveCost } from "./analysis"; import { advancePastOwnPass, @@ -600,6 +601,33 @@ describe("opponents' setup turns in planning", () => { describe("advancePastOwnPass", () => { const passedGame = () => new Engine([...SETUP_MOVES, "terrans pass booster4"]); + for (const accepted of [false, true]) { + it(`keeps a passed player's next-round income ${accepted ? "after accepting power" : "while power is offered"}`, () => { + const real = passedChargeGame(); + if (accepted) real.move("firaks charge 1pw"); + expect(real.phase).to.equal(Phase.RoundLeech); + expect(real.playerToMove).to.equal(accepted ? 0 : 2); + const original = JSON.stringify(real); + const engine = markAnalysisSeat(Engine.fromData(JSON.parse(original)), 2); + const expected = markAnalysisSeat(Engine.fromData(JSON.parse(original)), 2); + if (!accepted) expected.move("firaks decline 1pw"); + expected.move("terrans decline 1pw"); + expect(advancePastOwnPass(expected, 2)).to.equal(true); + settleAnalysisClone(expected, 2); + + expect(advancePastOwnPass(engine, 2)).to.equal(true); + settleAnalysisClone(engine, 2); + + expect(engine.round).to.equal(Round.Round2); + expect(engine.playerToMove).to.equal(2); + expect(engine.players[2].data.power).to.deep.equal(expected.players[2].data.power); + expect(engine.players[2].data.credits).to.equal(expected.players[2].data.credits); + expect(engine.players[2].data.ores).to.equal(expected.players[2].data.ores); + expect(engine.players[2].data.knowledge).to.equal(expected.players[2].data.knowledge); + expect(JSON.stringify(real)).to.equal(original); + }); + } + it("rolls a seat that has already passed into the next round instead of re-opening this one", () => { const engine = passedGame(); expect(engine.round).to.equal(Round.Round1); @@ -632,7 +660,7 @@ describe("advancePastOwnPass", () => { expect(JSON.stringify(engine)).to.equal(before); }); - it("does nothing outside RoundMove", () => { + it("does nothing during setup", () => { const engine = new Engine(PARTIAL_SETUP_MOVES); expect(advancePastOwnPass(engine, 0)).to.equal(false); }); diff --git a/viewer/src/logic/analysis.ts b/viewer/src/logic/analysis.ts index ed4f3759..8fecae4a 100644 --- a/viewer/src/logic/analysis.ts +++ b/viewer/src/logic/analysis.ts @@ -428,10 +428,18 @@ export function applySoloRoundFlow(engine: Engine, seat: number): void { * a line played in round N+1 describes moves the real game, still sitting in round N, cannot accept. */ export function advancePastOwnPass(engine: Engine, seat: number): boolean { - if (engine.phase !== Phase.RoundMove || !engine.passedPlayers?.includes(seat)) { + if ( + !engine.passedPlayers?.includes(seat) || + (engine.phase !== Phase.RoundMove && engine.phase !== Phase.RoundLeech) + ) { return false; } const startingRound = engine.round; + // A passed player can still charge. Finish the clone's remaining offers before the solo + // turn order clears passedPlayers; already accepted power stays in the cloned resources. + if (engine.phase === Phase.RoundLeech) { + resolveOpponentDecisions(engine, seat); + } // Bounded by the table size; the loop exits on its own as soon as control is back on this seat. for (let i = 0; i < 10; i++) { const toMove = engine.playerToMove; @@ -648,6 +656,9 @@ export function resolveOpponentDecisions(engine: Engine, seat: number): void { if (toMove === undefined || toMove === seat) { break; } + if (engine.phase === Phase.RoundMove && engine.passedPlayers?.includes(seat)) { + break; + } // Keep opponents' real placements and picks, but never invent their remaining setup moves. // Use the normal phase transition so our own placement count and round-one income stay intact. if (engine.phase === Phase.SetupBuilding || engine.phase === Phase.SetupBooster) { @@ -692,12 +703,12 @@ export function resolveOpponentDecisions(engine: Engine, seat: number): void { } break; // Nothing this function knows how to resolve - stop rather than guess at a move. } - abandonLeechPhase(engine, seat); + abandonLeechPhase(engine); } /** * The last resort behind `resolveOpponentDecisions`' loop: if the clone is STILL sitting in - * `Phase.RoundLeech` once the loop has given up, force it back to the analysis seat's move phase. + * `Phase.RoundLeech` once the loop has given up, return to the interrupted move phase. * * The loop declines through real engine code and normally lands this itself; this covers the case * where some offer it does not know how to answer survives. A surviving leech pause is not cosmetic - @@ -706,14 +717,13 @@ export function resolveOpponentDecisions(engine: Engine, seat: number): void { * declining them all would have produced (a decline changes nothing but `declined`), so nothing is * lost by taking the shortcut. */ -function abandonLeechPhase(engine: Engine, seat: number): void { +function abandonLeechPhase(engine: Engine): void { if (engine.phase !== Phase.RoundLeech) { return; } engine.leechSources = []; engine.tempTurnOrder = []; engine.tempCurrentPlayer = undefined; - engine.currentPlayer = seat; engine.changePhase(Phase.RoundMove); engine.clearAvailableCommands(); } diff --git a/viewer/src/testing/passed-charge.ts b/viewer/src/testing/passed-charge.ts new file mode 100644 index 00000000..42aab3bf --- /dev/null +++ b/viewer/src/testing/passed-charge.ts @@ -0,0 +1,30 @@ +import Engine from "@gaia-project/engine"; + +export function passedChargeGame(): Engine { + return new Engine([ + "init 4 concurrent-charge-test", + "p1 faction terrans", + "p2 faction nevlas", + "p3 faction firaks", + "p4 faction hadsch-hallas", + "p1 build m 8A2", + "p2 build m 8B1", + "p3 build m 8B3", + "p4 build m 7B5", + "p4 build m 1A2", + "p3 build m 7A4", + "p2 build m 5A2", + "p1 build m 4A4", + "p4 booster booster2", + "p3 booster booster4", + "p2 booster booster5", + "p1 booster booster6", + "hadsch-hallas income 2t", + "terrans up nav.", + "nevlas up nav.", + "firaks pass booster8", + "hadsch-hallas up nav.", + "terrans pass booster9", + "nevlas build ts 8B1.", + ]); +}