from builder import TextFileMazeBuilder
from strategies import BFSStrategy, DFSStrategy, AStarStrategy
from solver import MazeSolver
from observer import ConsoleView
from command import Player, MoveCommand

def main():
    builder = TextFileMazeBuilder()
    maze = builder.buildFromFile("mazes/small.txt")

    console = ConsoleView()
    console.update({"type": "message", "text": "Лабиринт загружен:"})
    console.update({"type": "render", "maze": maze})

    strategies = {
        "BFS": BFSStrategy(),
        "DFS": DFSStrategy(),
        "A*": AStarStrategy()
    }

    for name, strat in strategies.items():
        solver = MazeSolver(maze, strat)
        stats = solver.solve()
        print(f"{name}: time={stats.timeMs:.3f} ms, visited={stats.visitedCells}, path={stats.pathLength}")
        console.update({"type": "render", "maze": maze, "path": stats.path})

    player = Player(maze.start)
    cmd = MoveCommand(maze, player, "D")
    cmd.execute()
    console.update({"type": "render", "maze": maze, "player": player.position})

if __name__ == "__main__":
    main()