-
Notifications
You must be signed in to change notification settings - Fork 162
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
Implement Weighted Role Selection System #253
base: master
Are you sure you want to change the base?
Conversation
Related to eDonnes124#252 Implements a weighted role selection system to adjust player roles based on previous game outcomes, enhancing the game experience by reducing role repetition for players across sessions. - Adds a new game option to enable or disable the weighted role selection system, allowing hosts to control this feature in game settings. - Records each player's role at the end of a game and stores this information in a session-based collection to calculate future role assignments. - Updates the role assignment logic to consider the session's role history, aiming to assign roles less repetitively. - Modifies the game's documentation and options generation to include and describe the new weighted role selection feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it'd be great if you could make a checklist in the PR with todos as well so we could easily see everything that needs to be done and the current progress more clearly.
Thanks for beginning to set this up, it'd have taken me quite a bit of time to figure this out as while I've used Harmony a decent amount I've never touched the Among Us codebase.
Edit: didn't meant to approve originally, doesn't seem like GitHub has a way of undoing my misclick -_-
// Implement a method to record the roles assigned to each player at the end of a game. | ||
// Store the role history in a session-based collection. | ||
private static Dictionary<byte, List<RoleEnum>> _sessionRoleHistory = new Dictionary<byte, List<RoleEnum>>(); | ||
|
||
public static void RecordSessionRoles() { | ||
foreach (var player in PlayerControl.AllPlayerControls) { | ||
var playerId = player.PlayerId; | ||
var roleType = Role.GetRole(player)?.RoleType ?? RoleEnum.None; | ||
|
||
if (!_sessionRoleHistory.ContainsKey(playerId)) { | ||
_sessionRoleHistory[playerId] = new List<RoleEnum>(); | ||
} | ||
|
||
_sessionRoleHistory[playerId].Add(roleType); | ||
} | ||
} | ||
|
||
public static void Prefix() | ||
{ | ||
if (CustomGameOptions.WeightedRoleSelection) | ||
{ | ||
RecordSessionRoles(); // Record roles at the end of each game | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably happen at the start of the game and not the end as the final roles people end up with are not the same as those they initially were assigned and we only care about those original roles.
Additionally, I'm not sure how PlayerIds are handled in Among Us so doing it at game start may handle situations like disconnects better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, no this affect end game because you can see there is a harmony patch to patch the end game
[HarmonyPatch(typeof(EndGameManager), nameof(EndGameManager.Start))]
and about player id is a bit complicated
i don't think so that will make disconnects better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that currently it's targeting the end of the game, I'm suggesting that instead targeting the start of the game would make more sense due to the switching of roles and potentially disconnects (though the latter point you're saying doesn't matter). Conceptually it still makes more sense to me to save this stuff pretty much the moments it is generated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by "genereted" ?there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the original roles are randomly rolled and assigned.
i'm pretty sure when a player leaves the game, the player ids below the leaver's get pushed up, so the method of using a dict employing the use of player ids might not really work/be very ineffective. maybe add a case for disconnections? also if a session goes on for long enough you might end up with really large lists which might end up affecting performance so you might have to occasionally clear them, maybe clear a list if it exceeds 10 roles? |
@AlchlcDvl I like your thoughts on disconnections, agreed that some kind of handling there would be neat, could perform some kind of handshake where the host gives each client a uuid which they can hand back when reconnecting. As for really large lists, I think this is a bit of an overoptimization, as this is pretty trivial in both computational complexity and memory size, but maybe a limit of 100 in case something goes terribly wrong is reasonable, even then it's in the range of 1000-2000 iterations max which is still unnoticeable on anything that can run among us in the first place. |
yeah fair, i was just giving 10 as like a random number, even i felt like it was way too less lmao |
@Enduriel i have added The Role History List does nit exceed 100 entries and the method for more see the new code i still dont know if i should call The |
Some issues, you're not using |
oh yeah i didn't pay attention to that i will fix it soon i'm busy now |
@Enduriel i have fixed the issue |
Related to #252
Implements a weighted role selection system to adjust player roles based on previous game outcomes, enhancing the game experience by reducing role repetition for players across sessions.
CalculateWeightedRoleProbabilities
inAmongUsExtensions.cs
for future calculation of role probabilities based on session history, though the actual implementation is pending.MaxRoleHistorySizeList
is not used and throw an exceptionsif there any thing to do modify or something else feel free to ask me
@Enduriel