"""A bot's own process, in RLCard's own interface: agent.py defines a class Agent with eval_step(state) (returning the action, or the action and info, as RLCard agents do) or step(state), or a function act(state). The state is RLCard's raw state: state['raw_obs'] (self, landlord, current_hand, others_hand, played_cards, num_cards_left, seen_cards, trace, actions) and state['raw_legal_actions'], moves written as RLCard writes them ('33344', '789TJQ', 'BR', 'pass'). python3 -I referee/child.py """ import os, sys sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'kit')) from host import load, serve # noqa: E402 import random # noqa: E402 import numpy as np # noqa: E402 random.seed(0) # a bot's own randomness is seeded too, so a check gives the same score every time np.random.seed(0) made = load(sys.argv[1], 'Agent', 'act') bot = made() if isinstance(made, type) else None def handle(msg): state = {'raw_obs': msg['raw_obs'], 'raw_legal_actions': msg['raw_obs']['actions']} if bot is None: return str(made(state)) out = bot.eval_step(state) if hasattr(bot, 'eval_step') else bot.step(state) return str(out[0] if isinstance(out, tuple) else out) serve(handle)