From 6ae62e067c6376e847fb85f28edb637952114798 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Sat, 14 Nov 2026 00:50:16 +0000 Subject: [PATCH] Replace impossible warehouse achievement with legally attained five-stock feat --- docs/achievements.md | 51 ++++++++++++++++++++++---- engine/src/achievements.spec.ts | 63 +++++++++++++++++++++++++++++++-- engine/src/achievements.ts | 7 ++-- 3 files changed, 109 insertions(+), 12 deletions(-) diff --git a/docs/achievements.md b/docs/achievements.md index 70b0074..0377dc5 100644 --- a/docs/achievements.md +++ b/docs/achievements.md @@ -28,7 +28,28 @@ not require a victory. | `island-ten` | At least ten containers on the island at completion | | `island-diversity` | All five container colors on the island at completion | | `full-ship` | Five containers aboard the ship at completion | -| `warehouse-six` | At least six containers in the warehouse store at completion | +| `warehouse-five` | Five containers in the warehouse store at completion | + +## Threshold attainability audit + +`warehouse-six` was an invalid review-candidate ID and is retired, not repurposed. +Its replacement is `warehouse-five`. Revision 1 remains an unpublished candidate. + +| Feats | Legal limits checked | +| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Three/four factories | `BuyFactory` requires fewer than four factories and a new color; four is the cap, with five colors available. | +| Three/five warehouses | `BuyWarehouse` requires fewer than five; setup supplies five warehouse pieces per seat. | +| Warehouse stock five | `BuyFromFactory` requires stock below warehouse count: one container per warehouse, hence five total. | +| Full ship | `BuyFromWarehouse` requires fewer than five cargo containers. | +| Island five/ten/diversity | No island holding cap; auctions transfer cargo to the island. Setup supplies 12/16/20 containers of each of five colors for 3/4/5 seats. Ten holdings and five colors fit even the smallest supply. | +| Score 100/150 | Settled score, not cash; no score ceiling. Accepted bids add matching bank subsidies, and island holdings contribute to scoring. These thresholds are not constrained by a fixed cash supply. | +| Debt-free feats | Zero outstanding loans is legal; borrowing is optional and loans can be repaid. | +| Wins/player counts | Supported 3/4/5-seat games; no solo threshold or solo victory inferred. | + +The legal attainability regression starts from setup, buys warehouses and stock +using available moves, and completes a seeded game with five warehouse containers. +It checks capacities throughout and replays the serialized completed game to the +same awards. It does not inject final holdings or alter money/supply/phase. ## Rules and authority @@ -41,6 +62,8 @@ never applies scoring a second time or mistakes it for remaining cash. The existing wrapper ranks by score then island-container count. Achievements use those same comparisons, but do **not** use array/seat order to break an exact tie: tied leaders get `draw`, others `loss`, and no win achievements are granted. +The existing wrapper assigns sequential rankings even for exact ties; that +separate ranking bug is intentionally not changed by these achievement hooks. Bot and dropped seats receive no rows, but their results remain opponents' results; filtering eligibility cannot turn a loss into a win. Player count means original seats, including bots/drops. Singleton/unsupported games get no rows. @@ -54,11 +77,27 @@ inputs, and each manifest call returns a fresh object graph. ## Integration prerequisites / release boundary -- BGS must call the hook with the authoritative completed serialized state, map - zero-based seats to eligible human accounts, and reject cancelled, analysis, - tutorial and otherwise ineligible games using platform metadata. This engine - has no cancellation flag or account IDs. The hook additionally filters the - engine's `isAI` and `isDropped` flags. +- BGS calls the hook with authoritative completed serialized state and maps + zero-based seats to accounts. In the reviewed platform code, capture excludes + `game.cancelled`, `game.winClaim`, and `game.soloEditedAt`, requires ended status, + and skips already-ended games/existing evidence. Bot, dropped and quit seats + are mapped to null and discarded; other human seats can still earn feats. + See `apps/game-server/app/services/game-achievements.ts` (capture/extraction). + Admin edit-data and replay routes set `soloEditedAt` even for multiplayer games. + Container itself has no cancellation flag or account IDs; the hook additionally + filters its `isAI` and `isDropped` flags. +- **No blanket practice exclusion is established.** Capture does not consult + `soloRanked` or test custom seeds, `platformRewoundAt`, `soloAnalysisAt`, unlisted + games, or a generic tutorial/practice marker. Solo ranking policy is separate + (`packages/models/solo-ranking.ts`), and does not establish Container eligibility. + Platform analysis uses separate analysis records; Container tutorials run the + engine locally in the viewer. Neither fact is a general capture-time exclusion. + Container's `GameState` contains optional `analysisCash` (created by + `createAnalysisScenario`), but `createAnalysis` has no durable provenance flag; + the achievement hook does not classify practice from these states. No + multiplayer Container exposure through those paths has been demonstrated. + Broader practice exclusion, if required, remains a coordinator/platform policy + prerequisite rather than a guarantee of this implementation. - Install published protocol **0.11.0** using the committed lockfile. No local unpublished protocol dependency is used. - Coordinator review/activation is required. This branch does not upload to BGS, diff --git a/engine/src/achievements.spec.ts b/engine/src/achievements.spec.ts index 15fe368..8f7da43 100644 --- a/engine/src/achievements.spec.ts +++ b/engine/src/achievements.spec.ts @@ -3,8 +3,9 @@ import { expect } from 'chai'; import { cloneDeep } from 'lodash'; import seedrandom from 'seedrandom'; import * as wrapper from '../wrapper'; -import { setup } from './engine'; +import { move, moveAI, setup } from './engine'; import { containerColors, GameState, Phase } from './gamestate'; +import { MoveName } from './move'; // Compile against the published optional hooks, not a local protocol imitation. const hooks: Pick, 'achievementDefinitions' | 'achievements'> = wrapper; @@ -81,6 +82,62 @@ describe('per-game achievements', function () { } }); + it('earns warehouse-five through legal purchases and completion, including replay', () => { + const random = Math.random; + Math.random = seedrandom('warehouse-1'); + let G = setup(3, {}, 'warehouse-1'); + let reachedCapacity = false; + try { + // The ordinary AI stops expanding at three warehouses. This legal policy + // invests surplus cash in warehouses and fills them from offered stock. + // No money, pieces, phase or available moves are injected into the state. + for (let i = 0; i < 20000 && !wrapper.ended(G); i++) { + const seat = G.currentPlayers[0]; + const p = G.players[seat]; + const available = p.availableMoves!; + if (available[MoveName.BuyWarehouse] && p.money >= p.warehouses.length + 13) { + G = move(G, { name: MoveName.BuyWarehouse, data: true, extraData: G.warehousesLeft[0] }, seat); + } else if (available[MoveName.BuyFromFactory] && p.warehouses.length === 5 && p.money > 10) { + G = move( + G, + { + name: MoveName.BuyFromFactory, + data: available[MoveName.BuyFromFactory]![0], + extraData: { price: 6 }, + }, + seat + ); + } else { + G = moveAI(G, seat); + } + for (const player of G.players) { + expect(player.factories.length).to.be.at.most(4); + expect(player.warehouses.length).to.be.at.most(5); + expect(player.ship.containers.length).to.be.at.most(5); + expect(player.containersOnWarehouseStore.length).to.be.at.most(player.warehouses.length); + if (player.containersOnWarehouseStore.length === 5) { + reachedCapacity = true; + expect(player.availableMoves?.[MoveName.BuyFromFactory]).to.equal(undefined); + expect(player.availableMoves?.[MoveName.BuyWarehouse]).to.equal(undefined); + } + } + } + } finally { + Math.random = random; + } + expect(reachedCapacity).to.equal(true); + expect(wrapper.ended(G)).to.equal(true); + const saved: GameState = JSON.parse(JSON.stringify(G)); + expect(saved.players[2].warehouses).to.have.length(5); + expect(saved.players[2].containersOnWarehouseStore).to.have.length(5); + const result = wrapper.achievements(freeze(saved)); + expect(result[2].earned).to.include('warehouse-five'); + expect(result[2].earned).to.include('five-warehouses'); + expect(wrapper.achievements(wrapper.replay(saved))).to.deep.equal(result); + expect(wrapper.achievementDefinitions().achievements.map((d) => d.id)).not.to.include('warehouse-six'); + expect(result.every((row) => !row.earned.includes('warehouse-six'))).to.equal(true); + }); + it('rejects ongoing, tentative, unsupported singleton, and unsettled states', () => { expect(wrapper.achievements(setup(3, {}, 'ongoing'))).to.deep.equal([]); for (const change of [ @@ -154,8 +211,8 @@ describe('per-game achievements', function () { expect(earned()).to.include('island-diversity'); boundary('full-ship', 5, (n) => (p.ship.containers = containers(n))); boundary( - 'warehouse-six', - 6, + 'warehouse-five', + 5, (n) => (p.containersOnWarehouseStore = containers(n).map((piece) => ({ piece, price: 2, moved: false }))) ); p.loans = [{ id: 'L0' }]; diff --git a/engine/src/achievements.ts b/engine/src/achievements.ts index 7996820..824cfb7 100644 --- a/engine/src/achievements.ts +++ b/engine/src/achievements.ts @@ -20,7 +20,7 @@ const definitions = [ ['island-ten', 'Island Portfolio', 'Finish with at least ten containers on your island.'], ['island-diversity', 'A Colorful Portfolio', 'Finish with all five container colors on your island.'], ['full-ship', 'Loaded Freighter', 'Finish with five containers aboard your ship.'], - ['warehouse-six', 'Stocked for Trade', 'Finish with at least six containers in your warehouse store.'], + ['warehouse-five', 'Stocked for Trade', 'Finish with five containers in your warehouse store.'], ]; export function achievementDefinitions(): AchievementManifest { @@ -37,7 +37,8 @@ function compare(a: Player, b: Player): number { export function achievements(G: GameState): SeatAchievements[] { // Container supports 3–5 seats. There is no solo victory or engine cancellation - // flag. External cancellations, analysis games and account eligibility are BGS gates. + // flag. Platform cancellation/account eligibility must be checked by BGS; + // this state cannot establish general practice or analysis provenance. if (!ended(G) || G.newTurn === false || G.players.length < 3 || G.players.length > 5) return []; if (G.currentPlayers.length || G.players.some((p) => !Number.isFinite(p.money))) return []; const best = G.players.reduce((a, b) => (compare(a, b) >= 0 ? a : b)); @@ -63,7 +64,7 @@ export function achievements(G: GameState): SeatAchievements[] { ['island-ten', p.containersOnIsland.length >= 10], ['island-diversity', new Set(p.containersOnIsland.map((c) => c.color)).size === 5], ['full-ship', p.ship.containers.length === 5], - ['warehouse-six', p.containersOnWarehouseStore.length >= 6], + ['warehouse-five', p.containersOnWarehouseStore.length === 5], ] as const; return { seat, earned: earned.filter(([, met]) => met).map(([id]) => id), outcome }; })