MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / get_neighbours

Method get_neighbours

machine_learning/astar.py:61–86  ·  view source on GitHub ↗

Return the neighbours of cell

(self, cell)

Source from the content-addressed store, hash-verified

59 print(self.w)
60
61 def get_neighbours(self, cell):
62 """
63 Return the neighbours of cell
64 """
65 neughbour_cord = [
66 (-1, -1),
67 (-1, 0),
68 (-1, 1),
69 (0, -1),
70 (0, 1),
71 (1, -1),
72 (1, 0),
73 (1, 1),
74 ]
75 current_x = cell.position[0]
76 current_y = cell.position[1]
77 neighbours = []
78 for n in neughbour_cord:
79 x = current_x + n[0]
80 y = current_y + n[1]
81 if 0 <= x < self.world_x_limit and 0 <= y < self.world_y_limit:
82 c = Cell()
83 c.position = (x, y)
84 c.parent = cell
85 neighbours.append(c)
86 return neighbours
87
88
89def astar(world, start, goal):

Callers 1

astarFunction · 0.80

Calls 2

CellClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected