Skip to content

Commit 0ec9a41

Browse files
author
shinkuan
committed
Autoplay time compensation
1 parent 3affbd1 commit 0ec9a41

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

action.py

+4
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ def mjai2action(self, mjai_msg: dict | None, tehai: list[str], tsumohai: str | N
316316
else:
317317
dahai_delay = dahai_delay
318318

319+
if "time" in mjai_msg:
320+
dahai_delay -= mjai_msg["time"]
321+
if dahai_delay < 0:
322+
dahai_delay = 0
319323
time.sleep(dahai_delay)
320324
self.click_dahai(mjai_msg, tehai, tsumohai)
321325
return

mjai/bot/bot.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import time
23
import sys
34
import hashlib
45
import pathlib
@@ -38,14 +39,17 @@ def __init__(self, player_id: int):
3839
def react(self, events: str) -> str:
3940
events = json.loads(events)
4041

42+
start = time.time()
4143
return_action = None
4244
for e in events:
4345
return_action = self.model.react(json.dumps(e, separators=(",", ":")))
46+
time_elapsed = time.time() - start
4447

4548
if return_action is None:
46-
return json.dumps({"type":"none"}, separators=(",", ":"))
49+
return json.dumps({"type":"none", "time":time_elapsed}, separators=(",", ":"))
4750
else:
4851
raw_data = json.loads(return_action)
52+
raw_data["time"] = time_elapsed
4953
if self.online:
5054
raw_data["online"] = model.online_valid
5155
return json.dumps(raw_data, separators=(",", ":"))

0 commit comments

Comments
 (0)