-
Notifications
You must be signed in to change notification settings - Fork 0
/
Die.py
74 lines (56 loc) · 1.44 KB
/
Die.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
import random
class Die:
def __init__(self):
self.value = random.randint(1,6)
def roll(self):
self.value = random.randint(1,6)
def getValue(self):
return self.value
def scoreAces( hand ):
return hand.count(1)*1
def score2s( hand ):
return hand.count(2)*2
def score3s( hand ):
return hand.count(3)*3
def score4s( hand ):
return hand.count(4)*4
def score5s( hand ):
return hand.count(5)*5
def score6s( hand ):
return hand.count(6)*6
def score3OfaKind( hand ):
counts = [hand.count(x) for x in range(1,7)]
if 3 in counts:
return sum(hand)
return 0
def score4OfaKind( hand ):
counts = [hand.count(x) for x in range(1,7)]
if 4 in counts:
return sum(hand)
return 0
def scoreFullHouse( hand ):
counts = [hand.count(x) for x in range(1,7)]
if 2 in counts and 3 in counts:
return 25
return 0
def scoreSmallStraight( hand ):
hand.sort()
diffs = [str(hand[i+1]-hand[i]) for i in range(0,4)]
diffs = ''.join(diffs)
diffs = diffs.replace("0", "")
if "111" in diffs:
return 30
else:
return 0
def scoreLargeStraight( hand ):
hand.sort()
if [hand[i+1]-hand[i] for i in range(0,4)] == [1,1,1,1]:
return 40
return 0
def scoreYahtzee( hand ):
counts = [hand.count(x) for x in range(1,7)]
if 5 in counts:
return 50
return 0
def scoreChance( hand):
return sum(hand)