Search for the path, if a path is not found, only the starting position is returned
(self)
| 117 | self.reached = False |
| 118 | |
| 119 | def search(self) -> Path | None: |
| 120 | """ |
| 121 | Search for the path, |
| 122 | if a path is not found, only the starting position is returned |
| 123 | """ |
| 124 | while self.open_nodes: |
| 125 | # Open Nodes are sorted using __lt__ |
| 126 | self.open_nodes.sort() |
| 127 | current_node = self.open_nodes.pop(0) |
| 128 | |
| 129 | if current_node.pos == self.target.pos: |
| 130 | self.reached = True |
| 131 | return self.retrace_path(current_node) |
| 132 | |
| 133 | self.closed_nodes.append(current_node) |
| 134 | successors = self.get_successors(current_node) |
| 135 | |
| 136 | for child_node in successors: |
| 137 | if child_node in self.closed_nodes: |
| 138 | continue |
| 139 | |
| 140 | if child_node not in self.open_nodes: |
| 141 | self.open_nodes.append(child_node) |
| 142 | |
| 143 | if not self.reached: |
| 144 | return [self.start.pos] |
| 145 | return None |
| 146 | |
| 147 | def get_successors(self, parent: Node) -> list[Node]: |
| 148 | """ |
no test coverage detected