Reputation:
Let's say i have this class called grid for 2D arrays:
class grid:
def __init__(self, N, S, F, p):
## Make sure start and end are within the grid
assert N > 2
assert S[0] < N
assert S[1] < N
assert F[0] < N
assert F[1] < N
assert S[0] > 0
assert S[1] > 0
assert F[0] > 0
assert F[1] > 0
self.N = N
self.grid = np.zeros((N, N), dtype=np.int32)
## Surround the grid with obstacles
self.grid[0, :] = 1
self.grid[N - 1, :] = 1
self.grid[:, 0] = 1
self.grid[:, N - 1] = 1
obstacle_free_points = {S, F}
### Fill the grid with obstacles.
### An obstacle at position (x,y) -> grid[x,y]=1
### Ensure there is a path from S to F
### Your code here ###
def isReachable(self):
visited= np.zeros((N, N), dtype=np.int32)
queue=[]
queue.append(S)
visited[S] = True
def adjacent(self, S):
adjacent_nodes = []
for n in (node[0] - 1, node[1]), (node[0] + 1, node[1]), (node[0], node[1] - 1), (node[0], node[1] + 1):
if self.grid[n] == 0:
adjacent_nodes.append(n)
return adjacent_node
What i would like to do is use adjacent inside isReachable.More specificaly given a pair of numbers (x,y) find all the adjacent array cells using method adjacent.Adjacent works just fine if i use it outside of the class but calling it from another method produces errors.How could this be done?
Upvotes: 0
Views: 47