-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
39 lines (29 loc) · 866 Bytes
/
base.py
File metadata and controls
39 lines (29 loc) · 866 Bytes
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
class Environment(object):
"""Base class for environment."""
def __init__(self):
pass
@property
def num_of_actions(self):
raise NotImplementedError
def GetState(self):
"""Returns current state as numpy (possibly) multidimensional array.
If the current state is terminal, returns None.
"""
raise NotImplementedError
def ProcessAction(self, action):
"""Performs one step given selected action. Returns step reward."""
raise NotImplementedError
class Agent(object):
"""Base class for different agents."""
def __init__(self):
pass
def ChooseAction(self, state):
pass
def PlayEpisode(env, agent):
state = env.GetState()
total_reward = 0.
while state is not None:
action = agent.ChooseAction(state)
total_reward += env.ProcessAction(action)
state = env.GetState()
return total_reward