-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.py
59 lines (47 loc) · 1.41 KB
/
environment.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
import matplotlib.pyplot as plt
import numpy as np
class Environment:
UP = np.array([0, 1])
DOWN = np.array([0, -1])
LEFT = np.array([-1, 0])
RIGHT = np.array([1, 0])
DIRECTIONS = [UP, RIGHT, DOWN, LEFT]
def __init__(self, filename, xlim, ylim):
self.fig = plt.figure()
self.xlim = xlim
self.ylim = ylim
self.filename = filename
def is_goal_state(self, state):
raise NotImplementedError
def draw(self, state):
raise NotImplementedError
def next_state(self, state, action):
raise NotImplementedError
def get_player(self, state):
raise NotImplementedError
def get_neighbors(self, state):
raise NotImplementedError
def direction_to_str(self, direction):
if all(direction == Environment.UP):
return "UP"
elif all(direction == Environment.DOWN):
return "DOWN"
elif all(direction == Environment.LEFT):
return "LEFT"
return "RIGHT"
def direction_to_letter(self, direction):
if all(direction == Environment.UP):
return "U"
elif all(direction == Environment.DOWN):
return "D"
elif all(direction == Environment.LEFT):
return "L"
return "R"
def rotate_direction_90(self, direction):
if all(direction == Environment.UP):
return Environment.RIGHT
elif all(direction == Environment.RIGHT):
return Environment.DOWN
elif all(direction == Environment.DOWN):
return Environment.LEFT
return Environment.UP