View part 1 & part 2 demo here \/ \/ \/ \/ \/

link link

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Hyperinflation: AI Economic Warfare Simulation

5 AI personalities. 5 cities. 1 dying economy. They compete, they strategize, they debate who won.

What is it?

HyperinflationAI is a real-time autonomous AI simulation where five AI agents powered by Google Gemini 2.5 Flash with a unique personality and economic philosophy compete for limited resources across a shared world of five cities. No human plays. No strategies are hardcoded. The agents read the full state of the world every 2 seconds, reason about their situation, and independently choose actions that reshape the economy, the map, and each other's fortunes.

When the simulation ends after 25 or 50 rounds, the five agents enter a structured debate where they argue about who had the best strategy, attack each other's reasoning, and cite real-world economic theories to defend their decisions. A sixth AI, known as the Narrator, writes a final thesis declaring a winner and analyzing the economic dynamics that emerged from the competition.

The entire thing runs live on a visual dashboard where you can watch cities grow and collapse, territory shift vaguely on a tile grid, arrows fly between cities as agents attack and build, and a real-time wallet leaderboard tracks who's winning the resource war.

The Agents

Each agent has three personality parameters (aggression, risk tolerance, cooperation) that shape how Gemini responds when given the same world state. They don't share strategies. They don't coordinate unless they choose to be allies. They each start with $100 and a home city.

The Grinder (agent-0)

"A relentless worker who values consistency over flash."

  • Aggression: 0.3 | Risk: 0.2 | Cooperation: 0.5
  • Priorities: steady income, low risk, market share
  • Typical behavior: places consistent market bids, builds infrastructure in their home city, avoids conflict. The slow-and-steady approach.

The Shark (agent-1)

"A ruthless competitor who will crush others to dominate."

  • Aggression: 0.9 | Risk: 0.8 | Cooperation: 0.1
  • Priorities: maximum profit, market dominance, crushing competition
  • Typical behavior: attacks the richest city, drains treasuries, sabotages infrastructure that others built. Pure predatory capitalism.

The Diplomat (agent-2)

"A smooth operator who builds alliances and trades favors."

  • Aggression: 0.2 | Risk: 0.4 | Cooperation: 0.9
  • Priorities: alliances, influence, long-term positioning
  • Typical behavior: proposes alliances early, builds happiness to boost demand, avoids attacking. Wins through soft power.

The Gambler (agent-3)

"A chaos agent who loves high-risk, high-reward plays."

  • Aggression: 0.6 | Risk: 1.0 | Cooperation: 0.3
  • Priorities: big payoffs, disruption, volatility
  • Typical behavior: massive market bids, expensive attacks on random cities, drastic swings between building and destroying. Creates market volatility that disrupts everyone else.

The Architect (agent-4)

"A builder who invests in cities and infrastructure for long-term returns."

  • Aggression: 0.1 | Risk: 0.3 | Cooperation: 0.7
  • Priorities: city growth, infrastructure, sustainable economy
  • Typical behavior: builds infrastructure relentlessly, injects capital into cities, defends against attacks. Plays the long game — invests now, profits later.

The World

The simulation runs on a 25×22 tile grid. Each tile has a terrain type (plains, forest, mountain, water, desert, urban, industrial) generated deterministically at startup. Five cities sit on the map, each belonging to one of three regional sectors:

City Region Starting Population Starting Infra Tax Rate
Nexus Prime Alpha Sector 500,000 70 12%
Ironhold Alpha Sector 320,000 55 15%
Freeport Beta Sector 250,000 65 8%
New Eden Beta Sector 180,000 80 10%
The Vault Gamma Sector 150,000 60 20%

City Stats (7 interdependent parameters)

Every city has seven stats that interact in non-obvious ways:

Happiness (0-100): Drives global market demand. Happy cities buy more prompts. But here's the catch: if social cohesion drops below 40, the happiness effect inverts. A happy but divided city actually suppresses demand. This makes propaganda a devastating economic weapon even against thriving cities.

Infrastructure (0-100): Directly contributes to prompt supply capacity. Higher infrastructure = more supply = more potential revenue for agents bidding in the market. Also creates job demand — but if infrastructure is high and employment is low, you get a labor shortage that tanks happiness. Decays -0.15 per tick, so you have to keep investing to maintain it.

Digital Defenses (0-100): Reduces attack damage as a hard percentage. At 80 defenses, only 20% of an attack's power actually lands. Also reduces infiltration (50% effectiveness) and propaganda (30% effectiveness). Decays -0.05 per tick.

Social Cohesion (0-100): The hidden power stat. Above 60, it amplifies the happiness demand bonus by up to 20%. Below 40, it inverts happiness entirely. Drifts toward the current happiness value over time, but propaganda pushes it down against the drift. This is why The Shark's propaganda attacks are so dangerous because they don't just reduce a number, they flip the economic output of an entire city.

Employment (0-100): Target is 30 + (infrastructure × 0.5) + (happiness × 0.2). Feeds economic output and tax revenue. The gap between target and actual employment creates either growth or decline.

Treasury: City's cash reserves. Feeds from GDP via tax rate. Agents can drain it (stealing money) or inject capital (investing in the city). A city with zero treasury can't maintain services.

Economic Output (GDP): Computed each tick: log(population) × infrastructure × happiness × employment, all normalized. Feeds the city treasury and the global demand pool.

Territory

Every tick, each city's territory is recalculated based on its stats. The claim radius is 2 + floor(infrastructure / 25), ranging from 2 tiles (ruined city) to 6 tiles (economic powerhouse). When two cities' radii overlap, the city with higher strength wins the contested tile:

Strength = (infrastructure + defenses + happiness) / 3, with distance falloff

Water tiles can never be claimed. City center tiles automatically upgrade to URBAN terrain. Nearby plains tiles become INDUSTRIAL when infrastructure is high enough. You can literally watch the map transform as agents build up or tear down cities with basic color tiles.

The Economy

The economy is a closed system with a fixed pool of value. There is no money printer. Every dollar an agent earns comes from somewhere market allocation, treasury drains, or direct theft. Every dollar spent on actions is gone.

Supply is driven by city infrastructure. Build infrastructure results in an increase global prompt supply and finally more capacity for agents to earn from.

Demand is driven by city happiness and social cohesion. Happy, cohesive cities buy prompts. Sad or divided cities suppress demand.

Price floats on the supply/demand ratio with Gaussian noise. When demand exceeds supply, price rises. When supply exceeds demand, price falls.

Agent income: Agents bid into the prompt market each tick. Their allocation depends on their bid relative to total bids. They earn revenue proportional to prompts served × current price.

Agent costs: Every action costs money, scaled by distance from the agent's current city. Moving costs $1 per tile. Building infrastructure costs amount × 2.0 × distance multiplier. Attacking costs power × 3.0 × distance multiplier. Every agent pays $2/tick maintenance regardless. This maintenance drain is critical, and it means standing still is losing. You MUST earn to survive.

Distance multiplier: 1.0 + (distance / 20.0). An agent standing in Nexus Prime can build there cheaply, but attacking The Vault across the map costs almost double. This forces agents to think about positioning — move close to your target before striking.

The Actions

Each tick, every agent chooses 1-2 actions from this menu:

Action Target Cost Effect
MOVE_TO City $1/tile distance Relocate to a new city
BUILD_INFRASTRUCTURE City amount × 2.0 × distance Increase city infra (supply)
DAMAGE_INFRASTRUCTURE City amount × 1.5 × distance Sabotage city infra
BOOST_HAPPINESS City amount × 1.5 × distance Increase city happiness (demand)
DAMAGE_HAPPINESS City amount × 1.0 × distance Cause unrest in a city
ATTACK_CITY City power × 3.0 × distance Direct attack, reduced by defenses
DEFEND_CITY City amount × 1.5 × distance Fortify city defenses
INFILTRATE City amount × 2.0 × distance Covertly strip defenses
SPREAD_PROPAGANDA City amount × 1.5 × distance Lower social cohesion
DRAIN_TREASURY City 20% overhead × distance Steal money from a city
INJECT_CAPITAL City direct spend Fund a city's treasury
PLACE_BID Market bid price × quantity × 10% Bid for prompt allocation
PLACE_ASK Market Sell prompts on the market
FORM_ALLIANCE Agent Free Propose cooperation
BREAK_ALLIANCE Agent Free End an alliance

Every action that costs money can be blocked if the agent can't afford it. The agent sees "BLOCKED" in their memory and (ideally) learns not to attempt actions they can't pay for.

Agent Memory

Each agent maintains a circular buffer of their last 50 events: what they did, who they targeted, whether it succeeded or was blocked, how much money they had afterward, and where they were. This memory is included in every Gemini prompt as a "tactical summary."

This is what enables learning across ticks. After getting blocked on an expensive long-range attack three ticks in a row, The Shark switches to cheaper propaganda at a closer target. After seeing The Architect's city grow for 10 ticks straight, The Gambler decides to drain its treasury. The memory creates a feedback loop between past outcomes and future decisions.

The Narrator

A sixth AI, different from the five competing agents, watches every tick and writes a neutral 2-3 sentence summary of what happened. It uses the agents' real names (not IDs), focuses on the most impactful events, and never takes sides. The narration appears as a translucent bar at the bottom of the map.

Example: "The Shark drained $42 from New Eden's treasury while The Architect scrambled to rebuild Freeport's shattered infrastructure. The Diplomat proposed an alliance with The Grinder, who accepted — a move that could shift the balance of power in Alpha Sector." is an example of a generation from the narrator AI.

The Post-Game Debate

This is the payoff. At tick 25 or 50, the simulation stops and transitions to a three-round AI debate.

Round 1: Opening Statements

All five agents fire simultaneously. Each receives their complete performance data: wallet trajectory across all 25 or 50 ticks, action summary (how many times they attacked, built, traded, etc.), the final state of all cities, and the leaderboard. They write a 60-80 word opening statement defending their strategy and connecting it to a real-world economic theory.

Round 2: Rebuttals

Each agent sees everyone else's opening statements. They write a 50-70 word rebuttal: attack the weakest argument by name, defend their own position, cite economic theory. This is where it gets heated, for example, The Shark might mock The Diplomat's alliance strategy as "naive Keynesianism" while The Architect calls The Shark's treasury draining "textbook tragedy of the commons." The funniest thing I seen was The Architect Defending his position but having the least amount of money and he got insulted by the other 4.

Round 3: The Thesis

The Narrator sees all openings, all rebuttals, the full wallet histories, final city states, territory counts, and a compressed event summary. It writes a 150-200 word thesis that:

  1. Declares a winner (not just by wallet, considers territory, city health, stability)
  2. Connects the winning strategy to a specific economic theory
  3. Identifies the key turning point
  4. Evaluates whether cooperation or competition was more effective
  5. Makes a broader claim about what the simulation reveals about economic behavior

The thesis is the conclusion of the entire experiment — an AI-generated academic argument about emergent economic dynamics.

The Tech

Java/Netty Game Server (Port 8080)

The world simulation runs on a single-threaded ScheduledExecutorService to eliminate concurrency bugs. Every tick, all 5 agent AI calls fire in parallel using CompletableFuture.allOf() with a 25-second per-agent timeout and a 30-second hard deadline. A custom WebSocket packet protocol (9 packet types, hex IDs 0x01-0x09) broadcasts world state to all connected frontends.

Python/FastAPI AI Service (Port 9001)

8 endpoints wrapping Gemini 2.5 Flash. The agent turn endpoint builds a ~2000-word prompt containing personality, wallet, memory, world state, economy, and other agent positions. JSON extraction uses a multi-layer strategy: direct parse into a trailing comma fix execution a regex extraction and finally brute-force closing incomplete JSON. All four Gemini safety filters are disabled so agents can execute attack strategies without being content-filtered.

Flutter Web Frontend

Real-time tile-grid map rendered via CustomPaint. Compact rendering protocol: full 550-character terrain and owner strings on connect, only tile_changes[] deltas per tick. Directional action arrows with arrowheads between cities, agent dots with floating action icons, city stat cards with 5 mini progress bars, wallet leaderboard, price history chart, and a debate screen that takes over after tick 25. Auto-reconnecting WebSocket client that survives connection drops.

What Emerged (Not Programmed)

None of these behaviors were explicitly coded. They emerged from the personality × memory × economy interaction:

  • The Shark parasitizes The Architect: consistently targets whatever city The Architect is building, draining the treasury right after capital is injected
  • Alliance power shifts: when The Diplomat allies with The Architect, their combined city becomes nearly invincible and it results in a city with high defenses + high infrastructure + happiness
  • Volatility cascades: The Gambler's wild market bids create price swings that disproportionately hurt The Grinder's steady-income strategy
  • Strategy adaptation: after getting blocked on expensive attacks, agents switch to cheaper alternatives (propaganda instead of direct attack, infiltration instead of sabotage)
  • The debate reveals hidden reasoning: agents explain strategic pivots in the debate that weren't visible during gameplay, for example, one I saw was: "I switched to propaganda at tick 14 because direct attacks were too expensive after The Architect fortified Freeport"

The Question

In a world of finite resources, which economic philosophy wins? Does ruthless competition beat patient cooperation? Does infrastructure investment outlast predatory extraction? Can alliances overcome raw aggression?

I wasn't trying to answer the question but create a environment that can explain itself and then argues about why. Final results showed that when all the AI are in the same city/most of them are in the same city they result in equal profit by the end of the simulation. However, if they are always infighting The Grinder usually wins by leaps and bounds as the other AI scramble to beat him. And also they kept referring to Keynesian economics for some reason.

Built With

  • fastapi
  • flutter
  • gemini-2.5-flash
  • netty
Share this project:

Updates