Fix dropped-player setup progression and release engine 2.0.35
This commit is contained in:
parent
dda6a51a71
commit
621586b7ec
5 changed files with 134 additions and 33 deletions
45
docs/releases/dropped-setup-progression-2.0.35.json
Normal file
45
docs/releases/dropped-setup-progression-2.0.35.json
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"game": "powergrid",
|
||||
"gameVersion": 13,
|
||||
"publishedAt": "2026-11-14T18:19:49.549Z",
|
||||
"engine": {
|
||||
"package": {
|
||||
"name": "powergrid-engine",
|
||||
"version": "2.0.35",
|
||||
"url": "https://s3.fr-par.scw.cloud/bgs-assets/games/powergrid/13/engine/910f3441acd04344/powergrid-engine-2.0.35.tgz"
|
||||
},
|
||||
"entryPoint": "dist/wrapper.js",
|
||||
"version": "2.0.35",
|
||||
"sha256": "910f3441acd04344623cc7bb7ddf445d78bb82ffd46c6da7c848a7185783fa72",
|
||||
"bytes": 412162
|
||||
},
|
||||
"previousEngine": {
|
||||
"package": {
|
||||
"name": "powergrid-engine",
|
||||
"version": "2.0.34",
|
||||
"url": "https://s3.fr-par.scw.cloud/bgs-assets/games/powergrid/13/engine/ffabbfcb33d1d2b0/powergrid-engine-2.0.34.tgz"
|
||||
},
|
||||
"entryPoint": "dist/wrapper.js"
|
||||
},
|
||||
"changes": [
|
||||
"Approved dropped-player setup progression and regression tests; reviewed implementation unchanged."
|
||||
],
|
||||
"verification": {
|
||||
"engineTests": 730,
|
||||
"engineBuild": true,
|
||||
"engineLint": true,
|
||||
"localizationTests": 8,
|
||||
"achievementManifestRevision": 3,
|
||||
"achievementDefinitions": 36,
|
||||
"packedArtifactInstalled": true,
|
||||
"packedAchievementSchemaAndTwoReplayFixtures": true,
|
||||
"packedSourceTestsAndCompiledWrapperMatch": true,
|
||||
"productionMetadataActivated": true,
|
||||
"publicTarballHash": true,
|
||||
"unchangedNonEngineMetadata": true,
|
||||
"noGameMutations": true,
|
||||
"reviewedWrapperSha256": "e62735b2c3b211764a74357ae44efd86652e26367acc4d098605b316b709e893",
|
||||
"reviewedTestsSha256": "e6635bd1209d2f5879c919ba01d2d1d80b5f02799137fa7d3ad0d12f1709d2e0"
|
||||
},
|
||||
"verified": true
|
||||
}
|
||||
2
engine/package-lock.json
generated
2
engine/package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "powergrid-engine",
|
||||
"version": "2.0.34",
|
||||
"version": "2.0.35",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "powergrid-engine",
|
||||
"version": "2.0.34",
|
||||
"version": "2.0.35",
|
||||
"description": "An engine for Power Grid",
|
||||
"main": "dist/index.js",
|
||||
"types": "index.ts",
|
||||
|
|
|
|||
|
|
@ -716,6 +716,61 @@ describe('wrapper (tentative turns)', () => {
|
|||
expect(result.players[result.currentPlayers[0]].availableMoves).to.not.be.null;
|
||||
});
|
||||
|
||||
for (const chooseColors of [false, true]) {
|
||||
it(`advances off-turn dropped setup pickers (colors=${chooseColors})`, async () => {
|
||||
let G = setup(4, { chooseRegions: true, chooseColors }, 'dropped-setup');
|
||||
const [first, second, third, fourth] = G.playerOrder;
|
||||
for (const seat of [second, third]) G = await wrapper.dropPlayer(G, seat);
|
||||
expect(G.currentPlayers).to.deep.equal([first]);
|
||||
const before = G.log.length;
|
||||
const name = chooseColors ? MoveName.ChooseColor : MoveName.ChooseRegion;
|
||||
const data = G.players[first].availableMoves![name]![0];
|
||||
G = await wrapper.move(G, { name, data } as Move, first);
|
||||
expect(wrapper.toSave(G)).to.equal(G);
|
||||
expect(G.currentPlayers).to.deep.equal([fourth]);
|
||||
expect(
|
||||
G.log
|
||||
.slice(before)
|
||||
.filter((entry) => entry.type === 'move')
|
||||
.map((entry) => (entry.type === 'move' ? entry.player : -1))
|
||||
).to.deep.equal([first, second, third]);
|
||||
expect(wrapper.timeIncrements(G)[second]).to.equal(0);
|
||||
expect(wrapper.timeIncrements(G)[third]).to.equal(0);
|
||||
expect(G.players[fourth].availableMoves![name]).to.not.be.undefined;
|
||||
});
|
||||
}
|
||||
|
||||
for (const chooseRegions of [false, true]) {
|
||||
it(`settles dropped first seat across setup boundaries (regions=${chooseRegions})`, async () => {
|
||||
let G = setup(3, { chooseColors: true, chooseRegions }, 'dropped-boundary');
|
||||
const first = G.playerOrder[0];
|
||||
G = await wrapper.dropPlayer(G, first);
|
||||
for (let turns = 0; turns < 10 && G.phase !== Phase.Auction; turns++) {
|
||||
const seat = G.currentPlayers[0];
|
||||
expect(G.players[seat].isDropped).to.be.false;
|
||||
G = wrapper.moveAI(G, seat);
|
||||
expect(wrapper.toSave(G)).to.equal(G);
|
||||
}
|
||||
expect(G.phase).to.equal(Phase.Auction);
|
||||
expect(G.currentPlayers).to.not.include(first);
|
||||
expect(G.currentPlayers).to.not.be.empty;
|
||||
expect(G.currentPlayers.every((seat) => !G.players[seat].isDropped)).to.be.true;
|
||||
});
|
||||
}
|
||||
|
||||
it('ends cleanly when the last remaining setup player drops', async () => {
|
||||
let G = setup(3, { chooseColors: true, chooseRegions: true }, 'all-dropped-setup');
|
||||
const [first, ...rest] = G.playerOrder;
|
||||
for (const seat of rest) G = await wrapper.dropPlayer(G, seat);
|
||||
const before = G.log.length;
|
||||
G = await wrapper.dropPlayer(G, first);
|
||||
expect(wrapper.ended(G)).to.be.true;
|
||||
expect(G.currentPlayers).to.be.empty;
|
||||
expect(G.players.every((player) => player.availableMoves === null)).to.be.true;
|
||||
expect(G.log.length).to.equal(before + 1);
|
||||
expect(wrapper.toSave(G)).to.equal(G);
|
||||
});
|
||||
|
||||
it('should only hand back a state from logSlice when it knows whose it is', async () => {
|
||||
// `GET /gameplay/:id/log` is not logged-in: it resolves the player with
|
||||
// `findIndex`, which is -1 when there is no user. `stripSecret` then blanks
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { autoPassAuctions } from './src/auction-auto-pass';
|
|||
import { alreadyCreditedPowering, canReviseChoice } from './src/choice-revisions';
|
||||
import * as engine from './src/engine';
|
||||
import { playersSortedByScore } from './src/engine';
|
||||
import { GameOptions } from './src/gamestate';
|
||||
import { GameOptions, Phase } from './src/gamestate';
|
||||
import type { LogMove } from './src/log';
|
||||
import { Move, MoveName } from './src/move';
|
||||
import {
|
||||
|
|
@ -55,10 +55,11 @@ export function playerSettings(G: GameState, player: number): Record<string, unk
|
|||
function runAutomaticMoves(G: GameState, now: number): GameState {
|
||||
// Premoves can finish upkeep and enter a new auction round; passing can enter
|
||||
// Resources. Settle both in order without re-running them inside replay.
|
||||
G = advanceDroppedPlayers(G);
|
||||
G = autoPassAuctions(G, now);
|
||||
G = runPremoves(G, now);
|
||||
G = autoPassAuctions(G, now);
|
||||
return runPremoves(G, now);
|
||||
return advanceDroppedPlayers(runPremoves(G, now));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -294,11 +295,35 @@ export function round(G: GameState): number {
|
|||
return G.round;
|
||||
}
|
||||
|
||||
// Ceiling on the moves auto-played for one dropped player's turn. Real turns resolve in
|
||||
// a handful — the longest is a Resources phase bought one cube at a time — so this sits
|
||||
// orders of magnitude above any legitimate turn and only ever trips on a stuck state.
|
||||
// Bound the entire dropped-seat chain, not just one seat: setup may hand control
|
||||
// to several dropped players, or return to the first seat when auctions begin.
|
||||
const MAX_AUTO_MOVES = 1000;
|
||||
|
||||
function advanceDroppedPlayers(G: GameState): GameState {
|
||||
if (engine.ended(G)) return G;
|
||||
if (G.players.every((player) => player.isDropped)) {
|
||||
// There is nobody left to receive control. Do not try to play an entire
|
||||
// game with dropped seats (some turn selectors intentionally retain one).
|
||||
G.phase = Phase.GameEnd;
|
||||
G.currentPlayers = [];
|
||||
G.players.forEach((player) => (player.availableMoves = null));
|
||||
G.newTurn = true;
|
||||
return G;
|
||||
}
|
||||
|
||||
for (let count = 0; ; count++) {
|
||||
const seat = G.currentPlayers.find((id) => G.players[id].isDropped);
|
||||
if (engine.ended(G) || seat === undefined) return G;
|
||||
if (count >= MAX_AUTO_MOVES)
|
||||
throw new Error(`Dropped players are still current after ${MAX_AUTO_MOVES} auto-played moves`);
|
||||
// Use the engine directly: wrapper.moveAI would recursively run this
|
||||
// automation and credit time increments to an abandoned seat.
|
||||
G = G.players[seat].availableMoves?.[MoveName.Pass]
|
||||
? engine.move(G, { name: MoveName.Pass, data: true }, seat)
|
||||
: engine.moveAI(G, seat);
|
||||
}
|
||||
}
|
||||
|
||||
export async function dropPlayer(G: GameState, playerNum: number): Promise<GameState> {
|
||||
automation(G).liveUpdate = false;
|
||||
const player = G.players[playerNum];
|
||||
|
|
@ -309,32 +334,8 @@ export async function dropPlayer(G: GameState, playerNum: number): Promise<GameS
|
|||
event: `Player ${playerNum} was dropped`,
|
||||
});
|
||||
|
||||
if (player.availableMoves?.[MoveName.Pass]) {
|
||||
G = engine.move(G, { name: MoveName.Pass, data: true }, playerNum);
|
||||
} else {
|
||||
let autoMoves = 0;
|
||||
|
||||
while (G.currentPlayers.includes(playerNum)) {
|
||||
if (++autoMoves > MAX_AUTO_MOVES) {
|
||||
// A state moveAI cannot advance would otherwise spin this loop forever,
|
||||
// pinning a game-server worker at 100% CPU with no request ever
|
||||
// returning. Fail loudly instead: a thrown error is recoverable and
|
||||
// diagnosable, a hung worker is neither.
|
||||
throw new Error(
|
||||
`dropPlayer: player ${playerNum} is still current after ${MAX_AUTO_MOVES} auto-played ` +
|
||||
`moves (phase ${G.phase}, round ${G.round}) — aborting to avoid an infinite loop`
|
||||
);
|
||||
}
|
||||
|
||||
G = engine.moveAI(G, playerNum);
|
||||
}
|
||||
}
|
||||
|
||||
// Dropping a player must always yield a committed state: `G` was committed to
|
||||
// begin with (tentative states are never persisted), and the auto-play above ends
|
||||
// either with a Pass or with the dropped player leaving currentPlayers — both
|
||||
// commit. Force the flag anyway (it costs nothing) so an unexpected auto-play path
|
||||
// can never leave the persisted state un-saveable.
|
||||
// Off-turn drops only mark the seat. Automatic play starts when a dropped
|
||||
// seat becomes current, including after another player's later setup pick.
|
||||
G.newTurn = true;
|
||||
return runAutomaticMoves(G, Date.now());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue