Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role Distribution: Add options for "derandomization" for perceptually fairer distributions #1561

Merged
merged 21 commits into from
Aug 15, 2024

Conversation

nike4613
Copy link
Contributor

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:

  1. Players are initialized with a table containing a weight for all roles, where that weight is ttt_role_derandomize_min_weight.
  2. 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.
  3. After role selection, we increment the weights for each role for each player by 1.
  4. 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?

@TimGoll
Copy link
Member

TimGoll commented Jun 24, 2024

This looks really nice. I will look at it depth as soon as I've got time!

Copy link
Member

@saibotk saibotk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very very much for the work!

And for diving deep into the role selection that is some good amount of work!

Love how this is kept simple and how you added comments, followed stylua etc to match the codebase!

Good Job!

I only have some comments we need to discuss but otherwise this is looking very good!

lua/ttt2/extensions/math.lua Outdated Show resolved Hide resolved
lua/ttt2/extensions/math.lua Outdated Show resolved Hide resolved
lua/terrortown/menus/gamemode/administration/roles.lua Outdated Show resolved Hide resolved
lua/terrortown/lang/en.lua Show resolved Hide resolved
Copy link
Member

@TimGoll TimGoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the very late reply. I was very busy with life and work. Thank you so much for your contribution. Besides some small nitpickings and the naming issue saibotk mentioned, this looks really good to me.

lua/ttt2/extensions/math.lua Outdated Show resolved Hide resolved
@Histalek Histalek added the type/enhancement Enhancement or simple change to existing functionality label Aug 15, 2024
Copy link
Member

@TimGoll TimGoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine now. After reading your in-game texts I also think that your name is fitting. It doesn't really matter

@TimGoll
Copy link
Member

TimGoll commented Aug 15, 2024

@nike4613 From my POV it is finished. Let me know if you agree with the changes before I merge it

nike4613

This comment was marked as outdated.

@nike4613
Copy link
Contributor Author

@nike4613 From my POV it is finished. Let me know if you agree with the changes before I merge it

Looks fine to me.

@TimGoll TimGoll merged commit 1c62446 into TTT-2:master Aug 15, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Enhancement or simple change to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants