Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
main.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
yaku_list = [
|
4 |
-
"
|
5 |
"海底撈月", "河底撈魚", "嶺上開花", "槍槓",
|
6 |
"ダブル立直", "七対子", "混全帯幺九", "一気通貫",
|
7 |
"三色同順", "三色同刻", "三槓子", "対々和",
|
@@ -13,10 +13,10 @@ yaku_list = [
|
|
13 |
"地和",
|
14 |
]
|
15 |
|
16 |
-
|
17 |
-
"
|
18 |
"海底撈月":1, "河底撈魚":1, "嶺上開花":1, "槍槓":1,
|
19 |
-
"ダブル立直":2, "七対子":
|
20 |
"三色同順":2, "三色同刻":2, "三槓子":2, "対々和":2,
|
21 |
"三暗刻":2, "小三元":2, "混老頭":2, "二盃口":3,
|
22 |
"純全帯幺九":3, "混一色":3, "清一色":6, "国士無双":13,
|
@@ -26,32 +26,96 @@ yaku_hand = {
|
|
26 |
"地和":13,
|
27 |
}
|
28 |
|
29 |
-
|
30 |
-
|
|
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
def calculate_score(selected_yaku):
|
33 |
hand = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
for yaku in selected_yaku:
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
if hand > 13:
|
38 |
hand = 13
|
39 |
-
# 少数点以下切り捨て
|
40 |
-
elif hand > 4:
|
41 |
-
hand = int(hand)
|
42 |
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
def mahjong_score_interface(selected_yaku):
|
48 |
-
hand, parent_ron_score, children_ron_score = calculate_score(selected_yaku)
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
翻数: {hand}
|
52 |
親(ロン): {parent_ron_score}
|
53 |
子(ロン): {children_ron_score}
|
54 |
-
(役満以上は全て13
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
"""
|
56 |
|
57 |
yaku_checkboxes = [gr.Checkbox(label=yaku) for yaku in yaku_list]
|
@@ -59,8 +123,8 @@ yaku_checkboxes = [gr.Checkbox(label=yaku) for yaku in yaku_list]
|
|
59 |
interface = gr.Interface(
|
60 |
fn=mahjong_score_interface,
|
61 |
inputs=[gr.components.CheckboxGroup(choices=yaku_list, label="役を選択")],
|
62 |
-
outputs="
|
63 |
-
title="
|
64 |
)
|
65 |
|
66 |
-
interface.launch(
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
yaku_list = [
|
4 |
+
"門前清自摸和", "立直", "一発", "ドラ", "平和","役牌", "風牌",
|
5 |
"海底撈月", "河底撈魚", "嶺上開花", "槍槓",
|
6 |
"ダブル立直", "七対子", "混全帯幺九", "一気通貫",
|
7 |
"三色同順", "三色同刻", "三槓子", "対々和",
|
|
|
13 |
"地和",
|
14 |
]
|
15 |
|
16 |
+
yaku_hand_dict = {
|
17 |
+
"門前清自摸和":1, "立直":1, "一発":1, "ドラ":1, "平和":1,"役牌":1,"風牌":1,
|
18 |
"海底撈月":1, "河底撈魚":1, "嶺上開花":1, "槍槓":1,
|
19 |
+
"ダブル立直":2, "七対子":2, "混全帯幺九":2, "一気通貫":2,
|
20 |
"三色同順":2, "三色同刻":2, "三槓子":2, "対々和":2,
|
21 |
"三暗刻":2, "小三元":2, "混老頭":2, "二盃口":3,
|
22 |
"純全帯幺九":3, "混一色":3, "清一色":6, "国士無双":13,
|
|
|
26 |
"地和":13,
|
27 |
}
|
28 |
|
29 |
+
#ロン
|
30 |
+
parent_ron_points = {1:2000, 2:3900, 3:7700, 4:12000,5:12000,6:18000,7:18000,8:24000,9:24000,10:24000,11:36000,12:36000,13:48000}
|
31 |
+
children_ron_points = {1:1300, 2:2600, 3:5200, 4:8000,5:8000,6:12000,7:12000,8:16000,9:16000,10:16000,11:24000,12:24000,13:32000}
|
32 |
|
33 |
+
parent_pinhu_ron_points = {1:1500, 2:2900, 3:5800}
|
34 |
+
children_pinhu_ron_points = {1:1000, 2:2000, 3:3900}
|
35 |
+
|
36 |
+
parent_seven_pairs_ron_points = {2:2400, 3:4800, 4:9600}
|
37 |
+
children_seven_pairs_ron_points = {2:1600, 3:3200, 4:6400}
|
38 |
+
|
39 |
+
#ツモ
|
40 |
+
parent_tumo_points = {1:500, 2:1000, 3:2000, 4:4000,5:4000,6:6000,7:6000,8:8000,9:8000,10:8000,11:12000,12:12000,13:16000}
|
41 |
+
children_tumo_points = {1:"300-500", 2:"500-1000", 3:"1000-2000", 4:"2000-4000",5:"2000-4000",6:"3000-6000",7:"3000-6000",8:"4000-8000",9:"4000-8000",10:"4000-8000",11:"6000-12000",12:"6000-12000",13:"8000-16000"}
|
42 |
+
|
43 |
+
parent_pinhu_tumo_points = {2:700, 3:1300, 4:2600}
|
44 |
+
children_pinhu_tumo_points = {2:"400-700", 3:"700-1300", 4:"1300-2600"}
|
45 |
+
|
46 |
+
parent_seven_pairs_tumo_points = {3:1600, 4:3200}
|
47 |
+
children_seven_pairs_tumo_points = {3:"800-1600", 4:"1600-3200"}
|
48 |
+
|
49 |
+
|
50 |
+
#役から翻数と親子の点数を計算する関数
|
51 |
def calculate_score(selected_yaku):
|
52 |
hand = 0
|
53 |
+
flag_pinhu = False
|
54 |
+
flag_seven_pairs = False
|
55 |
+
flag_tumo = False
|
56 |
+
|
57 |
+
parent_tumo_score, children_tumo_score, parent_ron_score, children_ron_score = 0, 0, 0, 0
|
58 |
+
|
59 |
for yaku in selected_yaku:
|
60 |
+
if yaku == "平和":
|
61 |
+
flag_pinhu = True
|
62 |
+
elif yaku == "七対子":
|
63 |
+
flag_seven_pairs = True
|
64 |
+
elif yaku == "門前清自摸和":
|
65 |
+
flag_tumo = True
|
66 |
+
hand += yaku_hand_dict[yaku] # 各役の翻数を加算
|
67 |
+
|
68 |
+
if flag_pinhu and flag_seven_pairs:
|
69 |
+
return -1, parent_tumo_score, children_tumo_score, parent_ron_score, children_ron_score
|
70 |
+
|
71 |
if hand > 13:
|
72 |
hand = 13
|
|
|
|
|
|
|
73 |
|
74 |
+
if flag_tumo:
|
75 |
+
parent_tumo_score, children_tumo_score = parent_tumo_points[hand], children_tumo_points[hand]
|
76 |
+
if hand <=4:
|
77 |
+
if flag_pinhu:
|
78 |
+
parent_tumo_score, children_tumo_score = parent_pinhu_tumo_points[hand], children_pinhu_tumo_points[hand]
|
79 |
+
elif flag_seven_pairs:
|
80 |
+
parent_tumo_score, children_tumo_score = parent_seven_pairs_tumo_points[hand], children_seven_pairs_tumo_points[hand]
|
81 |
+
|
82 |
+
else:
|
83 |
+
parent_ron_score, children_ron_score = parent_ron_points[hand], children_ron_points[hand]
|
84 |
+
if hand <=4:
|
85 |
+
if flag_pinhu:
|
86 |
+
parent_ron_score, children_ron_score = parent_pinhu_ron_points[hand], children_pinhu_ron_points[hand]
|
87 |
+
elif flag_seven_pairs:
|
88 |
+
parent_ron_score, children_ron_score = parent_seven_pairs_ron_points[hand], children_seven_pairs_ron_points[hand]
|
89 |
+
|
90 |
+
return hand, parent_tumo_score, children_tumo_score, parent_ron_score, children_ron_score
|
91 |
|
92 |
+
#役と翻数をテキストで表示するための文字列を作る関数
|
93 |
+
def join_yaku_hand(selected_yaku):
|
94 |
+
yaku_hand_text = ""
|
95 |
+
for yaku in selected_yaku:
|
96 |
+
yaku_hand_text += f"{yaku}({yaku_hand_dict[yaku]})"
|
97 |
+
return yaku_hand_text
|
98 |
|
99 |
|
100 |
def mahjong_score_interface(selected_yaku):
|
101 |
+
hand, parent_tumo_score, children_tumo_score, parent_ron_score, children_ron_score = calculate_score(selected_yaku)
|
102 |
+
yaku_hand_text = join_yaku_hand(selected_yaku)
|
103 |
+
if hand == -1:
|
104 |
+
return f"選択された役({yaku_hand_text})は同時に成立できません。"
|
105 |
+
elif parent_tumo_score == 0:
|
106 |
+
return f"""
|
107 |
+
選択された役: {yaku_hand_text}
|
108 |
翻数: {hand}
|
109 |
親(ロン): {parent_ron_score}
|
110 |
子(ロン): {children_ron_score}
|
111 |
+
(役満以上は全て13翻とした。)
|
112 |
+
"""
|
113 |
+
return f"""
|
114 |
+
選択された役: {yaku_hand_text}
|
115 |
+
翻数: {hand}
|
116 |
+
親(ツモ): {parent_tumo_score}オール
|
117 |
+
子(ツモ): {children_tumo_score}
|
118 |
+
(役満以上は全て13翻とした。)
|
119 |
"""
|
120 |
|
121 |
yaku_checkboxes = [gr.Checkbox(label=yaku) for yaku in yaku_list]
|
|
|
123 |
interface = gr.Interface(
|
124 |
fn=mahjong_score_interface,
|
125 |
inputs=[gr.components.CheckboxGroup(choices=yaku_list, label="役を選択")],
|
126 |
+
outputs=gr.components.Textbox(label="翻数と親子の点数"),
|
127 |
+
title="簡易版面前麻雀点数計算アプリ"
|
128 |
)
|
129 |
|
130 |
+
interface.launch()
|