-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuman_agent.py
51 lines (42 loc) · 1.54 KB
/
human_agent.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
class HumanAgent(object):
''' A random agent. Random agents is for running toy examples on the card games
'''
def __init__(self, action_num):
''' Initilize the random agent
Args:
action_num (int): The size of the ouput action space
'''
self.action_num = action_num
@staticmethod
def step(state):
''' Predict the action given the curent state in gerenerating training data.
Args:
state (dict): An dictionary that represents the current state
Returns:
action (int): The action predicted (randomly chosen) by the random
agent
'''
action = 0
print(state)
print('what do we do?')
while True:
a = input()
if a >= '0' and a <= '2':
action = ord(a)-ord('0')
break
return action
def eval_step(self, state):
''' Predict the action given the current state for evaluation.
Since the random agents are not trained. This function is
equivalent to step function
Args:
state (dict): An dictionary that represents the current state
Returns:
action (int): The action predicted (randomly chosen) by
the random agent
probs (list): The list of action probabilities
'''
probs = [0 for _ in range(self.action_num)]
for i in state['legal_actions']:
probs[i] = 1/len(state['legal_actions'])
return self.step(state), probs