diff --git a/ProninVV/task-2-oop/AStarStrategy.py b/ProninVV/task-2-oop/AStarStrategy.py index b179458..f3bcd8d 100644 --- a/ProninVV/task-2-oop/AStarStrategy.py +++ b/ProninVV/task-2-oop/AStarStrategy.py @@ -3,18 +3,18 @@ from strategy import PathFindingStrategy class AStarStrategy(PathFindingStrategy): - def findPath(maze, start, exit): + def findPath(self, maze, start, exit): def heuristik(cell): return abs(cell.x - exit.x) + abs(cell.y - exit.y) - if not start or not exit: - return [] - parents = {start: None} queue = [start] + if not start or not exit: + return [], 0 + while len(queue) != 0: best_cell = queue[0] for cell in queue: @@ -38,4 +38,4 @@ class AStarStrategy(PathFindingStrategy): if child not in parents: parents[child] = u queue.append(child) - return [] + return [], len(parents) diff --git a/ProninVV/task-2-oop/BreadthFirstSearch.py b/ProninVV/task-2-oop/BreadthFirstSearch.py index 3fa9166..b2b0515 100644 --- a/ProninVV/task-2-oop/BreadthFirstSearch.py +++ b/ProninVV/task-2-oop/BreadthFirstSearch.py @@ -3,15 +3,16 @@ from Maze import Maze, Cell class BFSStrategy(PathFindingStrategy): - def findPath(maze: Maze, start: Cell, exit: Cell): + def findPath(self, maze: Maze, start: Cell, exit: Cell): - if not start or not exit: - return [] # очерель: перывй вошел - первый вышел queue = [start] # будем хранить откуда в какую клетку пришли parents = {start: None} + if not start or not exit: + return [], 0 + while (len(queue) != 0): u = queue.pop(0) if u == exit: @@ -28,4 +29,4 @@ class BFSStrategy(PathFindingStrategy): if child not in parents: parents[child] = u queue.append(child) - return [] + return [], len(parents) diff --git a/ProninVV/task-2-oop/Deikstra.py b/ProninVV/task-2-oop/Deikstra.py index 8c2524d..d7547b2 100644 --- a/ProninVV/task-2-oop/Deikstra.py +++ b/ProninVV/task-2-oop/Deikstra.py @@ -3,10 +3,10 @@ from Maze import Maze, Cell class DeikstraFind(PathFindingStrategy): - def findPath(maze, start, exit): + def findPath(self, maze, start, exit): if not start or not exit: - return [] + return [], len(parents) queue = [start] @@ -40,4 +40,4 @@ class DeikstraFind(PathFindingStrategy): if child not in queue: queue.append(child) - return [] + return [], len(parents) diff --git a/ProninVV/task-2-oop/DepthFirstSearch.py b/ProninVV/task-2-oop/DepthFirstSearch.py index a54d9ba..0f353ef 100644 --- a/ProninVV/task-2-oop/DepthFirstSearch.py +++ b/ProninVV/task-2-oop/DepthFirstSearch.py @@ -1,12 +1,16 @@ +import sys + from strategy import PathFindingStrategy from Maze import Maze, Cell +sys.setrecursionlimit(15000) + class DFSStrategy(PathFindingStrategy): - def findPath(maze: Maze, start, exit): + def findPath(self, maze: Maze, start, exit): if not start or not exit: - return [] + return [], 0 visited = set() path = [] @@ -16,7 +20,7 @@ class DFSStrategy(PathFindingStrategy): def dfs(root: Cell) -> bool: visited.add(root) path.append(root) - count_cell += 1 + # count_cell += 1 if root == exit: return True @@ -31,6 +35,6 @@ class DFSStrategy(PathFindingStrategy): return False if dfs(start): - return path, count_cell + return path, len(visited) - return [] + return [], len(visited)