Sub topic 10
Tuning rules and parameters
This chapter assumes you have read the earlier chapters on feedback loops and exploits. You should be comfortable with Python functions, loops, and the idea that a game state changes in discrete turns. Here you will learn to adjust a rule system after it exists, so that its emergent behavior is interesting and fair.
Rules versus parameters
A rule says what kind of thing happens. Fire spreads to flammable neighbors. A trailing player earns bonus income. A parameter says how much or how often. Fire spreads with 60% probability. The bonus is 10% of the gap.
The two kinds of change have different effects:
| Change | Example | Typical effect | Cost to test |
|---|---|---|---|
| Parameter | `catch_up` from 0.10 to 0.07 | Shifts how strong an existing behavior is | Low. Rerun the same simulation. |
| Rule | Add a cap on stored gold | Changes which behaviors exist | Higher. New interactions with every other rule. |
| Removed rule | Delete the interest term | Removes a behavior and everything built on it | Highest. Players may rely on it. |
Try parameters first. A parameter change keeps the rule set, so the interactions you already understand stay the same. If no parameter value gives acceptable behavior, the problem is structural, and you need a rule change.
Why small numbers matter so much
In an emergent system, parameters act on shared state over many turns. Their effects compound.
Recall the income function from the feedback loops chapter:
def income(gold, leader_gold, base=10, interest=0.05, catch_up=0.1):
"""Per-turn income for one player.
interest is a positive feedback term: more gold earns more gold.
catch_up is a negative feedback term: a bigger gap behind the leader earns more.
"""
return base + interest * gold + catch_up * (leader_gold - gold)Suppose the leader has L gold and the trailer has T gold, and both earn income once per turn. The leader's catch-up term is zero. The new gap is:
gap' = (L + base + interest*L) - (T + base + interest*T + catch_up*(L - T))
= gap * (1 + interest - catch_up)The base term cancels. The gap is multiplied by r = 1 + interest - catch_up every turn:
- If
r > 1(interest beats catch-up), leads grow. The match snowballs. - If
r = 1, the two forces cancel and the gap stays constant. - If
r < 1, the gap shrinks. Matches converge toward a tie.
Because r is raised to a power equal to the number of turns, a difference of 0.05 in one parameter changes the outcome by a large factor over 30 turns. This is why tuning by "a little more, a little less" often overshoots.
This closed form exists only because the example is tiny. Most real systems have no formula like this, so you have to measure them.
A worked sweep
A parameter sweep runs the same simulation across a grid of parameter values and records one outcome measure. Here the measure is the gap after 30 turns, starting from a 20-gold lead.
def income(gold, leader_gold, base=10, interest=0.05, catch_up=0.1):
return base + interest * gold + catch_up * (leader_gold - gold)
def simulate(interest, catch_up, turns=30, start=(120, 100)):
"""Return the gold gap between two players after `turns` turns."""
a, b = start
for _ in range(turns):
lead = max(a, b) # both players see the leader's gold from the start of the turn
a += income(a, lead, interest=interest, catch_up=catch_up)
b += income(b, lead, interest=interest, catch_up=catch_up)
return abs(a - b)
interests = (0.0, 0.05, 0.10)
catch_ups = (0.0, 0.05, 0.10)
print("interest \\ catch_up", *catch_ups, sep="\t")
for i in interests:
row = [round(simulate(i, c), 1) for c in catch_ups]
print(i, *row, sep="\t\t")The output should match this table, give or take rounding in the last digit:
| interest \ catch_up | 0.00 | 0.05 | 0.10 |
|---|---|---|---|
| 0.00 | 20.0 | 4.3 | 0.8 |
| 0.05 | 86.4 | 20.0 | 4.3 |
| 0.10 | 349.0 | 86.4 | 20.0 |
The grid shows two things. The diagonal is constant at 20.0 because interest = catch_up gives r = 1. The values along each diagonal match, because the system depends on the difference of the two parameters rather than on either one alone. A designer who tunes one parameter in isolation will be surprised when the "fixed" value stops working after the other one changes.
Tune against a target, not a feeling
"Feels balanced" cannot be searched for. A target is a statement about a measurable outcome. For the example, suppose a comeback should be possible but should take real effort. After 30 turns the starting 20-gold lead should be reduced, but not erased: the final gap should be between 4 and 12 gold.
def income(gold, leader_gold, base=10, interest=0.05, catch_up=0.1):
return base + interest * gold + catch_up * (leader_gold - gold)
def simulate(interest, catch_up, turns=30, start=(120, 100)):
a, b = start
for _ in range(turns):
lead = max(a, b)
a += income(a, lead, interest=interest, catch_up=catch_up)
b += income(b, lead, interest=interest, catch_up=catch_up)
return abs(a - b)
def acceptable_catch_ups(interest, low=4.0, high=12.0):
"""Return the catch_up values (in steps of 0.01) that meet the target band."""
good = []
for step in range(0, 21):
catch_up = step / 100
gap = simulate(interest, catch_up)
if low <= gap <= high:
good.append(catch_up)
return good
print(acceptable_catch_ups(interest=0.05))With interest=0.05 this prints [0.07, 0.08, 0.09, 0.1]. The four values form a range. Choosing a value near the middle of the range, such as 0.08 or 0.09, leaves room for later changes. Values at the edge of the range, such as 0.07 and 0.10, are fragile: a small change elsewhere in the game moves them out of the target.
The target band itself is a design decision. The code can tell you which values meet it, but not whether it is the right band. That judgment comes from playtests.
The tuning loop
Tuning is a loop of changing one thing and observing the result.
Three habits keep this loop honest:
- Change one thing per pass. If you change two parameters and the result improves, you do not know which change helped. Given the diagonal structure above, you may not even have changed anything real.
- Fix the random seed while comparing. If the game has randomness, seed the generator so two runs differ only because of your change. When you are done, test with many seeds to confirm the result holds in general.
- Record every run. Keep a log of parameter values, seeds, and results. Without it you cannot tell whether a later change undid an earlier fix.
What to measure
A single average hides most of what matters. Useful measures for emergent systems include:
- Spread, not only the mean. An average gap of 8 could mean every match ends near 8, or half end at 0 and half at 16. Record the minimum, maximum and percentiles.
- Match length. Strong positive feedback tends to shorten matches. Strong negative feedback tends to lengthen them.
- Outcome by starting position. If the first player wins 70% of matches, there is an advantage worth tuning, regardless of how good the average looks.
- Strategy diversity. If one build or action sequence wins in most simulated matches, you have found a candidate degenerate strategy. Revisit the exploits chapter.
- Sensitivity. Move each parameter by 10% and see how much the outcome changes. A parameter with high sensitivity needs careful, finely stepped tuning. A parameter with low sensitivity is not worth your time.
Common errors
- Tuning a symptom in the wrong place. If one unit dominates, nerfing its stats may only move the problem to the next-best unit. Ask which rule interaction makes it dominant first.
- Chasing the extremes. Fixing the most extreme reported match often breaks the common case. Look at the distribution before reacting to one story.
- Over-fitting to one scenario. Settings tuned on one map or one starting setup may fail on another. Sweep across several starting conditions, as the example sweeps interest and catch-up.
- Stacking patches. Each small fix adds a special case. After several, the rules no longer match the orthogonal design you started with. If you need more than two or three exceptions, consider replacing a rule instead.
- Forgetting the players adapt. Players change strategy in response to settings. A catch-up bonus that is slightly too strong will be deliberately triggered by players who fall behind on purpose. Treat this as a prediction to test.
- Tuning for fairness while losing the interesting part. Setting
interestequal tocatch_upgives a perfectly constant gap, but the game may feel flat. Balanced does not mean the same as fun.
Deciding when to stop
Tuning has no natural end, so set exit criteria before you begin:
- The measured outcomes lie inside the target band across the starting conditions you care about.
- Chosen values sit near the middle of their acceptable ranges rather than at the edges.
- Playtesters report that matches feel different from each other and that losing players still see a route back.
- The settings and the results that justified them are written down.
When these hold, stop. Further adjustment tends to trade one rough edge for another. After a rule change in the future, rerun the sweep before assuming old values still work.
Exercise
In the sweep above, the model gave the gap multiplier r = 1 + interest - catchup per turn. A designer sets interest = 0.08 and catchup = 0.04, then reports "leads are slightly bigger than I wanted, so I'll raise interest to 0.10 and catch_up to 0.06 to make comebacks easier." Will comebacks be easier? Compute r before and after, and say what the designer should change instead.
Show answer
Before: r = 1 + 0.08 - 0.04 = 1.04. After: r = 1 + 0.10 - 0.06 = 1.04. The multiplier is unchanged, so comebacks are no easier (the gap still grows 4% per turn), because only the difference interest - catchup matters in this model. To reduce snowballing, the designer should lower interest or raise catchup so the difference falls, for example catchup = 0.08 gives r = 1.00, and catchup above 0.08 makes leads shrink. A sweep over both parameters would have shown this.