Created
July 15, 2011 15:40
-
-
Save robrocker7/1084925 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def assign_roles(self): | |
from apps.comm.models import Chatroom | |
import math | |
# walk through player size and set roles | |
query_users = self.userrole_set.order_by('?') | |
users = [u for u in query_users] | |
user_length = len(users) | |
# start with smallest group | |
roles = {} | |
required_roles = [] | |
random_roles = {'ONE': 0, 'TWO': 0, 'THREE': 0} | |
def add_random(val): | |
random_roles[val] = random_roles[val] + 1 | |
def remove_random(val) | |
random_roles[val] = random_roles[val] - 1 | |
if user_length >= 4: | |
roles['RANDOM_ONE'] = ['VILLAGER', | |
'WITCHDOCTOR', | |
'MARTYR', | |
'CURSED', | |
'PUTRID', | |
'VILLAGER'] | |
if user_length > 4: # 5 players | |
required_roles = ['WEREWOLF', | |
'PSYCHIC', | |
'PRIEST', | |
'BLESSED', | |
'RANDOM_ONE'] | |
if user_length > 5: # 6 players | |
required_roles.append('HALFBREED') | |
if user_length > 6: # 7 players | |
add_random('ONE') | |
if user_length > 7: # 8 players | |
required_roles.append('OCCULTIST') | |
if user_length > 8: # 9 players | |
add_random('ONE') | |
if user_length > 9: # 10 players | |
required_roles.append('WEREWOLF') | |
add_random('ONE') | |
if user_length >= 11: | |
roles['RANDOM_TWO'] = ['KINDRED', | |
'DOPPLEGANGER', | |
'HAUNTED', | |
'VILLAGER', | |
'VILLAGER', | |
'VILLAGER'] | |
if user_length > 10: # 11 players | |
remove_random('ONE') | |
add_random('TWO') | |
add_random('TWO') | |
if user_length > 11: # 12 players | |
add_random('ONE') | |
if user_length > 12: # 13 players | |
add_random('TWO') | |
if user_length > 13: # 14 players | |
add_random('ONE') | |
if user_length > 14: # 15 players | |
required_roles.append('WEREWOLF') | |
if user_length >= 18: | |
roles['RANDOM_THREE'] = ['DAYWALKER', | |
'VILLAGER', | |
'VILLAGER', | |
'VILLAGER'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment