Balance algorithm for the random variant
The following is written in pseudo code, but more or less conveys how to implement a balance algorithm for the random variant
//The following is an idea of how to implement balance within the constructs of how the current random
//game generation is coded. The general balancing idea is to limit the number of town power roles
//based on the ratio of mafia to players, and to account for the fact that mafia power roles reduce
//the value of certain town power roles in different ways, but do not inherently shift the balance to
//the mafia, i.e. a godfather reduces the value of a town cop but is useless when the town has no cop,
//likewise a mafia roleblocker or busdriver reduces the value of all town roles that have a night
//action, but is useless against daykilling vigs and bulletproof townies.
//The first thing that needs to be done is to modify the .xml file to include 3 different balance
//parameters for each town role (in addition to the already existing parameters of name and weight)
//that represent how the role adds (or subtracts) value from the town.
//These balance paramaters are as follows:
//copvalue: the degree to which the role contributes as a cop. This value would be 1 for a sane cop
//and 0 for every role that does not have a cop investigation. The value could be 0.25 for an insane
//cop (representing that they are still useful if they know they are insane) and 0 for naive and 0 for
//paranoid cops (more on those later)
//nightvalue: the degree to which the role contributes using NON-COP night actions. This value would
//be 0 for cops and roles without night actions, and a positive number for all roles with non-cop night
//actions that potentially benefit the town. For example, doctors, watchers, and trackers could have
//a value of 1, roleblockers could have a value of 0.75, bodyguards could have a value of 0.5, etc.
//These values are just rough examples and can be adjusted later.
//absolutevalue: the degree to which the role contributes regardless of what power roles the mafia has.
//This value would be 0 for cops and 0 for other town night action roles, and would have a positive
//value (for example 1) for bulletproof townies and daykilling vigs. This number would be a slight
//negative value for town roles that are worse than vanilla townies, for example millers, naive cops,
//paranoid cops, naive docs, etc. could have a value of -0.25.
//Here are some examples of how the new .xml file would look like
name: "Vanilla Townie"
weight: 80
copvalue: 0
nightvalue: 0
absolutevalue: 0
name: "Cop" (sane)
weight: 10
copvalue: 1
nightvalue: 0
absolutevalue: 0
name: "Doc" (sane)
weight: 10
copvalue: 0
nightvalue: 1
absolutevalue: 0
name: "Watcher"
weight: 5
copvalue: 0
nightvalue: 1
absolutevalue: 0
name: "Daykilling Vigilante"
weight: 4
copvalue: 0
nightvalue: 0
absolutevalue: 1
name: "Cop" (paranoid)
weight: 2
copvalue: 0
nightvalue: 0
absolutevalue: -0.25
//Next, the .xml file would need to be modified to include two balance parameters for each mafia role
//representing how much they fractionally reduce (1 being 100%) the value of different types of town
//powers in a baseline game where there is only 1 mafia (this value is later divided by the number
//of mafia in the game). The values are as follows:
//copreduction: the fractional amount the role reduces the value of a town cop in a game with 1 mafia.
//This value is 1 for godfathers (i.e. in a game with only one mafia who is a godfather, the value of
//a cop is reduced by 100%, in a gamewith two mafia with one godfather, the value of a cop is reduced
//by 50%, etc), and this value is 0.5 (reduction by 50% in a game of 1, 25% in a game of 2) for
//mafia roleblockers and framers. Mafia busdrivers could have a value of 0.8. The values can be
//adjusted between 0 and 1.
//nightreduction: the fractional amount the role reduces the value of non-cop town night actions in a
//game with 1 mafia. This value is 0 for godfathers and framers, and 0.5 for roleblockers. Mafia
//busdrivers could have a value of 0.8.
//Here are some examples of what the new .xml file could look like
name: "Mafia Goon"
weight: 80
copreduction: 0
nightreduction: 0
name: "Godfather"
weight: 10
copreduction: 1
nightreduction: 0
name: "Mafia Roleblocker"
weight: 10
copreduction: 0.5
nightreduction: 0.5
//Now comes the implementation of the balance parameters into the game generation:
//First determine a maximum and minimum balance value (a decimal value, not int value) based on the
//ratio of mafia players to number of players. The c9 setup will be used as a standard for the balance
//algorithm, i.e. in a 7 player game with 2 mafia, there can be 0-2 town power roles, and therefore
//would have a min balance value of 0 and max balance value of 2. As the percentage of mafia decreases
//these values will decrease as well. Here is an exemplary algorithm.
real maxbalance = nummafia/numtown * 7
real minbalance = maxbalance - 2
//so for example with 1 mafia in a game of 5 players, the balance range is from -3/5 to 7/5
//Now generate the mafia roles as currently implemented, but generate the mafia roles BEFORE generating
//the town roles. As the mafia roles are generated, keep track of the multipliers that will be applied
//to the town power roles as follows:
real copmultiplier = 1
real nightmultiplier = 1
for each mafiarole added {
copmultiplier = copmultiplier * (1 - mafiarole.
nightmultiplier = nightmultiplier * (1 - mafiarole.
}
//Now generate the town roles as currently implement, but generate the town roles AFTER generating the
//mafia roles. However, as the town roles are generated, if the generated town role would push
//the balance (after multiplier effects) either above the maxbalance or below the minbalance, DO NOT
//add the role to the town. Instead re-select the role until the addition of that role would not shift
//the balance outside the maxbalance or minbalance. Here is implementation:
real balance = 0
for each townrole selected {
if (minbalance <= balance + townrole.
townrole.
town.
balance = balance + townrole.
townrole.
}
else reselect townrole
}
//That should be all that is needed to implement a balance algorithm. If you are concerned about
//the potential for an infinite (or at least rather long) loop in the reselection of townroles, you
//can change the reselect command to selecting a vanilla townie instead.
Blueprint information
- Status:
- Complete
- Approver:
- None
- Priority:
- Undefined
- Drafter:
- GoEC
- Direction:
- Needs approval
- Assignee:
- Matthias Schröder
- Definition:
- Approved
- Series goal:
- None
- Implementation:
-
Implemented
- Milestone target:
- None
- Started by
- Matthias Schröder
- Completed by
- Matthias Schröder