refactor: DFS not DST
The searching algorithm is called Depth-First Search not DST.
This commit is contained in:
parent
8466500092
commit
611935050b
2 changed files with 5 additions and 5 deletions
2
main.py
2
main.py
|
@ -18,7 +18,7 @@ def main():
|
||||||
|
|
||||||
solver = Solver(game)
|
solver = Solver(game)
|
||||||
|
|
||||||
if solver.solve(solver.solve_with_randomised_dst_r):
|
if solver.solve(solver.solve_with_randomised_dfs_r):
|
||||||
print("Maze solved successfully :)")
|
print("Maze solved successfully :)")
|
||||||
else:
|
else:
|
||||||
print("I'm unable to solve the maze :(")
|
print("I'm unable to solve the maze :(")
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Solver:
|
||||||
|
|
||||||
return solve_method(start_position, end_position)
|
return solve_method(start_position, end_position)
|
||||||
|
|
||||||
def solve_with_dst_r(
|
def solve_with_dfs_r(
|
||||||
self,
|
self,
|
||||||
current_position: MazePosition,
|
current_position: MazePosition,
|
||||||
end_position: MazePosition,
|
end_position: MazePosition,
|
||||||
|
@ -77,7 +77,7 @@ class Solver:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self._game.draw_path_between(current_position, adjacent_position)
|
self._game.draw_path_between(current_position, adjacent_position)
|
||||||
solved = self.solve_with_dst_r(adjacent_position, end_position)
|
solved = self.solve_with_dfs_r(adjacent_position, end_position)
|
||||||
if solved:
|
if solved:
|
||||||
return True
|
return True
|
||||||
self._game.draw_path_between(
|
self._game.draw_path_between(
|
||||||
|
@ -85,7 +85,7 @@ class Solver:
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def solve_with_randomised_dst_r(
|
def solve_with_randomised_dfs_r(
|
||||||
self,
|
self,
|
||||||
current_position: MazePosition,
|
current_position: MazePosition,
|
||||||
end_position: MazePosition,
|
end_position: MazePosition,
|
||||||
|
@ -130,7 +130,7 @@ class Solver:
|
||||||
chosen_direction,
|
chosen_direction,
|
||||||
)
|
)
|
||||||
self._game.draw_path_between(current_position, next_position)
|
self._game.draw_path_between(current_position, next_position)
|
||||||
solved = self.solve_with_randomised_dst_r(
|
solved = self.solve_with_randomised_dfs_r(
|
||||||
next_position, end_position)
|
next_position, end_position)
|
||||||
if solved:
|
if solved:
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in a new issue