Skip to content

Implement core TypeScript game engine#3

Open
Spbd1 wants to merge 1 commit into
codex/implement-database-layer-with-prismafrom
codex/implement-core-game-engine-in-typescript
Open

Implement core TypeScript game engine#3
Spbd1 wants to merge 1 commit into
codex/implement-database-layer-with-prismafrom
codex/implement-core-game-engine-in-typescript

Conversation

@Spbd1

@Spbd1 Spbd1 commented May 8, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Provide a pure TypeScript, framework-independent core game engine for the Parcel Society experiment that can deterministically generate maps, shocks and run simulations without Next.js or browser APIs.
  • Ensure reproducible experiments by adding a seeded RNG so the same seed + config yields identical maps, shock schedules and round outcomes.
  • Model the main game mechanics required by the spec: parcel generation with inequality conditions, production, player decisions, contracts, institutional uncertainty, round resolution, scoring and validation.

Description

  • Added a complete engine surface and typed domain model under packages/engine/src including types.ts plus modules random.ts, gini.ts, mapGenerator.ts, production.ts, decisions.ts, contracts.ts, shocks.ts, roundResolver.ts, serverSimulator.ts, scoring.ts, and validation.ts, and exported everything from index.ts.
  • Implemented deterministic seeded randomness in random.ts (SeededRandom / createRandom) and used it in mapGenerator.ts to create a 10x10 parcel grid with parcel fields (x,y,soil,water,marketAccess,risk,quality) and LOW/HIGH inequality quality mappings and a parcelQualityGini helper; added gini.ts for Gini calculation.
  • Implemented the production function in production.ts with defaults (A = 10, betaQ = 0.8, betaK = 0.5) and shock multipliers; implemented deterministic shock generation and schedules in shocks.ts and contract creation/resolution and reliability computation in contracts.ts (informal vs formal fee/default risk differences).
  • Implemented decision validation and application in validation.ts and decisions.ts (action points, resource cost checks, exited-player prevention, parcel ownership checks, contract fees/treasury transactions, public good payouts, investments, safe assets, lobbying, exit), deterministic institutional rule changes at rounds 3 and 5 for UNCERTAIN servers in serverSimulator.ts, a resolveRound function in roundResolver.ts that returns updated server/players/parcels/contracts/events/treasury/summary, scoring metrics in scoring.ts, and a runServerSimulation helper to run multiple rounds.
  • Added Vitest unit tests in index.test.ts covering deterministic map generation, gini, production output, action-point validation, overspending checks, exited-player prevention, deterministic shock schedule, inequality Gini comparison, and a basic round resolution sanity check.

Testing

  • Type-check: ran tsc --noEmit -p packages/engine/tsconfig.build.json which completed successfully for the new engine sources.
  • Formatting: ran prettier --write packages/engine/src to format the new files successfully.
  • Unit tests: attempted to run pnpm --filter @parcel-society/engine test (Vitest) but execution failed because node_modules are not present in this environment and vitest is unavailable; the test suite is included and will run in CI or after installing dependencies (pnpm install).
  • Dependency install: attempted pnpm install but it was blocked by the environment (npm registry returned 403 Forbidden), so external tool-based checks (Vitest, ESLint) could not be executed here.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant