@@ -66,19 +66,22 @@ def update(self, mjai_msg, state):
66
66
for i in range (3 ):
67
67
self .consumes [i ].update (TILE_2_UNICODE_ART_RICH ["?" ])
68
68
self .weight .update ("0.0" )
69
+ self .app .rpc_server .draw_top3 ([self .recommand_idx , "?" , "?" , "?" , "?" , 0.0 ])
69
70
return
70
71
recommand = mjai_msg ['meta' ][self .recommand_idx ]
71
72
for action_class in self .action .classes :
72
73
if "action_" in action_class :
73
74
self .action .remove_class (action_class )
74
75
self .weight .update (f"{ (recommand [1 ]* 100 ):.2f} " )
76
+ weight_text = f"{ (recommand [1 ]* 100 ):.2f} %"
75
77
if recommand [0 ] in TILE_LIST :
76
78
self .action .label = recommand [0 ]
77
79
self .action .add_class ("action_" + recommand [0 ])
78
80
self .pai .update (TILE_2_UNICODE_ART_RICH [recommand [0 ]])
79
81
self .vertical_rule .update (EMPTY_VERTICAL_RULE )
80
82
for i in range (3 ):
81
83
self .consumes [i ].update (TILE_2_UNICODE_ART_RICH ["?" ])
84
+ self .app .rpc_server .draw_top3 ([self .recommand_idx , recommand [0 ], "?" , "?" , "?" , weight_text ])
82
85
elif recommand [0 ] in ['chi_low' , 'chi_mid' , 'chi_high' ]:
83
86
self .action .label = "chi"
84
87
self .action .add_class ("action_chi" )
@@ -88,15 +91,18 @@ def update(self, mjai_msg, state):
88
91
last_kawa_tile_idx = TILE_LIST .index (last_kawa_tile )
89
92
match recommand [0 ]:
90
93
case 'chi_low' :
91
- self . consumes [ 0 ]. update ( TILE_2_UNICODE_ART_RICH [ TILE_LIST [last_kawa_tile_idx - 2 ]])
92
- self . consumes [ 1 ]. update ( TILE_2_UNICODE_ART_RICH [ TILE_LIST [last_kawa_tile_idx - 1 ]])
94
+ c0 = TILE_LIST [last_kawa_tile_idx + 1 ]
95
+ c1 = TILE_LIST [last_kawa_tile_idx + 2 ]
93
96
case 'chi_mid' :
94
- self . consumes [ 0 ]. update ( TILE_2_UNICODE_ART_RICH [ TILE_LIST [last_kawa_tile_idx - 1 ]])
95
- self . consumes [ 1 ]. update ( TILE_2_UNICODE_ART_RICH [ TILE_LIST [last_kawa_tile_idx + 1 ]])
97
+ c0 = TILE_LIST [last_kawa_tile_idx - 1 ]
98
+ c1 = TILE_LIST [last_kawa_tile_idx + 1 ]
96
99
case 'chi_high' :
97
- self .consumes [0 ].update (TILE_2_UNICODE_ART_RICH [TILE_LIST [last_kawa_tile_idx + 1 ]])
98
- self .consumes [1 ].update (TILE_2_UNICODE_ART_RICH [TILE_LIST [last_kawa_tile_idx + 2 ]])
100
+ c0 = TILE_LIST [last_kawa_tile_idx - 2 ]
101
+ c1 = TILE_LIST [last_kawa_tile_idx - 1 ]
102
+ self .consumes [0 ].update (TILE_2_UNICODE_ART_RICH [c0 ])
103
+ self .consumes [1 ].update (TILE_2_UNICODE_ART_RICH [c1 ])
99
104
self .consumes [2 ].update (TILE_2_UNICODE_ART_RICH ["?" ])
105
+ self .app .rpc_server .draw_top3 ([self .recommand_idx , "chi" , last_kawa_tile , c0 , c1 , weight_text ])
100
106
elif recommand [0 ] in ['pon' ]:
101
107
self .action .label = "pon"
102
108
self .action .add_class ("action_pon" )
@@ -106,6 +112,7 @@ def update(self, mjai_msg, state):
106
112
for i in range (2 ):
107
113
self .consumes [i ].update (TILE_2_UNICODE_ART_RICH [last_kawa_tile ])
108
114
self .consumes [2 ].update (TILE_2_UNICODE_ART_RICH ["?" ])
115
+ self .app .rpc_server .draw_top3 ([self .recommand_idx , "pon" , last_kawa_tile , last_kawa_tile , last_kawa_tile , weight_text ])
109
116
elif recommand [0 ] in ['kan_select' ]:
110
117
# The recommandation only shows kan_select, but not ['daiminkan', 'ankan', 'kakan'],
111
118
# this is due to the Mortal model structure limitations.
@@ -116,20 +123,23 @@ def update(self, mjai_msg, state):
116
123
self .vertical_rule .update (EMPTY_VERTICAL_RULE )
117
124
for i in range (3 ):
118
125
self .consumes [i ].update (TILE_2_UNICODE_ART_RICH ["?" ])
126
+ self .app .rpc_server .draw_top3 ([self .recommand_idx , "kan" , "?" , "?" , "?" , weight_text ])
119
127
elif recommand [0 ] in ['reach' , 'hora' , 'ryukyoku' , 'none' ]:
120
128
self .action .label = recommand [0 ]
121
129
self .action .add_class ("action_" + recommand [0 ])
122
130
self .pai .update (TILE_2_UNICODE_ART_RICH ["?" ])
123
131
self .vertical_rule .update (EMPTY_VERTICAL_RULE )
124
132
for i in range (3 ):
125
133
self .consumes [i ].update (TILE_2_UNICODE_ART_RICH ["?" ])
134
+ self .app .rpc_server .draw_top3 ([self .recommand_idx , recommand [0 ], "?" , "?" , "?" , weight_text ])
126
135
elif recommand [0 ] in ['nukidora' ]:
127
136
self .action .label = "nukidora"
128
137
self .action .add_class ("action_nukidora" )
129
138
self .pai .update (TILE_2_UNICODE_ART_RICH ["N" ])
130
139
self .vertical_rule .update (EMPTY_VERTICAL_RULE )
131
140
for i in range (3 ):
132
141
self .consumes [i ].update (TILE_2_UNICODE_ART_RICH ["?" ])
142
+ self .app .rpc_server .draw_top3 ([self .recommand_idx , "nukidora" , "N" , "?" , "?" , weight_text ])
133
143
pass
134
144
135
145
@@ -161,17 +171,17 @@ def compose(self) -> ComposeResult:
161
171
recommandations_container .border_title = "Recommandations"
162
172
mjai_log_container .border_title = "Mjai"
163
173
tehai_labels = [Label (TILE_2_UNICODE_ART_RICH ["?" ], id = "tehai_" + str (i )) for i in range (13 )]
164
- tehai_value_labels = [Label (HAI_VALUE [40 ], id = "tehai_value_" + str (i )) for i in range (13 )]
174
+ # tehai_value_labels = [Label(HAI_VALUE[40], id="tehai_value_"+str(i)) for i in range(13)]
165
175
tehai_rule = Label (VERTICAL_RULE , id = "tehai_rule" )
166
176
tsumohai_label = Label (TILE_2_UNICODE_ART_RICH ["?" ], id = "tsumohai" )
167
- tsumohai_value_label = Label (HAI_VALUE [40 ], id = "tsumohai_value" )
177
+ # tsumohai_value_label = Label(HAI_VALUE[40], id="tsumohai_value")
168
178
tehai_container = Horizontal (id = "tehai_container" )
169
179
for i in range (13 ):
170
180
tehai_container .mount (tehai_labels [i ])
171
- tehai_container .mount (tehai_value_labels [i ])
181
+ # tehai_container.mount(tehai_value_labels[i])
172
182
tehai_container .mount (tehai_rule )
173
183
tehai_container .mount (tsumohai_label )
174
- tehai_container .mount (tsumohai_value_label )
184
+ # tehai_container.mount(tsumohai_value_label)
175
185
tehai_container .border_title = "Tehai"
176
186
akagi_action = Button ("Akagi" , id = "akagi_action" , variant = "default" )
177
187
akagi_pai = Button ("Pai" , id = "akagi_pai" , variant = "default" )
@@ -184,9 +194,9 @@ def compose(self) -> ComposeResult:
184
194
loading_indicator = LoadingIndicator (id = "loading_indicator" )
185
195
loading_indicator .styles .height = "3"
186
196
checkbox_autoplay = Checkbox ("Autoplay" , id = "checkbox_autoplay" , classes = "short" , value = AUTOPLAY )
197
+ checkbox_overlay = Checkbox ("Overlay " , id = "checkbox_overlay" , classes = "short" )
187
198
checkbox_test_one = Checkbox ("test_one" , id = "checkbox_test_one" , classes = "short" )
188
- checkbox_test_two = Checkbox ("test_two" , id = "checkbox_test_two" , classes = "short" )
189
- checkbox_container = Vertical (checkbox_autoplay , checkbox_test_one , id = "checkbox_container" )
199
+ checkbox_container = Vertical (checkbox_autoplay , checkbox_overlay , id = "checkbox_container" )
190
200
checkbox_container .border_title = "Options"
191
201
bottom_container = Horizontal (checkbox_container , akagi_container , id = "bottom_container" )
192
202
yield Header ()
@@ -211,10 +221,10 @@ def on_mount(self) -> None:
211
221
self .recommandations_container = self .query_one ("#recommandations_container" )
212
222
self .mjai_log_container = self .query_one ("#mjai_log_container" )
213
223
self .tehai_labels = [self .query_one ("#tehai_" + str (i )) for i in range (13 )]
214
- self .tehai_value_labels = [self .query_one ("#tehai_value_" + str (i )) for i in range (13 )]
224
+ # self.tehai_value_labels = [self.query_one("#tehai_value_"+str(i)) for i in range(13)]
215
225
self .tehai_rule = self .query_one ("#tehai_rule" )
216
226
self .tsumohai_label = self .query_one ("#tsumohai" )
217
- self .tsumohai_value_label = self .query_one ("#tsumohai_value" )
227
+ # self.tsumohai_value_label = self.query_one("#tsumohai_value")
218
228
self .tehai_container = self .query_one ("#tehai_container" )
219
229
# self.liqi_log_container.scroll_end(animate=False)
220
230
self .mjai_log_container .scroll_end (animate = False )
@@ -233,8 +243,9 @@ def on_mount(self) -> None:
233
243
self .akagi_action .label = "Akagi"
234
244
235
245
def refresh_log (self ) -> None :
236
- # Yes I know this is stupid
237
246
try :
247
+ if self .flow_id not in self .app .liqi_msg_dict :
248
+ self .action_quit ()
238
249
if self .liqi_msg_idx < len (self .app .liqi_msg_dict [self .flow_id ]):
239
250
# self.liqi_log.update(self.app.liqi_msg_dict[self.flow_id][-1])
240
251
# self.liqi_log_container.scroll_end(animate=False)
@@ -275,25 +286,38 @@ def refresh_log(self) -> None:
275
286
tehai , tsumohai = state_to_tehai (player_state )
276
287
for idx , tehai_label in enumerate (self .tehai_labels ):
277
288
tehai_label .update (TILE_2_UNICODE_ART_RICH [tehai [idx ]])
278
- action_list = [x [0 ] for x in latest_mjai_msg ['meta' ]]
279
- for idx , tehai_value_label in enumerate (self .tehai_value_labels ):
280
- # latest_mjai_msg['meta'] is list of (pai, value)
281
- try :
282
- pai_value = int (latest_mjai_msg ['meta' ][action_list .index (tehai [idx ])][1 ] * 40 )
283
- if pai_value == 40 :
284
- pai_value = 39
285
- except ValueError :
286
- pai_value = 40
287
- tehai_value_label .update (HAI_VALUE [pai_value ])
289
+ # action_list = [x[0] for x in latest_mjai_msg['meta']]
290
+ # for idx, tehai_value_label in enumerate(self.tehai_value_labels):
291
+ # # latest_mjai_msg['meta'] is list of (pai, value)
292
+ # try:
293
+ # pai_value = int(latest_mjai_msg['meta'][action_list.index(tehai[idx])][1] * 40)
294
+ # if pai_value == 40:
295
+ # pai_value = 39
296
+ # except ValueError:
297
+ # pai_value = 40
298
+ # tehai_value_label.update(HAI_VALUE[pai_value])
288
299
self .tsumohai_label .update (TILE_2_UNICODE_ART_RICH [tsumohai ])
289
- if tsumohai in action_list :
290
- try :
291
- pai_value = int (latest_mjai_msg ['meta' ][action_list .index (tsumohai )][1 ] * 40 )
292
- if pai_value == 40 :
293
- pai_value = 39
294
- except ValueError :
295
- pai_value = 40
296
- self .tsumohai_value_label .update (HAI_VALUE [pai_value ])
300
+ # if tsumohai in action_list:
301
+ # try:
302
+ # pai_value = int(latest_mjai_msg['meta'][action_list.index(tsumohai)][1] * 40)
303
+ # if pai_value == 40:
304
+ # pai_value = 39
305
+ # except ValueError:
306
+ # pai_value = 40
307
+ # self.tsumohai_value_label.update(HAI_VALUE[pai_value])
308
+
309
+ self .app .rpc_server .clear_top3 ()
310
+
311
+ # 將weight轉換為字典形式以便快速查找
312
+ weight_dict = dict (self .app .mjai_msg_dict [self .flow_id ][- 1 ]['meta' ])
313
+
314
+ # 生成對應tile_list的權重列表
315
+ tile_order_weight = [weight_dict [tile ] if tile in weight_dict else - 1.0 if tile == "?" else 0.0 for tile in tehai ]
316
+ tile_order_weight .append (weight_dict [tsumohai ] if tsumohai in weight_dict else - 1.0 if tsumohai == "?" else 0.0 )
317
+ # tile_order_weight is numpy.float64, need to convert to float
318
+ tile_order_weight = [float (weight ) for weight in tile_order_weight ]
319
+ self .app .rpc_server .draw_weight (tile_order_weight )
320
+
297
321
# mjai log
298
322
self .mjai_log .update (self .app .mjai_msg_dict [self .flow_id ][- 3 :])
299
323
self .mjai_log_container .scroll_end (animate = False )
@@ -338,7 +362,6 @@ def refresh_log(self) -> None:
338
362
logger .log ("CLICK" , latest_mjai_msg )
339
363
self .app .set_timer (0.15 , self .autoplay )
340
364
# self.autoplay(tehai, tsumohai)
341
-
342
365
343
366
except Exception as e :
344
367
logger .error (e )
@@ -349,6 +372,14 @@ def checkbox_autoplay_changed(self, event: Checkbox.Changed) -> None:
349
372
global AUTOPLAY
350
373
AUTOPLAY = event .value
351
374
pass
375
+
376
+ @on (Checkbox .Changed , "#checkbox_overlay" )
377
+ def checkbox_overlay_changed (self , event : Checkbox .Changed ) -> None :
378
+ if event .value :
379
+ self .app .rpc_server .start_overlay_action ()
380
+ else :
381
+ self .app .rpc_server .stop_overlay_action ()
382
+ pass
352
383
353
384
def redo_action (self ) -> None :
354
385
try :
@@ -370,6 +401,7 @@ def autoplay(self) -> None:
370
401
pass
371
402
372
403
def action_quit (self ) -> None :
404
+ self .app .rpc_server .stop_overlay_action ()
373
405
self .app .set_timer (2 , self .app .update_flow .resume )
374
406
self .update_log .stop ()
375
407
self .app .pop_screen ()
0 commit comments