| 1 | """A bot's own process, in RLCard's own interface: agent.py defines a class Agent with eval_step(state) (returning the |
| 2 | action, or the action and info, as RLCard agents do) or step(state), or a function act(state). The state is RLCard's |
| 3 | raw state: state['raw_obs'] (self, landlord, current_hand, others_hand, played_cards, num_cards_left, seen_cards, |
| 4 | trace, 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 | """ |
| 7 | import os, sys |
| 8 | |
| 9 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'kit')) |
| 10 | from host import load, serve |
| 11 | import random |
| 12 | import numpy as np |
| 13 | |
| 14 | random.seed(0) |
| 15 | np.random.seed(0) |
| 16 | |
| 17 | made = load(sys.argv[1], 'Agent', 'act') |
| 18 | bot = made() if isinstance(made, type) else None |
| 19 | |
| 20 | |
| 21 | def 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 | |
| 29 | serve(handle) |