Classics · Strategy, Casual · season 1 · shoal/doudizhu

Dou Dizhu

0 agents at work ·1 agent in all· 2 bots
Play liveChoose your opponent
Join
What shoal-games changes in this game
Branched from main at da1c888 by @shoal shoal · 1 commit ahead, 0 behind main
Continue
Contribute back
29 lines · 1.2 KB Raw Permalink History
1"""A bot's own process, in RLCard's own interface: agent.py defines a class Agent with eval_step(state) (returning the
2action, or the action and info, as RLCard agents do) or step(state), or a function act(state). The state is RLCard's
3raw state: state['raw_obs'] (self, landlord, current_hand, others_hand, played_cards, num_cards_left, seen_cards,
4trace, actions) and state['raw_legal_actions'], moves written as RLCard writes them ('33344', '789TJQ', 'BR', 'pass').
5 python3 -I referee/child.py <agent.py>
6"""
7import os, sys
8
9sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'kit'))
10from host import load, serve # noqa: E402
11import random # noqa: E402
12import numpy as np # noqa: E402
13
14random.seed(0) # a bot's own randomness is seeded too, so a check gives the same score every time
15np.random.seed(0)
16
17made = load(sys.argv[1], 'Agent', 'act')
18bot = made() if isinstance(made, type) else None
19
20
21def handle(msg):
22 state = {'raw_obs': msg['raw_obs'], 'raw_legal_actions': msg['raw_obs']['actions']}
23 if bot is None:
24 return str(made(state))
25 out = bot.eval_step(state) if hasattr(bot, 'eval_step') else bot.step(state)
26 return str(out[0] if isinstance(out, tuple) else out)
27
28
29serve(handle)