Created
July 15, 2011 16:37
-
-
Save robrocker7/1085038 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, user_length=None): | |
from apps.comm.models import Chatroom | |
import math | |
import random | |
# walk through player size and set roles | |
query_users = self.userrole_set.order_by('?') | |
users = [u for u in query_users] | |
if user_length is None: | |
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 | |
def compile_roles(): | |
lrole = required_roles | |
rlrole = [] | |
if(random_roles['ONE']): | |
rlrole.extend(random.sample(roles['RANDOM_ONE'], random_roles['ONE'])) | |
if(random_roles['TWO']): | |
rlrole.extend(random.sample(roles['RANDOM_TWO'], random_roles['TWO'])) | |
if(random_roles['THREE']): | |
lrole.extend(random.sample(roles['RANDOM_THREE'], random_roles['THREE'])) | |
if 'KINDRED' in rlrole: | |
def add_kindred(l): | |
random.shuffle(l) | |
if l[0] == 'KINDRED': | |
add_kindred(l) | |
l.pop(0) | |
l.append('KINDRED') | |
return l | |
rlrole = add_kindred(rlrole) | |
lrole.extend(rlrole) | |
return lrole | |
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'] | |
add_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') | |
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 > 15: # 16 players | |
add_random('TWO') | |
if user_length > 16: # 17 players | |
add_random('ONE') | |
if user_length >= 18: | |
roles['RANDOM_THREE'] = ['DAYWALKER', | |
'VILLAGER', | |
'VILLAGER', | |
'VILLAGER', | |
'HIGHLANDER'] | |
if user_length > 17: # 18 players | |
remove_random('ONE') | |
add_random('THREE') | |
add_random('THREE') | |
if user_length > 18: # 19 players | |
add_random('THREE') | |
if user_length > 19: # 20 players | |
required_roles.append('WEREWOLF') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment