Sub topic 12
Delays and oscillation
This chapter assumes you can identify stocks and flows, you know how a balancing (negative) loop pulls a stock toward a target, and you can read short Python programs. Earlier chapters treated loops as if every correction took effect at once. In real games it rarely does. This chapter shows what happens when a loop reacts late.
Why a delay changes a balancing loop
A balancing loop measures a gap between the stock and a target, then pushes the stock to close that gap. Without a delay, the push shrinks as the gap shrinks, so the stock settles smoothly.
A delay breaks that link between the push and the current gap. The push is still sized by the gap, but it is sized by the gap as it was a while ago, or it arrives a while after it was ordered. The loop keeps pushing after the gap has closed. The stock passes the target, the gap flips sign, and the loop pushes the other way, also too late. The result is oscillation, a repeating swing above and below the target.
Two things control how bad the swing is:
- Delay length. A longer delay means more stale pushes pile up before the loop notices it has overshot.
- Loop strength. A stronger push means each stale push moves the stock further.
Delay length and loop strength interact. A loop that is perfectly calm with no delay can swing wildly with a delay.
Where delays hide in games
| Delay type | Example | What the loop reads or does late |
|---|---|---|
| Perception delay | A scoreboard that updates once per round | The gap between players |
| Action delay | Units that take 30 seconds to train | The effect of an order |
| Measurement delay | Dynamic difficulty based on the last five minutes of deaths | The player's current skill |
| Update delay | Balance patches every three months | The strength of a strategy |
| Reaction delay | Players switching strategy only after losing several matches | The popularity of a strategy |
The patch cycle is a loop with a delay. A strategy becomes too strong, players adopt it, the designers see the win rates months later and nerf it, and players abandon it. The nerf lands on a metagame that has already moved, so the new weak spot becomes the next problem. That is oscillation at the scale of seasons.
Watching a delay in code
The function below is the balancing loop from earlier, with one change. The correction reads the stock as it was delay turns ago. A deque (a list with fast removal from the front) holds the recent history.
from collections import deque
def balancing_with_delay(turns, delay, target=100.0, strength=0.25, start=20.0):
health = start
# seen[0] is the stock as it was `delay` turns ago
seen = deque([start] * (delay + 1), maxlen=delay + 1)
history = [health]
for _ in range(turns):
stale = seen[0]
health += strength * (target - stale) # correction based on old information
seen.append(health)
history.append(health)
return history
for k in (0.25, 0.5, 1.0):
h = balancing_with_delay(20, delay=1, strength=k)
overshoot = max(0.0, max(h) - 100.0)
print(k, round(overshoot, 1))It prints:
0.25 0.0
0.5 20.0
1.0 80.0With delay=0, the same code reproduces the smooth approach from the earlier example. With a one-turn delay, strength 0.25 still approaches the target from below. Strength 0.5 overshoots by 20. Strength 1.0 never settles: the stock bounces between 20 and 180 indefinitely.
The chart shows the 0.5 case. Health rises, overshoots to 120, drops below 100, and then the swings shrink.
The stability limit
For this model there is a hard boundary. If the strength exceeds a limit that depends on the delay, each swing is larger than the last. The limit is 2 * sin(pi / (4 * delay + 2)).
| Delay (turns) | Strength limit for decaying swings |
|---|---|
| 0 | 2.0 |
| 1 | 1.0 |
| 2 | about 0.62 |
| 3 | about 0.45 |
Below the limit the swings decay, but they can still be visible. With a one-turn delay, overshoot begins once strength passes 0.25. At strength 1.0 the delay-1 loop sits exactly on the limit, which is why it neither settles nor explodes.
Rule of thumb: every extra turn of delay lowers the strength you can afford. If you cannot shorten a delay, you have to weaken the loop.
Action delays and pipelines
The code above delays what the loop sees. The other common case is delay in what the loop does. You order units, and they arrive later. If the controller, whether a player, an AI, or a designer's script, ignores orders already in transit, it keeps ordering the same shortfall again and again. All those orders then arrive together.
def pipeline_run(turns, delay, strength, aware, target=100.0, start=20.0):
stock = start
pipeline = [0.0] * delay # orders placed but not yet arrived
history = [stock]
for _ in range(turns):
in_flight = sum(pipeline)
gap = target - stock - (in_flight if aware else 0.0)
order = strength * gap
pipeline.append(order)
stock += pipeline.pop(0) # the order placed `delay` turns ago arrives now
history.append(stock)
return history
for aware in (False, True):
h = pipeline_run(30, delay=2, strength=0.5, aware=aware)
print("aware" if aware else "naive", round(max(h), 1))It prints:
naive 160.0
aware 100.0Both controllers use the same strength and face the same two-turn delay. The naive one reaches 160 because it counts only the stock it can see. The aware one counts the stock plus what is on its way, so it never orders more than the true shortfall. It approaches 100 from below without overshooting.
This is the standard fix for action delays: make the pipeline part of the measured state. In game terms, show the player the training queue, the incoming reinforcements, or the pending trade.
Ways to tame oscillation
- Shorten the delay. Update the scoreboard every turn. Apply the dynamic-difficulty change on the next encounter, not the next level.
- Weaken the loop. A catch-up bonus of 5% per round is far safer than 30% when information is stale.
- Count what is in flight. Include queued orders in the measured gap, as in the aware controller.
- Limit the step size. Cap how much one correction can change the stock, so a stale reading cannot cause a large overshoot.
- Make the delay visible. Players who can see that a patch, an economy sink, or a difficulty change is coming will not stack their own reactions on top of it.
Delays in reinforcing loops
Delays also act on positive loops, but the symptom differs. A reinforcing loop with a long delay looks dormant: you invest in an economy upgrade and see nothing for several turns. Then the compounding shows up all at once. Players tend to misjudge such loops in two ways. They give up on the investment too early, or they underrate how large the late payoff is. If a delayed reinforcing loop is meant to reward patience, make the early progress visible, such as a partial-completion bar, so the player knows the loop is running.
Reading the structure
The delay can sit on any edge: before the measurement, between the order and its arrival, or between a patch decision and its effect on player behavior. Wherever it sits, the effect is the same: the loop acts on the past.
Exercise
A racing game gives a speed boost to players who are behind, based on their position at the start of the previous lap. Testers report that the leader and the player in second place keep swapping places every lap. Name the loop type, explain what causes the swapping, and give two changes that would reduce it.
Show answer
This is a balancing (catch-up) loop with a one-lap delay. The boost is based on last lap's position, so a player who has already passed the leader still receives the boost, and the new leader is slowed or left without one while the player behind still has it. Each lap the correction is applied to the wrong player, so positions swap. Two fixes: base the boost on the current gap, updated continuously, which removes the delay. Or reduce the boost strength so one lap of stale boost cannot move a player past the leader.
Exercise
Using the formula 2 * sin(pi / (4 * delay + 2)), check that a stale-reading loop with delay 2 and strength 0.7 is unstable. What should you do to the strength if you want a delay-2 loop to be stable?
Show answer
For delay 2 the limit is 2 * sin(pi / 10), which is about 0.62. A strength of 0.7 is above that, so each swing is larger than the last and the loop is unstable. Keep the strength below about 0.62, and lower still, for example 0.3 to 0.4, if you also want to avoid visible overshoot.