Sub topic 12
Fitting a Curve to Existing Content
Assume you know basic game design terms such as stats, cost, tiers, and power. You should also be comfortable with simple arithmetic and short Python programs. This chapter uses a power-law curve, but the same process applies to other curve shapes.
Start with reliable data
A cost curve maps measured power to a cost:
\[ cost = f(power) \]
To fit a curve, collect existing content that is already close to balanced. For each unit, item, or ability, record:
- An estimated power score.
- Its current cost.
- Its tier or progression context.
- Any unusual context, such as a strong faction bonus or a required resource.
Do not fit the curve to content that is already known to be too strong or too weak. The curve will learn those errors.
A common model is the power law:
\[ cost = scale \times power^{exponent} \]
The scale controls the overall price level. The exponent controls the curve shape. An exponent of 1 produces a linear curve. An exponent greater than 1 makes high-power content increasingly expensive.
Convert the curve into a line
Power laws are difficult to fit directly, but logarithms turn them into a linear equation:
\[ \log(cost) = \log(scale) + exponent \times \log(power) \]
This means you can:
- Take the logarithm of every power and cost value.
- Fit a straight line through those transformed points.
- Use the line's slope as the exponent.
- Convert the intercept back into the scale.
The fitting method is called least squares. It chooses the line that minimizes the total squared distance between the observed and predicted values.
import math
def fit_power_law(points):
"""Fit cost = scale * power ** exponent."""
if len(points) < 2:
raise ValueError("At least two points are required")
if any(power <= 0 or cost <= 0 for power, cost in points):
raise ValueError("Power and cost must be positive")
xs = [math.log(power) for power, _ in points]
ys = [math.log(cost) for _, cost in points]
mean_x = sum(xs) / len(xs)
mean_y = sum(ys) / len(ys)
denominator = sum((x - mean_x) ** 2 for x in xs)
if denominator == 0:
raise ValueError("Power values must not all be identical")
exponent = sum(
(x - mean_x) * (y - mean_y)
for x, y in zip(xs, ys)
) / denominator
scale = math.exp(mean_y - exponent * mean_x)
return scale, exponent
points = [(10, 12), (20, 30), (40, 75), (80, 190)]
scale, exponent = fit_power_law(points)
print(f"scale={scale:.2f}, exponent={exponent:.2f}")
print(f"predicted cost at power 50: {scale * 50 ** exponent:.1f}")Read the fitted result
The fitted exponent is a design signal:
- Near
1.0: cost grows roughly in proportion to power. - Above
1.0: powerful content receives a premium. - Below
1.0: the curve has diminishing returns, so high power becomes cheaper per point.
The fitted result is not automatically the correct design. It describes the existing data. If the data contains hidden synergies or inconsistent player demand, the result can encode those problems.
Check errors before using the curve
A residual is the difference between an observed cost and the curve's predicted cost. Large residuals can reveal:
- A unit whose power score ignores an important ability.
- A tier where players value power differently.
- A counter or synergy that changes practical strength.
- An incorrect cost or power measurement.
Inspect residuals across the whole range, not only their average. A curve can have a small average error while consistently underpricing high-tier content.
Exercise
Existing content has a fitted exponent of 1.4, but high-tier units are still dominating playtests. What should you inspect first?
Show answer
Inspect residuals and the power score. The model may be underestimating high-tier synergies, counters, or context-dependent effects. Do not increase the exponent without checking those causes.