fix: clear concurrent turn actor before next round income

This commit is contained in:
coyotte508 2026-10-30 22:13:04 +01:00
commit 2480697b96
6 changed files with 72 additions and 4 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@gaia-project/engine",
"version": "4.17.2",
"version": "4.17.3",
"description": "Javascript engine for project gaia",
"main": "dist/index.js",
"types": "index.ts",

View file

@ -1020,6 +1020,14 @@ export default class Engine {
}
}
// Older concurrent games could retain the last passer as the temporary actor into the
// next round. Completed turns have no temporary actor; partial moves (e.g. Brainstone)
// must keep theirs. Discard commands generated for that stale actor as well.
if (engine.options.concurrentCharges && engine.newTurn && engine.tempCurrentPlayer !== undefined) {
engine.tempCurrentPlayer = undefined;
engine.clearAvailableCommands();
}
repairBannedRandomFactions(engine);
return engine;
}

View file

@ -471,6 +471,8 @@ function beginSetupBoosterPhase(engine: Engine) {
}
function beginRoundStartPhase(engine: Engine) {
// The last concurrent turn must not override the next round's income/Gaia player.
engine.tempCurrentPlayer = undefined;
engine.round += 1;
startAutomaRound(engine);
engine.addAdvancedLog({ round: engine.round });

View file

@ -1,7 +1,8 @@
import { expect } from "chai";
import { automove, canMoveOutOfTurn, currentPlayer, move as hostedMove, moveAI } from "../wrapper";
import Engine from "./engine";
import { Command } from "./enums";
import { Command, Operator, Phase } from "./enums";
import Event from "./events";
import { chargeDecisionSeats, chargeFor, waitingForCharges } from "./pending-charges";
const setup = [
@ -172,6 +173,9 @@ describe("independent charge decisions", () => {
const copy = Engine.fromData(JSON.parse(JSON.stringify(engine)));
copy.move(`taklons charge 2pw @${id}`);
expect(copy.newTurn).to.equal(false);
const restored = Engine.fromData(JSON.parse(JSON.stringify(copy)));
expect(restored.tempCurrentPlayer).to.equal(0);
expect(restored.findAvailableCommand(0, Command.BrainStone)).to.not.equal(undefined);
expect(copy.findAvailableCommand(0, Command.BrainStone)).to.not.equal(undefined);
engine.players[0].settings.autoBrainstone = true;
const completed = hostedMove(engine, `taklons charge 2pw @${id}`, 0);
@ -191,6 +195,60 @@ describe("independent charge decisions", () => {
expect(engine.automation.turns[3]).to.equal(0);
});
it("hands income to the first passer after the last concurrent turn ends", () => {
const engine = game();
// Both the first and last passers have an income choice, as in Silver-signal-3116.
for (const seat of [0, 3]) engine.player(seat).loadEvents(Event.parse(["+t", "+4pw"], null));
for (let i = 0; i < 4; i++) pass(engine);
expect(engine.round).to.equal(2);
expect(engine.phase).to.equal(Phase.RoundIncome);
expect(engine.tempCurrentPlayer).to.equal(undefined);
expect(engine.playerToMove).to.equal(0);
expect(currentPlayer(JSON.parse(JSON.stringify(engine)))).to.equal(0);
const choices = engine.generateAvailableCommandsIfNeeded();
expect(choices.map((command) => command.player)).to.deep.equal([0]);
expect(choices[0].name).to.equal(Command.ChooseIncome);
const completed = hostedMove(JSON.parse(JSON.stringify(engine)), "terrans income t", 0);
expect(completed.newTurn).to.equal(true);
expect(completed.phase).to.equal(Phase.RoundMove);
expect(completed.playerToMove).to.equal(0);
expect(
completed.moveHistory.slice(engine.moveHistory.length).some((move) => move.startsWith("hadsch-hallas income"))
).to.equal(true);
});
it("keeps the first passer's turn when income needs no choices", () => {
const engine = game();
for (const player of engine.players) player.events[Operator.Income] = [];
for (let i = 0; i < 4; i++) pass(engine);
expect(engine.round).to.equal(2);
expect(engine.phase).to.equal(Phase.RoundMove);
expect(engine.tempCurrentPlayer).to.equal(undefined);
expect(engine.playerToMove).to.equal(0);
expect(currentPlayer(JSON.parse(JSON.stringify(engine)))).to.equal(0);
});
it("repairs a saved last-passer override without changing resources or history", () => {
const engine = game();
for (const seat of [0, 3]) engine.player(seat).loadEvents(Event.parse(["+t", "+4pw"], null));
for (let i = 0; i < 4; i++) pass(engine);
const saved = JSON.parse(JSON.stringify(engine));
saved.tempCurrentPlayer = 3;
saved.availableCommands = [{ name: Command.ChooseIncome, player: 3, data: ["t", "4pw"] }];
const restored = Engine.fromData(saved);
expect(restored.playerToMove).to.equal(0);
expect(restored.generateAvailableCommandsIfNeeded().map((command) => command.player)).to.deep.equal([0]);
expect(JSON.parse(JSON.stringify(restored.players))).to.deep.equal(saved.players);
expect(restored.moveHistory).to.deep.equal(saved.moveHistory);
const completed = hostedMove(restored, "terrans income t", 0);
expect(completed.newTurn).to.equal(true);
expect(completed.phase).to.equal(Phase.RoundMove);
});
it("settles remaining charges before starting the next round", () => {
const engine = game();
pass(engine);

View file

@ -1,6 +1,6 @@
{
"name": "@gaia-project/old-ui",
"version": "1.2.14",
"version": "1.2.15",
"scripts": {
"serve": "vite --port 5193",
"build": "vite build",

View file

@ -1,6 +1,6 @@
{
"name": "@gaia-project/viewer",
"version": "5.22.14",
"version": "5.22.15",
"description": "Functions to visualize the map and boards for gaia project inside html canvas",
"contributors": [
"coyotte508",