Skip to content

Commit

Permalink
Merge pull request #37 from motoiro:main
Browse files Browse the repository at this point in the history
优化出牌延迟
  • Loading branch information
shinkuan committed Mar 17, 2024
2 parents ffaf74d + a40f16b commit 7fa6544
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
28 changes: 27 additions & 1 deletion action.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
from loguru import logger
from xmlrpc.client import ServerProxy

YAOJIU = ('1p','1m','1s','9p','9m','9s','E','S','W','N','P','F','C')
TWOEIGHT = ('2p','2m','2s','8p','8m','8s')
TFFSS = ('3p','3m','3s','4p','4m','4s','5p','5m','5s','6p','6m','6s','7p','7m','7s')
REDFIVE = ('5pr','5mr','5sr')


# Coordinates here is on the resolution of 16x9
LOCATION = {
"tiles": [
Expand Down Expand Up @@ -106,6 +112,7 @@ def __init__(self, rpc_server: ServerProxy):
self.new_max = settings['RandomTime']['new_max']
self.min = settings['RandomTime']['min']
self.max = settings['RandomTime']['max']
self.moqiedelay = settings['RandomTime']['moqiedelay']
pass

def page_clicker(self, coord: tuple[float, float]):
Expand Down Expand Up @@ -279,11 +286,30 @@ def click_dahai(self, mjai_msg: dict | None, tehai: list[str], tsumohai: str | N
break


def mjai2action(self, mjai_msg: dict | None, tehai: list[str], tsumohai: str | None):
def mjai2action(self, mjai_msg: dict | None, tehai: list[str], tsumohai: str | None, isliqi: bool):
dahai_delay = self.decide_random_time()
if mjai_msg is None:
return
if mjai_msg['type'] == 'dahai' and not self.reached:
if self.moqiedelay:
if isliqi:
# if someone reached
# dahai_delay = 4.75
dahai_delay = dahai_delay
elif not mjai_msg['tsumogiri']:
if mjai_msg['pai'] in YAOJIU:
dahai_delay = dahai_delay
elif mjai_msg['pai'] in TWOEIGHT:
dahai_delay = dahai_delay
elif mjai_msg['pai'] in TFFSS:
dahai_delay = dahai_delay
elif mjai_msg['pai'] in REDFIVE:
dahai_delay = dahai_delay
else:
# tsumogiri
dahai_delay = dahai_delay
else:
dahai_delay = dahai_delay
time.sleep(dahai_delay)
self.click_dahai(mjai_msg, tehai, tsumohai)
return
Expand Down
7 changes: 6 additions & 1 deletion client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, flow_id, *args, **kwargs) -> None:
self.latest_operation_list = None
self.syncing = True
self.action = Action(self.app.rpc_server)
self.isLiqi = False

def compose(self) -> ComposeResult:
"""Called to add widgets to the app."""
Expand Down Expand Up @@ -145,6 +146,8 @@ def refresh_log(self) -> None:
self.action.latest_operation_list = liqi_msg['data']['data']['operation']['operationList']
if liqi_msg['data']['name'] == 'ActionDiscardTile':
self.action.isNewRound = False
if liqi_msg['data']['data']['isLiqi']:
self.isLiqi = True
pass
if liqi_msg['data']['name'] == 'ActionNewRound':
self.action.isNewRound = True
Expand Down Expand Up @@ -237,7 +240,9 @@ def checkbox_autoplay_changed(self, event: Checkbox.Changed) -> None:
pass

def autoplay(self) -> None:
self.action.mjai2action(self.app.mjai_msg_dict[self.flow_id][-1], self.tehai, self.tsumohai)
isliqi = self.isLiqi
self.action.mjai2action(self.app.mjai_msg_dict[self.flow_id][-1], self.tehai, self.tsumohai, isliqi)
self.isLiqi = False
pass

def action_quit(self) -> None:
Expand Down
3 changes: 2 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"new_min": 3.5,
"new_max": 4.5,
"min": 1.0,
"max": 3.2
"max": 3.2,
"moqiedelay": true
},
"Helper": false,
"Autohu": false,
Expand Down

0 comments on commit 7fa6544

Please sign in to comment.