-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.py
51 lines (33 loc) · 1.11 KB
/
grid.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
import numpy as np
from utils import print2
class grid:
def __init__(self, size):
# size = [h, w]
self.size = size
self.grid = np.zeros(size)
self.ogrid = None
self.dir = ['E', 'W', 'N', 'S']
self.terminate = []
self.unavailable = []
def init(self):
self.ogrid = np.copy(self.grid)
def set(self, coord, value):
self.grid[coord[0], coord[1]] = value
def set_terminate(self, coord, value):
self.grid[coord[0], coord[1]] = value
self.terminate.append(coord)
def set_unavailable(self, coord):
self.grid[coord[0], coord[1]] = np.nan
self.unavailable.append(coord)
def show(self, p = 'c'):
for h in xrange(self.size[0]):
for w in xrange(self.size[1]):
if w == 0:
print2('|')
if p == 'c':
print2(self.grid[h,w])
elif p == 'o':
print2(self.ogrid[h,w])
print2('|')
print ' '
#self.grid.set