Sub topic 1
Why Risk and Reward Make Decisions Interesting
Players face choices where the upside and downside are both real. A risk is a possible loss. A reward is a possible gain. When a choice offers both, the player must weigh them, and that weighing is the decision.
Prerequisites
This chapter assumes you have played a range of games and can read a probability as a fraction or percentage. You should also be comfortable reading short Python snippets.
Outcomes and stakes
A decision has outcomes, and each outcome has a stake, meaning what the player gains or loses. Describe a choice by listing each outcome, its value, and its probability.
A safe option always returns 10 points. A risky option returns 25 points half the time and loses 2 points half the time. The risky option has more upside, but its outcomes spread further from the safe result.
Expected value
Expected value is the probability-weighted average of the outcomes. It tells you what a choice is worth if you repeat it many times.
def expected_value(outcomes):
# outcomes: list of (probability, value) pairs whose probabilities sum to 1
return sum(p * v for p, v in outcomes)
safe = [(1.0, 10)]
risky = [(0.5, 25), (0.5, -2)]
print(expected_value(safe)) # 10.0
print(expected_value(risky)) # 11.5The risky option averages 11.5, slightly better than the safe 10.
Variance
Variance measures how far outcomes spread around the average. A high variance makes a choice feel swingy, even when its average is good.
def expected_value(outcomes):
return sum(p * v for p, v in outcomes)
def variance(outcomes):
mean = expected_value(outcomes)
return sum(p * (v - mean) ** 2 for p, v in outcomes)
safe = [(1.0, 10)]
risky = [(0.5, 25), (0.5, -2)]
print(variance(safe)) # 0.0
print(variance(risky)) # 182.25The safe option has zero variance because every result is 10. The risky option scores 182.25, so its results swing far from the average.
Exercise
Exercise
A choice pays 40 with probability 0.2 and 0 with probability 0.8. What are its expected value and variance?
Show answer
The expected value is 0.2 × 40 + 0.8 × 0 = 8. The variance is 0.2 × (40 − 8)² + 0.8 × (0 − 8)² = 0.2 × 1024 + 0.8 × 64 = 204.8 + 51.2 = 256.