MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / get_successors

Method get_successors

graphs/bidirectional_a_star.py:132–156  ·  view source on GitHub ↗

Returns a list of successors (both in the grid and free spaces)

(self, parent: Node)

Source from the content-addressed store, hash-verified

130 return [self.start.pos]
131
132 def get_successors(self, parent: Node) -> list[Node]:
133 """
134 Returns a list of successors (both in the grid and free spaces)
135 """
136 successors = []
137 for action in delta:
138 pos_x = parent.pos_x + action[1]
139 pos_y = parent.pos_y + action[0]
140 if not (0 <= pos_x <= len(grid[0]) - 1 and 0 <= pos_y <= len(grid) - 1):
141 continue
142
143 if grid[pos_y][pos_x] != 0:
144 continue
145
146 successors.append(
147 Node(
148 pos_x,
149 pos_y,
150 self.target.pos_y,
151 self.target.pos_x,
152 parent.g_cost + 1,
153 parent,
154 )
155 )
156 return successors
157
158 def retrace_path(self, node: Node | None) -> list[TPosition]:
159 """

Callers 2

searchMethod · 0.95
searchMethod · 0.45

Calls 2

NodeClass · 0.70
appendMethod · 0.45

Tested by

no test coverage detected