forked from UFRN-URNAI/urnai-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabenv.py
58 lines (45 loc) · 1.59 KB
/
abenv.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
from abc import abstractmethod
import inspect
import os
import sys
from typing import Tuple
from urnai.base.savable import Savable
from urnai.utils.returns import Done, Observation, Reward
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
parentdir = os.path.dirname(parentdir)
sys.path.insert(0, parentdir)
class Env(Savable):
"""
Abstract Base Class for all environments currently supported.
Environments are classes used to create a link between agents, models and
the game. For cases where an environment for a game already exists, this class
should still be used as a wrapper (e.g. implementing an environment for OpenAI gym).
"""
def __init__(self, _id: str, render=False, reset_done=True):
super().__init__()
self.id = _id
self.render = render
self.reset_done = reset_done
self.env_instance = None
"""
Starts the environment. The implementation should assign the value of env_instance.
"""
@abstractmethod
def start(self) -> None: ...
"""
Executes an action on the environment and returns an [Observation, Reward, Done] tuple.
"""
@abstractmethod
def step(self, action) -> Tuple[Observation, Reward, Done]: ...
"""
Resets the environment. This method should return an Observation, since it's used by the
Trainer to get the first Observation.
"""
@abstractmethod
def reset(self) -> Observation: ...
"""
Closes the environment.
"""
@abstractmethod
def close(self) -> None: ...