60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
import sys
|
|
import os
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from builders.text_file_maze_builder import TextFileMazeBuilder
|
|
from strategies.bfs_strategy import BFSStrategy
|
|
from strategies.dfs_strategy import DFSStrategy
|
|
from strategies.astar_strategy import AStarStrategy
|
|
from solver.maze_solver import MazeSolver
|
|
from observer.console_view import ConsoleView
|
|
|
|
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
MAZES_DIR = os.path.join(PROJECT_ROOT, "mazes")
|
|
|
|
mazes = {
|
|
"1": "small.txt",
|
|
"2": "medium.txt",
|
|
"3": "large.txt",
|
|
"4": "no_exit.txt"
|
|
}
|
|
|
|
strategies = {
|
|
"1": BFSStrategy(),
|
|
"2": DFSStrategy(),
|
|
"3": AStarStrategy()
|
|
}
|
|
|
|
print("Choose maze:")
|
|
print("1 - small")
|
|
print("2 - medium")
|
|
print("3 - large")
|
|
print("4 - no_exit")
|
|
maze_choice = input("> ").strip()
|
|
|
|
while maze_choice not in mazes:
|
|
print("Invalid choice. Try again.")
|
|
maze_choice = input("> ").strip()
|
|
|
|
print("\nChoose strategy:")
|
|
print("1 - BFS")
|
|
print("2 - DFS")
|
|
print("3 - A*")
|
|
strategy_choice = input("> ").strip()
|
|
|
|
while strategy_choice not in strategies:
|
|
print("Invalid choice. Try again.")
|
|
strategy_choice = input("> ").strip()
|
|
|
|
builder = TextFileMazeBuilder()
|
|
maze_path = os.path.join(MAZES_DIR, mazes[maze_choice])
|
|
maze = builder.build_from_file(maze_path)
|
|
strategy = strategies[strategy_choice]
|
|
|
|
solver = MazeSolver(maze, strategy)
|
|
view = ConsoleView(maze)
|
|
solver.attach(view)
|
|
stats = solver.solve(mazes[maze_choice])
|
|
|
|
print(stats) |