Selecting Encounters
A developer implementing this kind of functionality for the first time might devise a simple function, getEncounter
, that picks a random number to serve as a dice roll before searching through an array of encounters for the first one with a probability less than or equal to the dice roll. To that developer’s chagrin, this simple approach would also be incorrect! Though this approach works when rolling to determine the chance of a singular Encounter, it won’t work when there are multiple potential encounters. Here’s what the Asteroid Belt Encounter Table looks like in simplified form:
encounters: [ { id: 'rock_hazard', name: 'Rock Hazard', image: hazard_icon, probability: 0.90 }, ...