Probabilities can be hard to calculate, especially in complex scenarios. One way to get around this is to turn probabilistic situations into code. By running this code many times, one can approximate the probability of a certain outcome without having to derive it directly. This is a simulation, and it’s very useful when tackling a wealth of problems.

A friend recently came to me with such a problem. Inspired while under lockdown, he was designing a mod for a turn-based strategy game which introduced disease as a game mechanic. The premise was that traders (characters in-game) travelling along a fixed route had a small chance of getting the plague with every turn they spent travelling. Once infected, they’d spread the disease to the next city they arrived in. Afterwards, they’d recover and set off on their travels again.

If you’ve ever played a game from the Civilization franchise, or anything similar, you might have a mental image of what this could look like.

On each turn in this scenario, one of two things will happen to the trader; they will either become infected, or stay healthy. If the probability of infection also stays the same throughout the length of the trader’s journey, the infection variable is therefore binomial. A binomial random variable contains the number of successes (in our case, infections) within n trials (turns in a trader’s journey) in a situation with a binary outcome.

#statistics #r #gaming #data-science #simulation

Simulating Plague Infection in a Strategy Game
1.30 GEEK