-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathObserver_Builder.py
65 lines (49 loc) · 1.54 KB
/
Observer_Builder.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import numpy as np
def _get_one_hot_for_agent_direction(agent):
"""Retuns the agent's direction to one-hot encoding."""
direction = np.zeros(4)
direction[agent.direction] = 1
return direction
class ObservationBuilder:
"""
ObservationBuilder base class.
"""
def __init__(self):
self.world = None
self.NUM_CHANNELS = None
def set_env(self, env):
self.world = env
def reset(self):
"""
Called after each environment reset.
"""
raise NotImplementedError()
def get_many(self, handles):
"""
Called whenever an observation has to be computed for the `env` environment, for each agent with handle
in the `handles` list.
Parameters
----------
handles : list of handles, optional
List with the handles of the agents for which to compute the observation vector.
Returns
-------
function
A dictionary of observation structures, specific to the corresponding environment, with handles from
`handles` as keys.
"""
raise NotImplementedError
class DummyObserver(ObservationBuilder):
"""
DummyObservationBuilder class which returns dummy observations
This is used in the evaluation service
"""
def __init__(self):
super().__init__()
self.observation_size = 1
def reset(self):
pass
def get_many(self, handles) -> bool:
return True
def get(self, handle: int = 0) -> bool:
return True