I don't understand the math. They are very clear about what they want their algorithm to achieve:
> The problem comes up when we are assigning portions of the range to various players. If we wanted distance from the creature to be proportional to your chance to be selected--that is, if the closer you are the less chance you have of being attacked--then we would assign this range by taking your distance from the creature over the total distance--the distances of everybody under consideration added together. But we really want the inverse of this ratio
That couldn't be more explicit. In the example model, where distance is danger, player D is twice as far away as player A, and has twice the chance of being attacked.
To invert that, in the game, where proximity is danger, when player A is twice as close as player D, he should have twice the chance of being attacked.
The game's algorithm does not attempt to do this. In the worked example, player A is 50% more likely to be attacked than player D is.
The correct algorithm is not difficult to write or to execute:
1. Assign all players equal odds of being attacked.
2. Weight the odds by the ratio of (distance_to_furthest_targetable_player / distance_to_me).
To make the example easier to follow, assign player D [distance: 10] 60 units of probability space. Then player A [distance: 5] should receive 60*(10/5) = 120 units, player B [distance: 2] should receive 300 units, and player C [distance: 3] should receive 200 units. Generate a real number (or, heck, an integer) in the range [0, 680) and you have your selection. Or, if you prefer, normalize all the odds and then generate something in the range [0, 1). But how did they pick the crazy algorithm they're actually using?
> The problem comes up when we are assigning portions of the range to various players. If we wanted distance from the creature to be proportional to your chance to be selected--that is, if the closer you are the less chance you have of being attacked--then we would assign this range by taking your distance from the creature over the total distance--the distances of everybody under consideration added together. But we really want the inverse of this ratio
That couldn't be more explicit. In the example model, where distance is danger, player D is twice as far away as player A, and has twice the chance of being attacked.
To invert that, in the game, where proximity is danger, when player A is twice as close as player D, he should have twice the chance of being attacked.
The game's algorithm does not attempt to do this. In the worked example, player A is 50% more likely to be attacked than player D is.
The correct algorithm is not difficult to write or to execute:
1. Assign all players equal odds of being attacked.
2. Weight the odds by the ratio of (distance_to_furthest_targetable_player / distance_to_me).
To make the example easier to follow, assign player D [distance: 10] 60 units of probability space. Then player A [distance: 5] should receive 60*(10/5) = 120 units, player B [distance: 2] should receive 300 units, and player C [distance: 3] should receive 200 units. Generate a real number (or, heck, an integer) in the range [0, 680) and you have your selection. Or, if you prefer, normalize all the odds and then generate something in the range [0, 1). But how did they pick the crazy algorithm they're actually using?