Two Ways to Play, One Player
The standalone build is a static site: the whole economy runs in the browser and saves to local storage. The classroom build swaps the pass-key check for a real login and sends each round's decisions to the server.
main. Images cached for a year, so new art gets a new _vNN nameintlabs:sim:state:v1, the whole run as one save, schema v10src/gamesim layer around it/api, JWT on every request, scores each roundWhat Happens in One Simulated Day
Decisions never move time. Only confirming a phase does: the game then runs the rest of the phase as one batch of days, stopping at the first interrupt (a market event or a phase review) and resuming after it. Each day runs the same 13 steps across every notebook line in the portfolio.
dayTick in src/engine/simulationEngine.ts. advanceDay(state, n) calls it n times and stops early at any interrupt.One Import Surface
The UI imports game logic from one facade, engine/mockEngine.ts. Behind it sit small modules: demand, cost, production, quality, complexity, cash flow, events, scoring and projections.
Same Seed, Same Run
Every random roll comes from a seeded generator with its own key: <seed>-<day> for the real day, and <seed>:preview:<day> for forecasts. A preview can never change the real outcome, and a replay with the same decisions gives the same numbers.
No NaN, Ever
Numbers pass through small guards (finite, clamp01, safeDiv) at the engine's edges, so a bad input can't reach the save file or the charts.
Score Out of 100
Net profit counts for 50 points, a clean inventory (no stockouts, no overstock) for 25, and the three end-of-phase insight questions for 25. The questions are built from the player's own ledger, so the answers can't be memorised.
One Store, One Way to Change It
All game state lives in a single Zustand store with Immer. Components never change it directly: they call apply(fn) with an engine mutator. That one path makes the profit and loss statement, the decision timeline and undo fall out of the same records.
setPrice(s, 12), a pure function over the draftintlabs:sim:state:v1The Parts and How They Connect
A game is data, not code. Each simulation type is a set of database rows: its products (whose fields are the decision form), audience segments, global inputs and market data. That is why most of the operator console is editing screens over those collections.
api.int-labs.siteimageAssetFrom a Team's Decision to the Official Result
The browser runs the game so it feels instant. The server holds the official numbers: when the facilitator ends the round, it scores every team against the others in one database transaction.
PhaseSequenceModal, src/gamesim/sync.ts, roundControllers.endRound and services/roundCalculation.ts.How the Server Splits the Market
For each audience segment and product, the server compares every team's decisions with everyone else's. Your share depends on where your choices sit among the other teams', not on hitting a fixed target.
runRoundCalculation. The player then shows rank, leaderboard and official revenue, COGS and customers.The Core Collections
Twelve of the twenty-two MongoDB collections. Blue is a session's spine, amber is game design, green is live telemetry. Rounds link to decisions, results and projections by round number, not by id.
BaseData
- _id
- simulationTypeId
- marketData
- marketModel
SimulationType
- _id
- name
- outputs[ ]
- yearRange
Segment
- _id
- simulationTypeId
- key
- fields[ ]
Product
- _id
- simulationTypeId, segmentId
- productName
- fields[ ] (the decision form)
Simulation
- _id
- simulationTypeId
- status
- config.totalRounds
Round
- _id
- simulationId
- roundNumber, status
- timer
User
- _id
- teamId
- role
- passkey
Team
- _id
- simulationId
- teamName
- members[ ]
Decision
- _id
- simulationId, teamId
- roundNumber
- inputs[ ] by product
Results
- _id
- productId, segmentId
- roundNumber
- weightedScores, marketShares
TeamProgress
- _id
- teamId
- day, phase, cash
- lastSeenAt
Projections
- _id
- teamId
- roundNumber
- projections.<product>
Two Doors, One Token
Staff sign in with email and password; teams sign in with a passkey alone. Both get a 12-hour JSON Web Token. Every request carries it, and the server checks it before any handler runs.
Authorization: Bearer tokenWho Built What
The Player and Its Engine
Designed and built by me with Claude Code: the game, the economy engine, the store and saves, Amelia, the art direction and the booth mode for events.
The Classroom Server
The core API, its data model and both scoring calculators are the IntLabs development team's work. On top of it I rebuilt the operator console, wrote the service that closes and scores a round in one transaction, and added the live progress, run report, debrief and content models.
How It Is Checked
- The game's type check runs on every build.
- The server has unit tests for the market model, the config validators, and a parity test proving the server's copy of the engine matches the game's, value by value and file by file.
- The console has a Playwright suite: sign-in, every page, and access checks between teams.