Sub topic 13
Checking the curve with simulation and playtests
A cost curve is a hypothesis: "content with this much power should cost this much." Fitting it to existing content, as in the previous chapter, only shows that the curve matches your own past decisions. This chapter covers how to test whether the prices produce fair play.
This chapter assumes you can read short Python programs and know the earlier pieces: raw_power, cost_from_power, and the power-to-cost ratio.
What you are testing
A balanced cost curve makes equally priced options about equally good. So the central test is the equal-cost matchup: give two sides the same budget, let each spend it on a different option, and see who wins.
Three kinds of evidence answer this, and each catches different problems.
| Evidence | What it measures | What it catches | Weakness |
|---|---|---|---|
| Simulation | Win rate at equal cost in a simplified combat model | Pricing errors in raw stats, bad exponents, rounding effects | Only as realistic as the model |
| Playtests | What real players pick and how they do | Fun, readability, strategies you did not model | Few samples, noisy, skill-dependent |
| Telemetry (live data) | Pick rate and win rate at scale | Drift after release, skill-dependent power | Arrives late, and players adapt |
Use simulation first because it is cheap and repeatable. Use playtests to check that the simulation was asking the right question.
Building a budget-matched simulation
The simulator below spends a budget on copies of one unit. It fights two armies and repeats the fight many times. Damage varies randomly by ±20%, so single fights are noisy.
The combat model is deliberately separate from the power formula. Speed is priced in the formula but only multiplies damage here. If the two disagree, the simulation shows it.
import math
import random
STAT_VALUE = {"attack": 2.0, "health": 0.5, "speed": 3.0}
def raw_power(stats):
return sum(STAT_VALUE[name] * amount for name, amount in stats.items())
def cost_from_power(power, scale=1.0, exponent=1.3):
return scale * power ** exponent
def make_army(unit, budget):
# Whole units only: leftover budget is wasted, which is a real effect.
count = int(budget // cost_from_power(raw_power(unit)))
return [{"dmg": unit["attack"] * unit["speed"], "hp": unit["health"]}
for _ in range(count)]
def roll_hits(attackers, rng):
return [a["dmg"] * rng.uniform(0.8, 1.2) for a in attackers]
def apply_hits(hits, defenders):
for hit in hits:
if not defenders:
return
defenders[0]["hp"] -= hit
if defenders[0]["hp"] <= 0:
defenders.pop(0)
def fight(army_a, army_b, rng, max_rounds=100):
rounds = 0
while army_a and army_b and rounds < max_rounds:
hits_a = roll_hits(army_a, rng) # both volleys use the start-of-round armies
hits_b = roll_hits(army_b, rng)
apply_hits(hits_a, army_b)
apply_hits(hits_b, army_a)
rounds += 1
if army_a and not army_b:
return 1.0
if army_b and not army_a:
return 0.0
return 0.5 # mutual wipe-out or round limit
def win_rate(unit_a, unit_b, budget, trials, rng):
total = 0.0
for _ in range(trials):
total += fight(make_army(unit_a, budget), make_army(unit_b, budget), rng)
return total / trials
def round_robin(units, budget=300, trials=500, seed=7):
rng = random.Random(seed)
averages = {}
for name, unit in units.items():
rates = [win_rate(unit, other, budget, trials, rng)
for other_name, other in units.items() if other_name != name]
averages[name] = sum(rates) / len(rates)
return averages
def win_rate_interval(win_rate_value, trials, z=1.96):
margin = z * math.sqrt(win_rate_value * (1 - win_rate_value) / trials)
return win_rate_value - margin, win_rate_value + margin
units = {
"Archer": {"attack": 4, "health": 10, "speed": 1},
"Knight": {"attack": 3, "health": 30, "speed": 1},
"Mage": {"attack": 8, "health": 10, "speed": 1},
"Scout": {"attack": 2, "health": 6, "speed": 3},
}
for name, rate in round_robin(units).items():
low, high = win_rate_interval(rate, 500)
flag = "" if low <= 0.5 <= high else " <-- check pricing"
print(f"{name:7s} {rate:.2f} ({low:.2f}-{high:.2f}){flag}")A unit's average win rate against the rest of the roster should sit near 0.5 if the curve is fair. The printed interval is approximate, because draws count as half a win and the matchups share a single average. Treat it as a guide.
Why a win rate needs an interval
Win rate from random fights is an estimate, not a fact. The standard error of a win rate p over n trials is sqrt(p(1-p)/n). At p = 0.5 and n = 500, that is about 0.022, so a 95% interval is roughly ±0.044. A reading of 0.53 therefore tells you nothing.
You have two ways to tighten the estimate:
- Run more trials. Halving the error takes four times as many.
- Fix the random seed while you iterate, so a change in results comes from your change and not from luck.
Switch seeds before you trust a result. A finding that survives three different seeds is sturdier than one tuned to a single seed.
The validation loop
Simulation and playtesting feed back into the curve. They do not replace it.
Reading the results
The pattern across the roster usually points at the cause.
- One unit is far above 0.5, the rest are slightly below. That unit is underpriced. Raise its cost, not its stats, so its identity survives.
- All units of one kind are strong. The exponent is probably wrong. If cheap units win everything, the curve is too steep. Expensive units may be priced as if they were worth more than the combat model rewards.
- One unit wins in some matchups and loses badly in others, averaging 0.5. The average hides a counter relationship. That can be healthy design (rock-paper-scissors) or a trap, so look at the full matchup table and not only the averages.
- Win rates move with the budget. Rerun at budgets of 100, 300, and 1000. Units whose strength depends on army size show up here, and so do large rounding losses.
Rounding wastes budget
In the simulator, int(budget // cost) discards leftover budget. If a unit costs 62 and the budget is 300, you get 4 units and waste 52 points. A unit costing 58 gets 5. This creates breakpoints in budget that look like power differences. Check whether an apparent imbalance is really a divisibility effect by testing several nearby budgets.
Playtests
Simulation answers "does the arithmetic hold?" Playtests answer "do people play it that way?" Plan them so they produce usable evidence.
- Decide the question beforehand, for example "Is the Mage a default pick?"
- Record choices as well as outcomes. Pick rate shows what players believe is strong.
- Compare the same players on different options when possible, since skill differences swamp small balance gaps.
- Look for strategies absent from your model, such as stacking, ordering, or ability combinations.
A unit with a 0.50 simulated win rate and a 70% pick rate is a design problem even though the numbers are balanced. Players may find it easy to use, or may misjudge its price. Either way, fix the cause. Do not repeat the simulation and hope.
Using the results to adjust the curve
When the evidence says several units are mispriced in a consistent way, refit instead of patching units one by one. Take the new pairs of (power, cost) that produced win rates near 0.5, and run fit_power_law on them. Compare the new exponent with the old one. A shift from 1.3 to 1.1 means playtests found that strong content was overpriced.
When one unit is off, change its cost directly and record why. A small log of such overrides is useful: if a third of your units need overrides, the curve is the problem.
Common errors
- Too few trials. A 0.56 from 50 fights is noise.
- Testing only the mirror. Equal units always give 0.5. It proves nothing about the curve.
- Letting the model copy the formula. If damage in combat is exactly the same weighted sum used for power, the simulation will always agree with the curve. Model behavior independently.
- Ignoring order and targeting. Front-line targeting in the sketch above favors durable units differently from area damage or focus fire. State your model's assumptions beside your results.
- Treating simulated skill as player skill. A simulation plays perfectly and identically. Real players do not, so options that need skill to use will look stronger in a simulation than in the game.
Exercise
A simulation of 400 fights gives the Mage a win rate of 0.58 against the Archer at equal cost. Using a 95% interval, is this likely a real imbalance, and what do you do next?
Show answer
The standard error is sqrt(0.58 × 0.42 / 400) ≈ 0.0247, so the 95% interval is about 0.58 ± 0.048, or 0.53 to 0.63. It excludes 0.5, so the Mage is probably slightly stronger, but the lower end is close to fair. Rerun with more trials and a different seed, and check other budgets for rounding effects. If the gap persists, raise the Mage's cost a little and rerun, instead of changing its stats.
Exercise
Why is a round-robin average win rate of 0.50 not enough to call a unit balanced?
Show answer
The average can hide strong counter relationships. A unit that beats two units 90% of the time and loses to two others 90% of the time still averages 0.50. Look at the full matchup table to decide whether those counters are intended design or an accident of pricing.