-
Notifications
You must be signed in to change notification settings - Fork 0
/
16_2.py
39 lines (34 loc) · 1.11 KB
/
16_2.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
import random
def rollDie():
return random.choice([1,2,3,4,5,6])
class CrapsGame(object):
def __init__(self):
self.passWins, self.passLosses = 0, 0
self.dpWins, self.dpLosses, self.dpPushes = 0, 0, 0
def playHand(self):
throw = rollDie() + rollDie()
if throw == 7 or throw == 11:
self.passWins += 1
self.dpLosses += 1
elif throw == 2 or throw == 3 or throw == 12:
self.passLosses += 1
if throw == 12:
self.dpPushes += 1
else:
self.dpWins += 1
else:
point = throw
while True:
throw = rollDie() + rollDie()
if throw == point:
self.passWins += 1
self.dpLosses += 1
break
elif throw == 7:
self.passLosses += 1
self.dpWins += 1
break
def passResults(self):
return (self.passWins, self.passLosses)
def dpResults(self):
return (self.dpWin, self.dpLosses, self.dpPushes)