-
Notifications
You must be signed in to change notification settings - Fork 7
/
bot.py
43 lines (34 loc) · 1.11 KB
/
bot.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
import json
import sys
class Bot:
def __init__(self, actor_id):
self.actor_id = actor_id
def react(self, events: str) -> str:
events = json.loads(events)
assert len(events) > 0
# 最後のイベントの `type` によって分岐
if events[-1]["type"] == "tsumo": # type: ignore
# 最後にツモった牌を捨てる
return json.dumps({
"type": "dahai",
"pai": events[-1]["pai"], # type: ignore
"actor": self.actor_id,
"tsumogiri": True,
}, separators=(",", ":"))
else:
# それ以外
# 他人の打牌に対して常にアクションしない
return json.dumps({
"type": "none",
}, separators=(",", ":"))
def main():
player_id = int(sys.argv[1])
assert player_id in range(4)
bot = Bot(player_id)
while True:
line = sys.stdin.readline().strip()
resp = bot.react(line)
sys.stdout.write(resp + "\n")
sys.stdout.flush()
if __name__ == "__main__":
main()