2026-05-17 21:40:59 +00:00
|
|
|
from builders import (TextFileMazeBuilder)
|
2026-05-24 19:18:38 +00:00
|
|
|
from strategies import (BFSStrategy, DFSStrategy, AStarStrategy)
|
2026-05-18 19:10:10 +00:00
|
|
|
from solver import (MazeSolver)
|
2026-05-24 19:18:38 +00:00
|
|
|
from observer_command import ConsoleView, Player, MoveCommand
|
|
|
|
|
import os
|
2026-05-17 21:40:59 +00:00
|
|
|
|
|
|
|
|
builder = TextFileMazeBuilder()
|
2026-05-24 20:53:59 +00:00
|
|
|
maze = builder.buildFromFile("no_exit_maze.txt")
|
2026-05-24 19:18:38 +00:00
|
|
|
print("Лабиринт:\n")
|
2026-05-18 19:10:10 +00:00
|
|
|
maze.printMaze()
|
|
|
|
|
print("Выберете алгоритм")
|
|
|
|
|
print("1 - BFS")
|
|
|
|
|
print("2 - DFS")
|
|
|
|
|
print("3 - A*")
|
|
|
|
|
choice = input()
|
|
|
|
|
if choice == "1":
|
|
|
|
|
strategy = BFSStrategy()
|
|
|
|
|
elif choice == "2":
|
|
|
|
|
strategy = DFSStrategy()
|
|
|
|
|
elif choice == "3":
|
|
|
|
|
strategy = AStarStrategy()
|
|
|
|
|
else:
|
|
|
|
|
print("Неверный выбор")
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
solver = MazeSolver(maze, strategy)
|
2026-05-24 19:18:38 +00:00
|
|
|
view = ConsoleView()
|
|
|
|
|
solver.addObserver(view)
|
2026-05-18 19:10:10 +00:00
|
|
|
stats = solver.solve()
|
|
|
|
|
print("Результат:")
|
|
|
|
|
print(stats)
|
2026-05-24 19:18:38 +00:00
|
|
|
path, _ = strategy.findPath(
|
|
|
|
|
maze,
|
|
|
|
|
maze.start,
|
|
|
|
|
maze.exit
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if not path:
|
|
|
|
|
print("\nПуть не найден")
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
print("\nНайденный путь:")
|
|
|
|
|
for cell in path:
|
|
|
|
|
print(f"({cell.x}, {cell.y})")
|
|
|
|
|
|
|
|
|
|
print("\nПошаговое движение игрока")
|
|
|
|
|
player = Player(maze.start)
|
|
|
|
|
|
|
|
|
|
history = []
|
|
|
|
|
passed_path = [maze.start]
|
|
|
|
|
|
|
|
|
|
view.render(maze, player, passed_path)
|
|
|
|
|
|
|
|
|
|
for cell in path[1:]:
|
|
|
|
|
|
|
|
|
|
input("\nEnter -> следующий шаг")
|
|
|
|
|
|
|
|
|
|
command = MoveCommand(player, cell)
|
|
|
|
|
command.execute()
|
|
|
|
|
|
|
|
|
|
history.append(command)
|
|
|
|
|
|
|
|
|
|
passed_path.append(cell)
|
|
|
|
|
|
|
|
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
|
|
|
|
|
|
view.render(maze, player, passed_path)
|
2026-05-18 19:10:10 +00:00
|
|
|
|