Return the neighbours of cell
(self, cell)
| 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 | |
| 89 | def astar(world, start, goal): |