Sub topic 17
Testing Your Design with Simulation
Assume you know basic percentages, expected value, variance, and simple Python. This chapter shows how to test a random mechanic before putting it in front of players.
A simulation runs the mechanic many times and records the results. It cannot prove exactly what will happen in one match. It can reveal whether the long-run behavior matches your design and whether rare outcomes happen often enough to affect player experience.
Turn a design question into a measurement
Start with a specific question:
- Does a 5% reward appear close to 5% over many attempts?
- How often can a player miss six times in a row?
- Does a skill bonus give an experienced player a reliable advantage?
- Does a pity timer reduce the longest losing streak?
Choose measurements before running the test. Common measurements include:
| Design concern | Useful measurement |
|---|---|
| Reward frequency | Percentage of successful attempts |
| Bad luck | Longest failure streak |
| Match balance | Win rate for each player type |
| Outcome spread | Minimum, maximum, and percentile results |
Averages alone are dangerous. Two systems can have the same average reward while one produces steady results and the other produces extreme streaks.
Build a repeatable simulation
Use a separate random number generator for the test. Give it a fixed seed while developing. A seed is an initial value that makes a pseudo-random number generator produce the same sequence again.
import random
def simulate_match(skill_bonus, rng):
player_roll = skill_bonus + rng.randint(1, 6)
opponent_roll = rng.randint(1, 6)
return player_roll > opponent_roll
def win_rate(skill_bonus, trials=10_000, seed=7):
rng = random.Random(seed)
wins = sum(simulate_match(skill_bonus, rng) for _ in range(trials))
return wins / trials
for bonus in (0, 1, 2):
print(f"bonus {bonus}: {win_rate(bonus):.1%}")The simulation compares three designs: no skill bonus, a small bonus, and a larger bonus. The result is an estimate because it samples a finite number of matches. Running 10,000 trials usually gives a clearer estimate than running 20, but it still does not equal the exact probability.
Run several seeds when checking stability. If the conclusion changes greatly between seeds, the sample is too small, the mechanic has high variance, or both.
Interpret the output
Compare the results with a design target. For example, you might want a novice to win 40% of matches against an expert, rather than 10%. Adjust the bonus and simulate again.
Inspect the distribution, not only the mean. Percentiles answer questions such as “What result does a player see in the worst 5% of sessions?” Track streaks when a mechanic creates repeated successes or failures.
A practical testing loop
Test edge cases separately. Check zero attempts, the pity limit, maximum bonuses, empty tables, and ties. A mechanic can have the correct average while still producing an impossible state or an unacceptable worst case.
Exercise
A reward has a 2% chance on each independent attempt. Why might a simulation of 100 attempts produce zero rewards without indicating a bug?
Show answer
The expected count is only 2 rewards, not a guarantee. Random variation can produce zero, especially in a short sample. Run many independent batches and inspect the overall rate and failure streaks.