Sub topic 12
Simulating an economy before release
This chapter assumes you can read short Python and that you know sources, sinks, and the stock-and-flow balance from earlier chapters. You will turn those ideas into a small model you can run, change, and compare against pacing targets.
Why simulate
Changing a price or a reward after launch is expensive. Players notice, some of them have already spent at the old price, and a correction can feel like a penalty. A simulation lets you find problems while changes are still free.
A simulation will not tell you whether the game is fun. It answers narrower questions:
- Does the balance grow without bound, or settle somewhere?
- How many days does each kind of player need to afford a given item?
- Which parameter does the outcome depend on most?
- Does a proposed sink remove enough currency, or too much?
Start with the simplest model
The smallest useful model has one source, one proportional sink, and one player. This is the loop from the stock-and-flow chapter, written as code.
def simulate(days, income_per_day, sink_rate, start=0.0):
"""Track one player's balance. Each day they earn a fixed amount,
then a percentage of the balance is removed (for example repair costs or fees)."""
balance = start
history = []
for _ in range(days):
balance += income_per_day
balance -= balance * sink_rate
history.append(round(balance, 2))
return history
print(simulate(60, 100, 0.10)[-1]) # close to 900The balance settles where daily inflow equals daily outflow. Setting the balance b equal to (b + income) * (1 - rate) gives b = income * (1 - rate) / rate, which is 900 here. You can check this one against algebra. Do that with any model you build, because a simulation that disagrees with a case you can solve by hand has a bug.
What a pre-release model contains
A realistic model adds four things to the minimal one.
| Part | What it represents | Where the numbers come from |
|---|---|---|
| Segments | Groups of players who earn at different rates | Design assumptions, later playtest data |
| Randomness | Day-to-day variation in play time and drops | Observed spread, or a guess you flag as a guess |
| Behavior rules | When players buy, save, or spend | Simple rules such as "buy as soon as affordable" |
| Targets | The outcomes you want | Your pacing plan, for example "a regular player affords the item in about a week" |
Keep the behavior rules crude and explicit. A rule like "buy the item the first day the balance covers it" is wrong for many real players, but it is easy to reason about. It also gives a consistent worst-case or best-case baseline.
A segment-based model
The next model simulates many players drawn from three segments. It reports how many of them buy a target item within the time horizon, and how long that takes.
import random
from statistics import median
SEGMENTS = {
"casual": {"share": 0.6, "hours_per_day": 0.5},
"regular": {"share": 0.3, "hours_per_day": 1.5},
"hardcore": {"share": 0.1, "hours_per_day": 4.0},
}
def simulate_player(days, hours_per_day, income_per_hour, sink_rate, item_price, rng):
balance = 0.0
bought_on = None
for day in range(1, days + 1):
played = max(0.0, rng.gauss(hours_per_day, hours_per_day * 0.3))
balance += played * income_per_hour
balance -= balance * sink_rate
if bought_on is None and balance >= item_price:
balance -= item_price
bought_on = day
return balance, bought_on
def run(players, days, income_per_hour, sink_rate, item_price, seed=7):
rng = random.Random(seed)
names = list(SEGMENTS)
weights = [SEGMENTS[n]["share"] for n in names]
results = {n: [] for n in names}
for _ in range(players):
name = rng.choices(names, weights)[0]
hours = SEGMENTS[name]["hours_per_day"]
results[name].append(
simulate_player(days, hours, income_per_hour, sink_rate, item_price, rng)
)
summary = {}
for name, rows in results.items():
bought = [d for _, d in rows if d is not None]
summary[name] = {
"players": len(rows),
"buy_share": len(bought) / len(rows) if rows else 0.0,
"median_day": median(bought) if bought else None,
}
return summary
for name, s in run(1000, 60, 450, 0.05, 5000).items():
print(f"{name:9} players={s['players']:4} bought={s['buy_share']:.0%} "
f"median_day={s['median_day']}")With a 5% daily sink, a casual player's balance levels off near 4,275 (225 earned per day, using the formula above). That is below the 5,000 price, so casual players should never buy the item. Regular players level off near 12,800 and should buy it around day 10. Hardcore players should buy it within the first few days.
Your design may allow that outcome, or it may not. If the item is meant to be reachable by everyone, the model has caught a real problem. The sink is too aggressive for the slowest segment, even though the average player looks fine.
Sensitivity sweeps
Once the model runs, vary one parameter at a time and watch the result. This shows which knobs matter and how much margin you have.
for rate in (0.02, 0.05, 0.10):
summary = run(1000, 60, 450, rate, 5000)
casual = summary["casual"]
print(f"sink={rate:.0%} casual bought={casual['buy_share']:.0%} "
f"median_day={casual['median_day']}")At 2% the casual segment can afford the item in about a month. At 5% and 10% they cannot, because their ceiling falls to 4,275 and then 2,025. A change of a few points in one sink rate moves a segment from reachable to impossible. Tell your designers that sensitivity: it is the main thing a simulation gives you that intuition does not.
The workflow
Two habits keep this loop honest.
- Fix the random seed while comparing variants. In the code above,
random.Random(seed)makes each run repeatable. If two runs differ, the cause is your change, not luck. Afterwards, run several seeds to see how much results vary by chance. - Change one parameter at a time. If you change the price, the income, and a sink together, you cannot tell which change produced the result.
What to measure
Choose output metrics that match the questions you set at the start. Useful ones for economies include:
- Median and 90th-percentile days to afford key items, per segment.
- The balance distribution at day 7, 30, and 60. A long tail of very rich players is an early warning of inflation.
- Total currency created and destroyed per source and sink, so you can see which one dominates. The ledger from the safeguards chapter produces the same per-reason totals in a live game.
- The share of each segment that is stuck, meaning unable to reach any goal.
Limits of the model
A simulation reflects your assumptions. These are the common ways it misleads.
- Players adapt. Real players find the most efficient source and repeat it. If your model has fixed income per hour, it will not predict that shift. Add a "best source" behavior to test it.
- Invented inputs. Before playtests, every income rate is a guess. Mark each guess, and replace it as soon as you have data.
- Missing sources and sinks. If the model leaves out gifts, events, or a rarely used sink, its totals will drift from reality. Compare modeled totals with a ledger from internal play.
- False precision. A result like "median day 9.5" is useful for comparing variants. It is not a promise about launch.
Exercise
A player earns 200 coins per day and then loses 20% of the balance to a repair sink each day, using the same order as simulate (earn first, then sink). Where does the balance settle, and would an item priced at 900 ever be affordable?
Show answer
The balance settles at income (1 - rate) / rate = 200 0.8 / 0.2 = 800. The balance approaches 800 but never reaches it, so an item priced at 900 is never affordable. To make it reachable, raise income or lower the sink rate. At a rate of 0.15, the ceiling is about 1,133.
Exercise
In the segment model, you want casual players to afford the 5,000-coin item within 60 days at 450 coins per hour of play. Name two parameters you could change, and say what you would check afterward.
Show answer
You could lower the sink rate, for example from 5% to 2%, or raise income per hour. Afterward, rerun with the same seed and check the casual segment's buy share and median day. Also check that regular and hardcore players do not now afford the item so quickly that it loses its value as a goal.