-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
69 lines (57 loc) · 1.33 KB
/
main.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
import numpy as np
####
# Init
vals = np.array([0,1,2,4,5,6])
D = np.zeros(5) # dummy
####
# Aux f'ns
def roll_them(D):
return vals[np.random.randint(0, 6, len(D))]
####
# Policy f'ns
def policy(D,kind=None):
'''
Return the indices of dice to take.
:param D: sorted int list of dice
:param kind: string policy kind
:return: int list of dice indexes to take
'''
global force_taketwo
if kind is None:
exit('Error: please select a policy.')
# forced takes
if len(D) == 1:
return [0]
if force_taketwo:
force_taketwo = False
return [0,1]
if kind == 'take_none':
return []
elif kind == 'take_one':
return [0]
elif kind == 'take_two':
return [0,1]
else:
exit('Error: invalid policy kind.')
####
# Main
score = 0
force_taketwo = False
while len(D) > 0:
# roll
print('Roll---------------')
D = np.sort(roll_them(D))
print(D)
# decide which dice to keep
keeping = policy(D,kind='take_none')
if len(keeping) > 0:
print('Keeping: %s' % D[keeping])
# update score
score += np.sum(D[keeping])
# update D
D = np.delete(D,keeping)
print('Score: %i' % score)
else:
force_taketwo = True
print('-------------------')
print('FINAL SCORE: %i' % score)