-
Notifications
You must be signed in to change notification settings - Fork 1
/
distributionfunctions.py
73 lines (67 loc) · 2.9 KB
/
distributionfunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import random
import datetime
from bot import Bot
from config import playerExceptions, ignorePlayers
from exception import NoPlayerFoundException
def randDownRandPlayers(**kwargs):
"""
kwargs -> None
bot: Bot | the bot to which we need to assign players
eligiblePlayers: ListOfTuples | List of distribution-eligible
players. Format: (firstName, lastName, 3digitTeamAbbreviation)
activeDate: datetimedate | date for which we are making selections
Randomly decides whether or not to doubleDown, and randomly chooses
players to assign to bot. Returns the assigned players
"""
print "RANDOM DOWN"
# Update the bot and return the players
# import pdb
# pdb.set_trace()
return staticDownRandPlayers( bot=kwargs['bot'],
eligiblePlayers=kwargs['eligiblePlayers'],
doubleDown=random.choice((True, False)) )
def staticDownRandPlayers(**kwargs):
"""
kwargs -> None
bot: Bot | the bot to which we are assigning playres
eligiblePlayers: ListOfTuples | List of distribution-eligible
players. Format: (firstName, lastName, 3digitTeamAbbreviation)
doubleDown: bool | True if its a double down, False if its a single Down
Given a type of Down, randomly chooses playres to assign to bot. Returns
the assigned players
"""
print "STATIC DOWN : {}".format(kwargs['doubleDown'])
## check arguments
assert type(kwargs['bot'] == Bot)
assert type(kwargs['eligiblePlayers'] == list)
assert len(kwargs['eligiblePlayers']) != 0
assert type(kwargs['doubleDown'] == bool)
# Pseudo-randomly choose playres
global ignorePlayers # list of players to ignore
global playerExceptions # number of NoPlayerFoundExceptions for each player
print "eP: {}".format(kwargs['eligiblePlayers'])
print "iP: {}".format(ignorePlayers)
print "pE: {}".format(playerExceptions)
try:
p1 = random.choice(kwargs['eligiblePlayers'])
if kwargs['doubleDown'] and (len(kwargs['eligiblePlayers']) != 1):
p2 = p1
while (p1 == p2):
p2 = random.choice(kwargs['eligiblePlayers'])
else:
p2 = ()
# Assign the players to the bot and return them to the caller
kwargs['bot'].choose_players(p1=p1, p2=p2)
return p1, p2
except NoPlayerFoundException as e:
## Add player to ignorePlayers, if necessary
for player in (p1, p2):
if (player in playerExceptions.keys()) and \
(playerExceptions[player] == 10) and \
(player not in ignorePlayers):
ignorePlayers.append(player)
e.args += (' with players {} and {}'.format(p1, p2),)
raise e
except Exception as e:
e.args += (' with players {} and {}'.format(p1, p2),)
raise e