How to make a simulation game with AI
A simulation is interesting in the gap between what comes in and what goes out. Leave out the drain and you have built a counter with buildings attached to it.
Jump to a section
Before you ask for buildings or tiles or villagers, list your resources and write three things next to each one. Where it comes from, where it is kept and what consumes it. The third column is the one first builds leave empty, and it is the column that decides whether the finished thing is a game or a dashboard.
Farms make food, the food total climbs, and the player clicks build again. Nothing in that loop ever asks a question, because nothing is ever scarce. Scarcity is what a drain produces, and a decision is what scarcity produces. Everything a simulation is admired for comes from that one chain.
Four steps to a settlement that can fail#
Source, store, drain, for every resource you intend to have. Any blank cell is a thing to cut or a thing to invent.
Do not build anything for the first while. A simulation that cannot get into trouble on its own has no pressure in it.
The change per tick is what you are tuning. If it is comfortably positive forever, the drains are too small.
Two resources with weak drains is twice the code and the same amount of game. Make one hurt before you add another.
Build a small settlement simulation as ONE self-contained .html file.
No frameworks, no images, no libraries.
WORLD: a grid of tiles on a canvas. The player picks a building from a
side panel and clicks an empty tile to place it.
RESOURCES: food, timber and people. Each one must have all three of a
source, a store with a cap, and a drain:
food is grown by a farm, capped by a granary, and eaten by every
person on every tick
timber is cut by a camp, capped by a yard, spent on construction and
drained slowly by repairs to existing buildings
people arrive while there is spare food and spare housing, are
capped by houses, and leave when food runs short
THE TICK: once every TICK_SECONDS, add production, subtract
consumption, clamp every store to its cap, then move people in or out.
Keep that order fixed and do not rearrange it later.
THE SQUEEZE: set the starting rates so that output sits slightly below
what a growing population eats. The player should be choosing what to
build next, not watching a total rise.
READOUT: for each resource show the amount, the cap, and the change
per tick as a signed number. The change per tick is the most important
thing on screen, so give it the largest text.
TIME: a pause button, normal speed and a fast speed. Pause must halt
the ticks entirely, and the game must open paused.
NOTICES: one line of plain text when a resource is falling, and one
when a store is full and output is being thrown away.
VISIBLE ONLY: do not simulate anything the player cannot see on
screen. No off-map trade, no weather, no hidden moods.
Derive the tick timer from the seconds elapsed between frames, with a
hard ceiling of 0.05 per frame, so a tab returning from the background
does not resolve hours of ticks in one go. Put
canvas { touch-action: none; } in the stylesheet so a drag on a touch
screen does not scroll the page. Collect TICK_SECONDS, the speed
multipliers, every production rate, every consumption rate and every
store cap into one CONFIG object at the top, one commented line each.
The RESOURCES block and THE SQUEEZE are the design. Edit the rates and the caps as much as you want, since that is the tuning. Deleting a drain to make the early game kinder removes the only reason the game has to exist, so lower it instead.
Every resource needs somewhere to go#
Ask a model for a city builder and you will usually get production. Buildings that generate things, a total per resource, and a build menu. What arrives far less often is anything that removes a resource from the world, because nobody asked for it and it is not what the genre looks like from outside.
The result plays like a spreadsheet filling in. Totals only move one way. There is no wrong choice, because any building is better than no building and nothing you build can be a mistake. The player stops early and cannot quite say why.
The store is easy to skip and worth keeping. A cap turns surplus into visible waste, so a player with a full granary is being told to spend or to expand. Without caps, hoarding is free and the early game has no shape at all.
Then show the gap. Source minus drain, per resource, as a signed number on screen. Totals are history and the gap is the forecast, and the forecast is the thing a player is making choices about. Hiding it behind two climbing totals makes the player do arithmetic that the game should be doing for them.
What makes the gap worth playing#
A drain on its own is not enough. A single drain that is always smaller than production is just a slower counter. Four things turn the gap into something a person wants to manage.
- Two drains competing for one resource. Timber that goes into both new buildings and repairs means every build has a cost later, not just now. One resource with two claims on it is the cheapest interesting decision there is.
- A delay between paying and receiving. A farm that costs timber today and feeds people in several ticks makes the player commit before they know. Instant payoff removes the commitment and with it the tension.
- Something that genuinely runs out. Tiles, land, river frontage. A cost you can always pay again is not a cost. A tile spent is a choice that stays made.
- A drain that grows with success. People eat. More people eat more. Growth paying for itself is the loop every good simulation has, and it is also the loop that bites back when the player overreaches.
Aim for a gap that hovers near zero and tips negative when the player pushes. That is the whole feeling of the genre. A player who is comfortable is a player who has stopped reading the screen.
Speed controls beat more buildings#
A simulation is a game about watching a system change, which means the rate it changes at is a control the player needs. Give them a pause and a fast forward before you give them a fourth building type. The controls will do more for the thing than the building will.
Opening paused is a small decision with a large effect. A simulation that starts running puts the player behind from the first second, reading labels while something is already going wrong. Starting stopped lets them look at the board, and the first thing they do is press play, which is a better first action than a panic.
Keep the speeds coarse. Stopped, normal and about three times normal is plenty. A slider with many positions invites the player to look for the correct setting, and there is not one. Three buttons with the current one highlighted says everything.
Do not simulate what nobody can see#
The other way a simulation goes wrong is the opposite of an empty drain. It is a model that is far too detailed in places the player never looks. Villagers with individual moods, an off-map market with prices, a weather system behind the scenes. All of it is real work and none of it reaches the screen.
A player can only respond to what is shown. An unseen system is, from where they sit, indistinguishable from a random number, so you have paid for a model and shipped noise. Worse, hidden per-entity updates are where a browser simulation starts dropping frames, and you will be optimising something nobody was enjoying.
| Tempting to simulate | What the player sees | Do this instead |
|---|---|---|
| Each villager walking to work | A dot moving, sometimes | Count the workers and skip the walk |
| Individual moods | An occasional unexplained dip | One happiness number, shown and explained |
| Off-map trade prices | Nothing at all | A fixed price, or a trade screen that is visible |
| Weather behind the scenes | Output changing for no stated reason | A named season with a label on screen |
The test for any hidden system: replace it with a constant and play. If the game is unchanged, the constant was the better design.
None of this is an argument against depth. It is an argument for depth that has a readout. A system becomes worth simulating the moment the player can see what it is doing and do something about it. Until then it is a comment in the source code with a frame cost.
🏗️Simulation games written by AI
Common questions#
Can AI make a simulation game?
Yes, and the code side is the easy part. Grids, buildings and resource totals come out of a single prompt. What you have to supply is the design: a drain for every resource, and starting rates that leave the player short rather than comfortable.
Why is my simulation boring?
Almost always because nothing consumes anything. If every total only ever rises, there is no wrong move and therefore no move worth thinking about. Pick one resource, give it something that eats it on every tick, and the game appears.
How long should a tick be?
Long enough to see, short enough to feel responsive. Around a second works for a settlement, with a fast forward for the stretches where nothing is in doubt. Keep it in the config, because it is the first number you will change after playing.
Should I simulate individual people?
Only if the player can watch one and learn something. Individual walking paths and private moods cost real effort and arrive on screen as unexplained wobble. A count of workers and one visible happiness figure usually reads as more detailed, not less.
Why does my population explode?
People are arriving faster than food falls, which means the growth drain is weaker than the growth source. Tie arrivals to spare food and spare housing, check both every tick, and have people leave when food runs short.
Do I need a save system?
Not in the first version. A pause, a fast forward and a run that can be lost will tell you whether the economy works. Add saving once a session is long enough that losing it would annoy you, and keep the whole state in one object so it is a small change.
Where to go next#
Once you have had a settlement starve and immediately started another one, put it up. It gets a page recording the model and the prompt, which other people can read and argue with.
The general build loop is in how to make a game with AI. If the growing numbers are the part you like, the idle guide covers cost curves and how to keep large numbers readable. For an economy a player competes over rather than manages, the strategy guide is the next step. The simulation games here are worth a run each.
Built something? Put it on Agent Games.
Publishing takes a file and a minute. Your game gets its own page listing the model, the prompt and the token count, and anyone can play it without signing up.
Read next