1
1
from collections import Counter
2
2
3
3
# Score categories
4
- YACHT = 50
5
- ONES = 1
6
- TWOS = 2
7
- THREES = 3
8
- FOURS = 4
9
- FIVES = 5
10
- SIXES = 6
4
+ ONES = "ONES"
5
+ TWOS = "TWOS"
6
+ THREES = "THREES"
7
+ FOURS = "FOURS"
8
+ FIVES = "FIVES"
9
+ SIXES = "SIXES"
11
10
FULL_HOUSE = "FULL_HOUSE"
12
11
FOUR_OF_A_KIND = "FOUR_OF_A_KIND"
13
- STRAIGHT = 30
12
+ STRAIGHT = "STRAIGHT"
14
13
LITTLE_STRAIGHT = "LITTLE_STRAIGHT"
15
14
BIG_STRAIGHT = "BIG_STRAIGHT"
16
15
CHOICE = "CHOICE"
16
+ YACHT = "YACHT"
17
+
18
+ # Score per category
19
+ scores = {
20
+ ONES : 1 ,
21
+ TWOS : 2 ,
22
+ THREES : 3 ,
23
+ FOURS : 4 ,
24
+ FIVES : 5 ,
25
+ SIXES : 6 ,
26
+ STRAIGHT : 30 ,
27
+ YACHT : 50 ,
28
+ }
17
29
18
30
def score_ones (dice ):
19
- return ONES * dice .count (1 )
31
+ return scores [ ONES ] * dice .count (1 )
20
32
21
33
def score_twos (dice ):
22
- return TWOS * dice .count (2 )
34
+ return scores [ TWOS ] * dice .count (2 )
23
35
24
36
def score_threes (dice ):
25
- return THREES * dice .count (3 )
37
+ return scores [ THREES ] * dice .count (3 )
26
38
27
39
def score_fours (dice ):
28
- return FOURS * dice .count (4 )
40
+ return scores [ FOURS ] * dice .count (4 )
29
41
30
42
def score_fives (dice ):
31
- return FIVES * dice .count (5 )
43
+ return scores [ FIVES ] * dice .count (5 )
32
44
33
45
def score_sixes (dice ):
34
- return SIXES * dice .count (6 )
46
+ return scores [ SIXES ] * dice .count (6 )
35
47
36
48
def score_full_house (dice ):
37
49
return sum (dice ) if sorted (set (Counter (dice ).values ())) == [2 , 3 ] else 0
@@ -47,16 +59,16 @@ def score_four_of_a_kind(dice):
47
59
return 0
48
60
49
61
def score_little_straight (dice ):
50
- return STRAIGHT if sorted (dice ) == [1 , 2 , 3 , 4 , 5 ] else 0
62
+ return scores [ STRAIGHT ] if sorted (dice ) == [1 , 2 , 3 , 4 , 5 ] else 0
51
63
52
64
def score_big_straight (dice ):
53
- return STRAIGHT if sorted (dice ) == [2 , 3 , 4 , 5 , 6 ] else 0
65
+ return scores [ STRAIGHT ] if sorted (dice ) == [2 , 3 , 4 , 5 , 6 ] else 0
54
66
55
67
def score_choice (dice ):
56
68
return sum (dice )
57
69
58
70
def score_yacht (dice ):
59
- return YACHT if len (set (dice )) == 1 else 0
71
+ return scores [ YACHT ] if len (set (dice )) == 1 else 0
60
72
61
73
def score (dice , category ):
62
74
if (category == ONES ):
0 commit comments