From f3908409ce1f8c88502394feed2e767b07ab6c47 Mon Sep 17 00:00:00 2001 From: volkovva Date: Mon, 25 May 2026 03:52:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20MazeSolver,=20SearchStats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VolkovVA/cod.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/VolkovVA/cod.py b/VolkovVA/cod.py index fa15e82..99a78b7 100644 --- a/VolkovVA/cod.py +++ b/VolkovVA/cod.py @@ -1,6 +1,6 @@ -from abc import ABC, abstractmethod from collections import deque import heapq +import time # --- Модель --- class Cell: @@ -62,10 +62,11 @@ class MazeBuilder: return maze -class PathFindingStrategy(ABC): - @abstractmethod + +class PathFindingStrategy: def findPath(self, maze, start, exit): - pass + + raise NotImplementedError("Этот метод должен быть реализован в стратегии!") def _reconstruct_path(self, parents, current): path = [] @@ -74,6 +75,8 @@ class PathFindingStrategy(ABC): current = parents.get(current) return path[::-1] + + class BFSStrategy(PathFindingStrategy): def findPath(self, maze, start, exit): queue = deque([start]) @@ -114,17 +117,13 @@ class AStarStrategy(PathFindingStrategy): heapq.heappush(heap, (f, neighbor)) return [] -if __name__ == "__main__": - builder = MazeBuilder() - try: - path_to_maze = r"C:\Users\vva26\2026-rff_mp\VolkovVA\docs\data\maze.txt" - maze = builder.buildFromFile(path_to_maze) - print(f"Лабиринт {maze.width}x{maze.height} загружен.") - - - solver = BFSStrategy() - path = solver.findPath(maze, maze.start_cell, maze.exit_cell) - print(f" {len(path)}") - - except Exception as e: - print(f"Ошибка: {e}") \ No newline at end of file +class SearchStats: + def __init__(self, time_ms, visited, length): + self.time_ms = time_ms + self.visited = visited + self.length = length + +class MazeSolver: + def __init__(self, maze): + self.maze = maze + self.strat = None \ No newline at end of file