-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Rework role distribution #6
Comments
Methods of distribution:
*1 There's also each after exclusion - meaning don't include the initial player count needed to activate it's condition. |
Remainder roles (or greedy roles as I sometimes call them) are intended to take the remaining slots of any game, but to do so requires the total ratio to be less than the certainty of 1 and for slots to not be taken up to begin with. Role slot allocation can be done in
Roles assigned with |
|
Depending on the active context used to explain how this is meant to work, the description of At the core of the distribution theory, there are two methods to deal roles to a group of players.
/** This contains the necessary data to *assemble* the role roster that is to be assigned to players. */
interface RoleData {
/** The type of role behaviour. */
type: RoleType;
/** The name of the role */
name: string;
/** Minimum number of players required to include this role. */
activation: number;
/** The physical chance the role will be included in the roster, after meeting the activation threshold. */
activationChance: number;
/** The absolute quantity of the role, after activiation. */
quantity: number;
/** Minimum number of roles to add, after activation. */
minimum: number;
/** Maximum number of players allowed to play this role. */
maximum: number;
/** Include the initial player count that was required to get the role. */
include: boolean;
/** The number of players required to add another role. */
each: number;
/** The target role to replace when called upon. */
replace: string;
/** The chance of the role being given to a player */
chance: number;
/** The type of chance behaviour */
chanceType: ChanceType;
/** The thresholds to add a new role. */
thresholds: number[];
} |
Role grouping:
Given that While I have no intention to continue working on the
|
If class RoleBuilder {
// ...
withRatio(ratio) {
// 1:R --> r:1
if (ratio > 1 || ratio < 0)
ratio = 1 - 1 / ratio;
this.data.each = ratio;
}
// ...
} |
For less than 0, abs the value... rather than also sending through this branch, which would return as a certain probability. ratio = Math.abs(ratio);
if (ratio > 1) // etc.
|
With references to the different methods to assign roles, assembling the role list itself is likely to remain as it is by iterating over its role entries, rather than over the player count (mainly for focus on efficiency and minimal time complexity). Swapping the loop target would likely increase the number of iterations needed to determine what the program should do (regardless of player count), and more likely to be inconsistent. |
class Role {
selectOne(players: number, currentRoles: string[]) {
const { name, type } = this.data
const isUnique = type === RoleType.UNIQUE; // new type?
if (Array.isArray(name)) {
const filteredRoles = name.filter(r => !currentRoles.includes(r));
// if (filteredRoles.length <= 1) filteredRoles[0]; // ?? undefined
return chance.pickone(filteredRoles);
} else {
return isUnique && currentRoles.includes(name) ? undefined : name;
}
}
} |
Ultimately, I give credit to WolfiaBot for it's implementation in Java for guiding me towards a solution. But I diverge from it's logic by allowing the roles themselves to decide how much they should allocate based on the values provided to them.
Detective
is added every 5 players, after at least 5 players are in game (not including said players).Werewolf
is added every 4 players.Villager
... and the program ends once it logs the role distribution of 1, 2 and 7 respectively.
It is theortically possible to implement this logic into the ratios by having the same failover, and I have no idea how the literal role allocation differs from ratio allocation... likely the same if it's using the same equations. It may also be possible to continue this by allowing multiple greedy roles before it terminates (removing the need for a break, but also offsetting the remaining allocation of roles to the end) - and requiring some sort of distribution code (literal split / round robin / or another ratio).
Code Source
https://github.com/wolfiabot/Wolfia/blob/5e84f31e/src/main/java/space/npstr/wolfia/game/mafia/MafiaInfo.java#L89
https://github.com/wolfiabot/Wolfia/blob/5e84f31e/src/main/java/space/npstr/wolfia/game/CharakterSetup.java#L30
The text was updated successfully, but these errors were encountered: