forked from TheWaunaKeeganOrganization/Yahtzee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyahtzee_categories.py
71 lines (57 loc) · 1.34 KB
/
yahtzee_categories.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
from collections import Counter
def ones(d):
return 1*d.count(1)
def twos(d):
return 2*d.count(2)
def threes(d):
return 3*d.count(3)
def fours(d):
return 4*d.count(4)
def fives(d):
return 5*d.count(5)
def sixes(d):
return 6*d.count(6)
def threeOfAKind(d):
if max(Counter(d).itervalues())>=3:
return sum(d)
return 0
def fourOfAKind(d):
if max(Counter(d).itervalues())>=4:
return sum(d)
return 0
def fullHouse(d):
if (list(Counter(d).itervalues())[0]==3 and list(Counter(d).itervalues())[1]==2) or (list(Counter(d).itervalues())[0]==2 and list(Counter(d).itervalues())[1]==3):
return 25
return 0
def smallStraight(d):
s=min(d)
if s+1 in d and s+2 in d and s+3 in d:
return 30
return 0
def largeStraight(d):
s=min(d)
if s+1 in d and s+2 in d and s+3 in d and s+4 in d:
return 30
return 0
def yahtzee(d):
if d.count(d[0])==5:
return 50
return 0
def chance(d):
return sum(d)
def allCategories(d):
scores={}
scores["ones"]=ones(d)
scores["twos"]=twos(d)
scores["threes"]=threes(d)
scores["fours"]=fours(d)
scores["fives"]=fives(d)
scores["sixes"]=sixes(d)
scores["threeOfAKind"]=threeOfAKind(d)
scores["fourOfAKind"]=fourOfAKind(d)
scores["fullHouse"]=fullHouse(d)
scores["smallStraight"]=smallStraight(d)
scores["largeStraight"]=largeStraight(d)
scores["yahtzee"]=yahtzee(d)
scores["chance"]=chance(d)
return scores