-
Notifications
You must be signed in to change notification settings - Fork 0
/
gridWorld.py
53 lines (43 loc) · 1.43 KB
/
gridWorld.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
import numpy as np
from utils import *
from node import Node
class GridWorld():
def __init__(self, params: dict, fixed_grid=False):
self.N = params['n']
self.nodes = []
self.zvals = []
if fixed_grid: self.create_fixed_grid(fixed_grid)
else: self.create_grid()
def create_grid(self):
# print('generating random grid...')
for i in range(self.N):
nodes_row = []
zvals_row = []
for j in range(self.N):
z = np.round(np.random.uniform(0, 10), 1)
n = Node(i, j, z)
zvals_row.append(z)
nodes_row.append(n)
self.zvals.append(zvals_row)
self.nodes.append(nodes_row)
self.nodes[0][0].cost = 0
self.nodes[0][0].f = 0
self.nodes[0][0].visited = True
def create_fixed_grid(self, grid):
# print('building fixed grid...')
self.zvals = grid
for i in range(len(grid)):
nodes_row = []
for j in range(len(grid[i])):
n = Node(i, j, grid[i][j])
nodes_row.append(n)
self.nodes.append(nodes_row)
self.nodes[0][0].cost = 0
self.nodes[0][0].f = 0
self.nodes[0][0].visited = True
def display_self(self):
for row in self.nodes:
for node in row:
node.display_self()
print()
print()