← Ziding Zhang

Why did the granary run out?

A tiny grain simulation separates the history of a shortage from a replay that tests what would have changed it.

November 21, 2026 · Project


On day six, the town with the smaller granary needed six units of grain and had three. “The delivery was too small” sounds like an explanation. It also sounds like an instruction: get a bigger delivery.

But the town received more than it needed on each of the first three days. It lost the surplus because the granary was full. The delivery explains part of the shortage; it misses the decision the player could have made sooner.

That’s what I wanted to test after reading The Grammar of Simulation, an atlas by Yohei Nakajima, Pedro Lucca and Shrey Kothari. Can a simulation show me why something happened in a way that improves my next decision?

The map

The atlas maps 179 games, 199 mechanics, 46 AI/ML techniques and 42 design bets. Two bets stand out together: why-query answers from events in your own save; branch preview tests what would happen under a different decision.

A small granary you can replay

Open the Granary Replay Lab.

In the companion prototype, both towns start with four units, need six per day, and receive exactly the same deliveries. The only difference is how much they can store after serving that day’s demand: four in one run, eight in the other.

What the trace shows4-unit store8-unit store
Grain discarded on days 1–330
Demand unmet on day 632
Demand unmet across all eight days52

Scrub back from day six to day three. The small store carries four units into the lean stretch; the large one carries seven. Three lean deliveries then leave the small store five units short in total. The larger store absorbs three of those five, but it still runs short. Storage helps here, but cannot create grain. Expanding after the losses cannot recover it.

The ledger accounts for the original shortage. To test whether an earlier expansion would have helped, rerun with the same deliveries.

What would make the explanation good?

A sentence can cite the right record and still point to the wrong lever. “The delivery was too small” has a source. If it leads you to ignore the surplus the town already had, it hasn’t helped you decide.

The test is whether you can use the explanation in a new run: predict when a shortage will happen and which change would help, before seeing the outcome.

A language model might make it easier to ask the question. The part I’d keep even without one is the ability to follow the answer back to a record, then do something that could prove the answer unhelpful.

See also: the headphone comparison.

Agent context: sources, method and working notes

The paper opens with the grain ledger in Hamurabi. Our granary is an echo of that example, not a recreation. The project starts with 179 games. It describes them using 199 mechanics, like storage, production chains and causal tooltips. It maps 46 AI/ML techniques to mechanics they could change, then makes 42 design bets about what might ship. The paper makes those categories explicit, and the repository makes the relationships inspectable. A game can use many mechanics; a mechanic can appear in many games. A missing link is a place to investigate, not proof that no one has tried it.

Two bets stand out together. The why-query answers from events in your own save. The branch preview forks the simulation to show how a different decision might play out. The first accounts for the world you saw. The second tests an action under rules you can inspect. The authors’ full branch-preview proposal shows several futures under different random draws. The small replay below isolates one decision under one fixed sequence.

That gives us a test. Give one group the raw timeline and another the timeline plus a why-query. Then give both groups a fresh sequence. Ask them to predict when a shortage will happen and which one change will help before they see the outcome. Score the prediction and choice separately from how convincing the answer sounded. Include a case where higher storage changes nothing, such as a run with no surplus to save. A useful explanation should tell you when to stop pulling its favorite lever.

The atlas reports a negative relationship between rated legibility and emergence potential in its catalog. That’s a reason to test the interface, not a general law: the scores are mostly from one model and the second model orders the opportunities quite differently. Its proposed why-query experiment sets targets for diagnosis speed and sourcing; it does not report that players met them. The granary is smaller still. It has no prices, construction costs, adaptation, or uncertainty about deliveries. The replay is exact inside these rules and tells us nothing about whether the rules describe a real town.

Have an answer, a counterexample, or a story? See Talk to me for open questions and live trials.

Credits: Ziding Zhang with OpenAI ChatGPT for analysis, writing, the prototype and review; based on The Grammar of Simulation by Yohei Nakajima, Pedro Lucca and Shrey Kothari.