Role Distribution: Add options for "derandomization" for perceptually fairer distributions
Randomness is bursty. Given a fair random roll, it is possible (fairly likely even) that consecutive rolls will be close to each other in value. However, we humans, with our pattern-seeking brains, see that as a pattern, and think "that must be wrong".
Rather famously, a good music shuffle is not truly random. We can see a similar problem in TTT rounds; over some sessions, some players can consistently get traitor-aligned roles, and others consistently get innocent-aligned roles. Even though it is "fair" in that it is truly random, it does not feel good to be that guy who hasn't played traitor for the past two and a half hours, while another player has gotten it multiple times on every map.
This pull request aims to give server admins options to be able to fix this problem.
The problem of shuffling a playlist is different enough from the problem of selecting roles, so we take a different approach than is laid out in that post. The broad algorithm is this:
- Players are initialized with a table containing a weight for all roles, where that weight is
ttt_role_derandomize_min_weight. - When selecting base roles or upgrading to sub-roles, instead of picking a random player from the remaining player list with equal weight, we instead select players according to a per-role weight.
- After role selection, we increment the weights for each role for each player by 1.
- Finally, we reset the weights of the selected base- and sub-roles to the value of
ttt_role_derandomize_min_weight.
The end result of this system is that players who have not gotten a role in several rounds are more likely to be selected for that role. How much each round affects that weighting can effectively be controlled by adjusting the minimum weight, with a higher minimum weight causing each round to have less effect.
The one downside of this system is that it can enable players to metagame, and guess "player A hasn't been traitor for 4 rounds, they're quite likely to be it now", which is why this mode is off by default. A note to this effect is also included in the help text in the UI for server owners. I do not believe that this should be a blocker, however: an appropriate choice of minimum weight can minimize the ability of a player to do that, and for private servers, the players can simply agree to not do that. In those cases (particularly the latter), this change could be a significant improvement over the current role distribution.
As implemented right now, the weights ALWAYS reset on map-change. I'd like to provide options to enable it to persist across map changes, possibly even with an option preventing it from persisting across sessions. I don't know what a good way to do this would be though. Any suggestions?
This looks really nice. I will look at it depth as soon as I've got time!
@nike4613 From my POV it is finished. Let me know if you agree with the changes before I merge it
@nike4613 From my POV it is finished. Let me know if you agree with the changes before I merge it
Looks fine to me.