/
Perudo Attempt inc aces and palifico.py
316 lines (314 loc) · 15 KB
/
Perudo Attempt inc aces and palifico.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
from random import randint as roll
import numpy as np
def binomial_cdf(x,n,p):
cdf = 0
b = 0
for k in range(x):
if k > 0:
b += + np.log(n-k+1) - np.log(k)
log_pmf_k = b + k * np.log(p) + (n-k) * np.log(1-p)
cdf += np.exp(log_pmf_k)
return 1- cdf
def rolling():
for x in range(dice):
x=roll(1,6)
turn.append(x)
print('your roll is: ',turn)
for x in range(compdice):
x=roll(1,6)
compturn.append(x)
def palifico():
if (dice==1 or compdice==1) and winpalifico==False:
return True
else:
return False
def get_mode(numbers): #this is to find max. mode, for consideration re: aces call
counts = {k:numbers.count(k) for k in set(numbers)}
modes = sorted(dict(filter(lambda x: x[1] == max(counts.values()), counts.items())).keys())
if modes[-1]==1:
return modes[-2]
else:
return modes[-1]
print('Welcome to Perudo. Here is your roll: ')
dice=5
compdice=5
winpalifico = False
while (dice>0 and compdice>0):
if palifico() is True:
print('This is a Palifico Round!')
dudo = False
turn=[]
compturn=[]
rolling()
totalturn=compturn+turn
prevquant=0
prevnumb=0
while dudo is False:
print('prevquant: ',prevquant, 'prevnumb: ',prevnumb)
if prevquant!=0:
dudoCall=input('Do you call dudo? (y/n) ')
if dudoCall=='y':
if totalturn.count(prevnumb)-prevquant>=0:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ',totalturn.count(prevnumb),prevnumb,'s')
print('you lose')
dice-=1
dudo = True
else:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(prevnumb),prevnumb,'s')
print('you win')
compdice-=1
dudo = True
winpalifico=True
elif dudoCall=='n':
try:
quant=int(input('what is your call quantity? '))
numb=int(input('what is your number call? '))
except ValueError:
print('you have not made a valid choice. please try again and use numbers this time')
continue
if quant<prevquant:
print('your call is invalid (higher quantity needed). Please try again')
continue
elif numb!=prevnumb:
print('your call is invalid (cannot change number). Please try again')
continue
elif numb>6:
print('your call is invalid (can only call 1-6). Please try again')
continue
elif binomial_cdf(quant-compturn.count(numb),len(turn),0.16666666)<0.3:
print('Computer calls Dudo')
print('total number is: ',totalturn.count(numb))
if totalturn.count(numb)-quant>=0:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(numb),numb,'s')
print('you win')
compdice-=1
dudo = True
else:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(numb),numb,'s')
print('you lose')
dice-=1
dudo = True
else:
try:
quant=int(input('what is your call quantity? '))
numb=int(input('what is your number call? '))
except ValueError:
print('you have not made a valid choice. please try again and use numbers this time')
continue
if binomial_cdf(quant-compturn.count(numb),len(turn),0.1666666666)<0.3:
print('Computer calls Dudo')
if totalturn.count(numb)-quant>=0:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(numb),numb,'s')
print('you win')
compdice-=1
dudo = True
winpalifico=True
else:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(numb),numb,'s')
print('you lose')
dice-=1
dudo = True
else:
print('computer is thinking...')
print('Computer calls: ',
'quantity: ',quant+1,
'number: ',numb)
prevquant=quant+1
prevnumb=numb
print(prevquant)
dudo = False
turn=[]
compturn=[]
rolling()
totalturn=compturn+turn
prevquant=0
prevnumb=0
while dudo is False:
print('prevquant: ',prevquant, 'prevnumb: ',prevnumb)
if prevquant!=0:
dudoCall=input('Do you call dudo? (y/n) ')
if dudoCall=='y':
if totalturn.count(prevnumb)+totalturn.count(1)-prevquant>=0:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ',totalturn.count(prevnumb),prevnumb,'s')
print('and ', totalturn.count(1), 'aces')
print('you lose')
dice-=1
dudo = True
else:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(prevnumb),prevnumb,'s')
print('and', totalturn.count(1), 'aces')
print('you win')
compdice-=1
dudo = True
elif dudoCall=='n':
try:
quant=int(input('what is your call quantity? '))
numb=int(input('what is your number call? '))
except ValueError:
print('you have not made a valid choice. please try again and use numbers this time')
continue
if quant<prevquant and numb!=1:
print('your call is invalid (higher quantity needed). Please try again')
continue
elif quant==prevquant and numb<=prevnumb and numb!=1:
print('your call is invalid (higher number needed). Please try again')
continue
elif numb>6:
print('your call is invalid (can only call 1-6). Please try again')
continue
elif quant<(prevquant*0.5) and numb==1:
print('your call is invalid (aces call must be greater than half the previous call. Please try again')
continue
elif numb==1:
favnumb=get_mode(compturn)
if binomial_cdf(quant-compturn.count(numb), len(turn), 0.16666666)<0.4:
print('Computer calls Dudo')
print('total number is: ',totalturn.count(numb))
if totalturn.count(numb)-quant>=0:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(numb),numb,'s')
print('you win')
compdice-=1
dudo = True
else:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(numb),numb,'s')
print('you lose')
dice-=1
dudo = True
elif binomial_cdf(quant+1-compturn.count(numb),len(turn), 0.16666666)>=binomial_cdf((2*quant)+1-favnumb,len(turn),0.3333333):
print('computer is thinking...')
print('Computer calls: ',
'quantity: ',quant+1,
'number: ',numb)
prevquant=quant+1
prevnumb=numb
print(prevquant)
else:
print('Computer calls: ',
'quantity: ',2*quant+1,
'number: ',get_mode(compturn))
prevquant=2*quant+1
prevnumb=get_mode(compturn)
print(prevquant)
elif binomial_cdf(quant-compturn.count(numb)-compturn.count(1),len(turn),0.33333333)<0.4:
print('Computer calls Dudo')
print('total number is: ',totalturn.count(numb))
print('total number of aces is: ',totalturn.count(1))
if totalturn.count(numb)+totalturn.count(1)-quant>=0:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(numb)+totalturn.count(1),numb,'s')
print('you win')
compdice-=1
dudo = True
else:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(numb)+totalturn.count(1),numb,'s')
print('you lose')
dice-=1
dudo = True
else:
print('computer is thinking...')
if numb<=5:
if binomial_cdf((quant+1)-compturn.count(numb)-compturn.count(1),len(turn),0.3333333)>binomial_cdf(quant-compturn.count(numb+1)-compturn.count(1),len(turn),0.33333333):
print('Computer calls: ',
'quantity: ',quant+1,
'number: ',numb)
prevquant=quant+1
prevnumb=numb
print(prevquant, 'line 149')
else:
print('Computer calls: ',
'quantity: ',quant,
'number: ',numb+1)
prevnumb=numb+1
prevquant=quant
print(prevnumb, 'line 156')
else:
print('Computer calls: ',
'quantity: ',quant+1,
'number: ',get_mode(compturn))
prevnumb=get_mode(compturn)
prevquant=quant+1
print(prevnumb, 'line 163')
else:
try:
quant=int(input('what is your call quantity? '))
numb=int(input('what is your number call? '))
except ValueError:
print('you have not made a valid choice. please try again and use numbers this time')
continue
if binomial_cdf(quant-compturn.count(numb)-compturn.count(1),len(turn),0.333333)<0.4:
print('Computer calls Dudo')
if totalturn.count(numb)+totalturn.count(1)-quant>=0:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(numb),numb,'s')
print('and there are ', totalturn.count(1), 'aces')
print('you win')
compdice-=1
dudo = True
else:
print('You rolled: ',turn)
print('Computer rolled: ', compturn)
print('That means there are ', totalturn.count(numb),numb,'s')
print('and there are ', totalturn.count(1), 'aces')
print('you lose')
dice-=1
dudo = True
else:
print('computer is thinking...')
if quant>=0.6*(len(turn)):
if binomial_cdf((quant+1)-compturn.count(numb)-compturn.count(1)-int(0.6*(len(turn))),len(turn),0.3333333)>=binomial_cdf(quant-compturn.count(numb+1)-compturn.count(1),len(turn),0.33333333) and quant<6:
print('Computer calls: ',
'quantity: ',quant+1,
'number: ',numb)
prevquant=quant+1
prevnumb=numb
elif binomial_cdf((quant+1)-compturn.count(numb)-compturn.count(1),len(turn),0.33333333)==binomial_cdf(quant-compturn.count(numb+1)-compturn.count(1),len(turn),0.3333333):
print('Computer calls: ',
'quantity: ',quant+1,
'number: ',numb)
prevquant=quant+1
prevnumb=numb
else:
print('Computer calls: ',
'quantity: ',quant,
'number: ',numb+1)
prevnumb=numb+1
prevquant=quant
else:
if binomial_cdf((quant+1)-compturn.count(numb)-compturn.count(1),len(turn),0.33333333)>=binomial_cdf(quant-compturn.count(numb+1)-compturn.count(1),len(turn),0.33333333) and quant<6:
print('Computer calls: ',
'quantity: ',quant+1,
'number: ',numb)
prevquant=quant+1
prevnumb=numb
print(prevquant)
else:
print('Computer calls: ',
'quantity: ',quant+1,
'number: ',get_mode(compturn))
prevnumb=get_mode(compturn)
prevquant=quant+1
print('you have reached the end')