Sub topic 8
Pricing Abilities with Expected Value
This chapter assumes you can read short Python examples and that you know the earlier chapters' ideas: stats priced in a common currency, a power score for a unit, and a cost curve that turns power into cost. You will learn to turn an ability into a number on the same scale as the stats, so a unit's abilities and stats can be added together before the cost curve is applied.
Why abilities need their own method
A stat is always on. A unit with 4 attack has 4 attack in every fight, so its value is a fixed number times a fixed price. An ability is different. It may fire one attack in four, last three seconds out of every ten, or only work against flying enemies. If you price it at its best case, you charge for power the player rarely sees.
The standard fix is expected value: the average result of the ability over many uses. You price what the ability delivers on average, not what it delivers when it works perfectly.
The formula
The model in this tutorial uses four inputs:
- Effect value is what the ability is worth each time it is fully active, in the same currency as your stats.
- Chance is the probability that the effect happens when it has a chance to happen.
- Uptime is the fraction of time the effect is active.
- Drawback is the value subtracted for costs the ability imposes on its owner.
Expected power is the effect value times chance times uptime, minus the drawback.
def ability_power(effect_value, chance=1.0, uptime=1.0, drawback=0.0):
return effect_value * chance * uptime - drawback
# A 10-point effect that triggers half the time and carries a 1-point drawback.
print(ability_power(10, chance=0.5, drawback=1)) # 4.0Chance and uptime are separate because they describe different things. Chance is about whether the effect happens at all. Uptime is about how long it lasts once it happens. A 25% chance of a one-hit bonus has full uptime for that hit. A guaranteed buff that lasts three seconds out of ten has a chance of 1.0 and an uptime of 0.3.
Getting the effect value
The formula is only as good as its first input. Effect value must come from your stat valuations, not from a feeling. In this tutorial's running example, an attack point is worth 2.0, a health point 0.5, and a speed point 3.0. Convert the effect into stat terms and multiply:
- "Heal 8 health" is worth 8 × 0.5 = 4.0.
- "+4 attack while active" is worth 4 × 2.0 = 8.0.
- "Deal 6 bonus damage" needs a price for one point of damage. If you treat one point of damage dealt as equal to one point of health removed, it is worth 6 × 0.5 = 3.0, but many games value damage higher than health. Pick one rate, write it down, and use it for every ability.
For a buff, the effect value is the value of the stat boost while it is active. Uptime then scales it to the average.
Computing uptime from a cooldown
For an ability on a cooldown, uptime is the duration divided by the time between activations. It cannot exceed 1.0, because an effect cannot be active more than all the time.
def uptime_from_cooldown(duration, cooldown):
return min(1.0, duration / cooldown)
print(uptime_from_cooldown(3, 10)) # 0.3
print(uptime_from_cooldown(12, 10)) # 1.0, the effect never lapsesThe cap matters for edge cases. If the duration is longer than the cooldown, the buff overlaps itself. Whether overlapping uses stack or merely refresh is a rule of your game. If it only refreshes, the cap is right. If it stacks, uptime above 1.0 is meaningful and you should model stacking explicitly instead of using this helper.
A worked example
Here are four abilities priced with the same function.
def ability_power(effect_value, chance=1.0, uptime=1.0, drawback=0.0):
return effect_value * chance * uptime - drawback
abilities = {
"Critical Strike": dict(effect_value=12, chance=0.25),
"Poison Dart": dict(effect_value=6, chance=0.3),
"Frost Aura": dict(effect_value=8, uptime=0.6),
"Overcharge": dict(effect_value=20, uptime=0.2, drawback=2),
}
for name, params in abilities.items():
print(name, round(ability_power(**params), 2))The output is 3.0 for Critical Strike, 1.8 for Poison Dart, 4.8 for Frost Aura, and 2.0 for Overcharge.
| Ability | Effect value | Chance | Uptime | Drawback | Power |
|---|---|---|---|---|---|
| Critical Strike | 12 | 0.25 | 1.0 | 0 | 3.0 |
| Poison Dart | 6 | 0.3 | 1.0 | 0 | 1.8 |
| Frost Aura | 8 | 1.0 | 0.6 | 0 | 4.8 |
| Overcharge | 20 | 1.0 | 0.2 | 2 | 2.0 |
Overcharge looks the strongest on paper, with an effect value of 20. Once uptime and its drawback are applied, it is worth less than Frost Aura. This is the main reason to price by expected value: raw effect size is a poor guide to how strong an ability feels.
Adding the ability to a unit
Ability power is on the same scale as stat power, so a unit's total power is their sum. The sum then goes through the cost curve.
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 ability_power(effect_value, chance=1.0, uptime=1.0, drawback=0.0):
return effect_value * chance * uptime - drawback
def cost_from_power(power, scale=1.0, exponent=1.3):
return scale * power ** exponent
archer = {"attack": 4, "health": 10, "speed": 1}
crit = ability_power(12, chance=0.25)
plain = raw_power(archer)
with_crit = plain + crit
print(plain, round(cost_from_power(plain), 1)) # 16.0 36.8
print(with_crit, round(cost_from_power(with_crit), 1)) # 19.0 46.0Adding 3.0 power raises the cost from about 36.8 to 46.0, a rise of about 9.2. With an exponent above 1.0, the same ability costs more on a strong unit than on a weak one. That is often what you want. A critical-strike chance is worth more on a unit that already hits hard. If you would rather charge a flat price for an ability, price it separately and add it after the curve.
Common errors
Pricing the best case. An ability that "deals 20 damage" but needs a rare setup has a low chance or uptime. Write down the setup frequency and include it. If you can't estimate it, measure it in simulation (covered in a later chapter).
Treating chance as a percentage of the unit's strength. Chance is per opportunity. A 25% trigger on each attack is worth more on a fast unit than on a slow one, because it gets more opportunities. When the number of opportunities differs between units, fold the attack rate into the effect value or the chance, and do it consistently.
Double counting. If an ability says "+50% attack" and you also priced attack as a stat, the effect value should be 50% of the unit's attack value, not a flat number. An ability that scales with a stat should be priced from that stat's current value.
Ignoring variance. Two abilities can have the same expected value and feel very different. A 1% chance of 100 damage and a guaranteed 1 damage both have an expected value of 1. Players tend to dislike losing to bad luck, and some games reward swingy plays. The formula does not capture this. Apply a small discount or premium if your game has a view on randomness, and state it as a rule.
Hiding drawbacks in the effect value. Subtract costs separately so you can see them. The next chapter covers how to price drawbacks and conditions; here, treat a drawback as a number you can estimate the same way you estimated the effect.
Checking your estimates
A short routine keeps ability prices honest:
- Write the effect in plain words, then convert it to stat terms using your stat valuations.
- List how often the effect happens (chance) and how long it lasts (uptime). Use cooldowns and durations where you have them.
- List every cost the ability imposes and give each a value.
- Compute the power, add it to the unit's stat power, and apply the cost curve.
- Compare the result against similar abilities. If one sits far from the rest, recheck its inputs before changing the price.
Exercise
A unit has the ability "On each attack, 40% chance to heal 8 health." Health is worth 0.5 per point. Chance applies per attack and the effect is instant, so uptime is 1.0. There is no drawback. What is the ability's power?
Show answer
The effect value is 8 × 0.5 = 4.0. The power is 4.0 × 0.4 × 1.0 − 0 = 1.6.
Exercise
A unit has a buff that gives +4 attack for 4 seconds, usable every 10 seconds. Attack is worth 2.0 per point. The buff also costs the unit 1.0 in value because it cannot move while the buff is active. What is the ability's power, using the uptimefromcooldown helper?
Show answer
The effect value is 4 × 2.0 = 8.0. The uptime is min(1.0, 4 / 10) = 0.4. The power is 8.0 × 1.0 × 0.4 − 1.0 = 2.2.
Exercise
Why can a high effect value ability end up cheaper than a modest one?
Show answer
The effect value is only the best case. Chance and uptime scale it down to the average, and drawbacks are subtracted. An ability with a large effect, low chance or short uptime, and a real drawback can have a lower expected power than a small effect that is always on.