-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bot.py
66 lines (53 loc) · 1.67 KB
/
test_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
from mahjong_env.core import Mahjong
from mahjong_env.consts import ActionType
from mahjong_env.player_data import Action
from mahjong_env.base_bot import RandomMahjongBot
def play_round(rd, env):
res = env.init(rd['tiles'], rd['round_wind'], rd['first_player'])
print(res)
for actions in zip(*rd['actions']):
for player in env.players_data:
print('Tile:', ' '.join(sorted(player.tiles)),
', Claiming:', '; '.join([str(c) for c in player.claimings]),
', Remain tiles:', len(player.tile_wall))
print()
act_list = [Action(i, ActionType(act[0]), None if len(act) == 1 else act[1])
for i, act in enumerate(actions)]
res = env.step(act_list)
print(res)
print('Done:', env.done)
if env.fans is not None:
print('Fans:', env.fans)
print('Rewards:', env.rewards)
print()
def random_test():
env = Mahjong()
res = env.init()
print(res)
agent = RandomMahjongBot()
while not env.done:
print(env.observation())
print()
obs = [env.player_obs(i) for i in range(4)]
actions = [agent.action(ob) for ob in obs]
res = env.step(actions)
print(res)
if env.fans is not None:
print('Fans:', env.fans)
print('Rewards:', env.rewards)
print()
def play_test():
rounds = []
with open('mahjong_data/processed_data_sample.json') as f:
for line in f:
rounds.append(json.loads(line))
print(len(rounds))
env = Mahjong()
for rd in rounds:
play_round(rd, env)
def main():
random_test()
play_test()
if __name__ == '__main__':
main()