-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhanafuda_yaku.py
156 lines (124 loc) · 5.14 KB
/
hanafuda_yaku.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
from typing import List, Callable, Tuple, Dict
from hanafuda_card import Card, Month, Category, deck
class Yaku:
def __init__(self, check_combo:Callable[[List[Card]], int]):
self.name = check_combo.__name__[6:]
self.check_combo = check_combo
# hikaris
crane_and_sun = Card(Month.JANUARY, Category.HIKARI, 'sm_Hana-01-01.jpg')
curtain = Card(Month.MARCH, Category.HIKARI, 'sm_Hana-03-01.jpg')
full_moon = Card(Month.AUGUST, Category.HIKARI, 'sm_Hana-08-01.jpg')
ono_no_michikaze = Card(Month.NOVEMBER, Category.HIKARI, 'sm_Hana-11-01.jpg')
chinese_phenoix = Card(Month.DECEMBER, Category.HIKARI, 'sm_Hana-12-01.jpg')
goko = [
crane_and_sun,
curtain,
full_moon,
ono_no_michikaze,
chinese_phenoix
]
shiko = [
crane_and_sun,
curtain,
full_moon,
chinese_phenoix
]
# sake cup
sake_cup = Card(Month.SEPTEMBER, Category.SAKAZUKI, 'sm_Hana-09-01.jpg')
# inoshikacho
butterfiles = Card(Month.JUNE, Category.TANE, 'sm_Hana-06-01.jpg')
boar = Card(Month.JULY, Category.TANE, 'sm_Hana-07-01.jpg')
deer = Card(Month.OCTOBER, Category.TANE, 'sm_Hana-10-01.jpg')
inoshikacho = [butterfiles, boar, deer]
# tanzakus
poetry_tanzaku = [
Card(Month.JANUARY, Category.TANZAKU, 'sm_Hana-01-02.jpg'),
Card(Month.FEBRUARY, Category.TANZAKU, 'sm_Hana-02-02.jpg'),
Card(Month.MARCH, Category.TANZAKU, 'sm_Hana-03-02.jpg'),
]
blue_tanzaku = [
Card(Month.JUNE, Category.TANZAKU, 'sm_Hana-06-02.jpg'),
Card(Month.SEPTEMBER, Category.TANZAKU, 'sm_Hana-09-02.jpg'),
Card(Month.OCTOBER, Category.TANZAKU, 'sm_Hana-10-02.jpg'),
]
def count_intersection(point_file:List[Card], combo:List[Card]) -> int:
intersection = [card for card in point_file if card in combo]
return len(intersection)
def check_goko(point_pile:List[Card]) -> int:
return 15 if all(card in point_pile for card in goko) else 0
def check_shiko(point_pile:List[Card]) -> int:
return 8 if (ono_no_michikaze not in point_pile) and count_intersection(point_pile, shiko) == 4 else 0
def check_ameshiko(point_pile:List[Card]) -> int:
return 7 if (ono_no_michikaze in point_pile) and count_intersection(point_pile, shiko) == 3 else 0
def check_sanko(point_pile:List[Card]) -> int:
return 6 if (ono_no_michikaze not in point_pile) and count_intersection(point_pile, shiko) == 3 else 0
def check_tsukimizake(point_pile:List[Card]) -> int:
return 5 if (sake_cup in point_pile) and (full_moon in point_pile) else 0
def check_hanamizake(point_pile:List[Card]) -> int:
return 5 if (sake_cup in point_pile) and (curtain in point_pile) else 0
def check_inoshikacho(point_pile:List[Card]) -> int:
return 5 if all(card in point_pile for card in inoshikacho) else 0
def check_tane(point_pile:List[Card]) -> int:
tane_count = len([card for card in point_pile if card.category == Category.TANE or card.category == Category.SAKAZUKI])
return tane_count - 4 if tane_count >= 5 else 0
def check_akatan(point_pile:List[Card]) -> int:
return 5 if all(card in point_pile for card in poetry_tanzaku) else 0
def check_aotan(point_pile:List[Card]) -> int:
return 5 if all(card in point_pile for card in blue_tanzaku) else 0
def check_tanzaku(point_pile:List[Card]) -> int:
tanzaku_count = len([card for card in point_pile if card.category == Category.TANZAKU])
return tanzaku_count - 4 if tanzaku_count >= 5 else 0
def check_tsukifuda(point_pile:List[Card]) -> int:
tsukifuda_count = len([month for month in Month if len([card for card in point_pile if card.month == month]) == 4])
return tsukifuda_count * 4
def check_kasu(point_pile:List[Card]) -> int:
kasu_count = len([card for card in point_pile if card.category == Category.KASU or card.category == Category.SAKAZUKI])
return kasu_count - 9 if kasu_count >= 10 else 0
# Edit this list to add/remove functions
check_combo_functions = [
check_goko,
check_shiko,
check_ameshiko,
check_sanko,
check_tsukimizake,
check_hanamizake,
check_inoshikacho,
check_tane,
check_akatan,
check_aotan,
check_tanzaku,
# check_tsukifuda,
check_kasu
]
yakus = [
Yaku(check_combo_function)
for check_combo_function in check_combo_functions
]
def check_all_yakus(point_pile:List[Card]) -> Tuple[int, List[str]]:
obtained_yakus = []
sum_point = 0
for yaku in yakus:
yaku_point = yaku.check_combo(point_pile)
if yaku_point:
sum_point += yaku_point
obtained_yakus.append(yaku.name)
return sum_point, obtained_yakus
# print(check_all_yakus(deck))
# print(check_all_yakus(deck[:10]))
def point_pile_summary(point_pile:List[Card]) -> Dict[Category, int]:
summary = {}
for card in point_pile:
if card.category == Category.SAKAZUKI:
if Category.TANE not in summary:
summary[Category.TANE] = 1
else:
summary[Category.TANE] += 1
if Category.KASU not in summary:
summary[Category.KASU] = 1
else:
summary[Category.KASU] += 1
elif card.category not in summary:
summary[card.category] = 1
else:
summary[card.category] += 1
return summary