from builders.text_file_maze_builder import TextFileMazeBuilder

from strategies.bfs_strategy import BFS
from strategies.dfs_strategy import DFSStrategy
from strategies.astar_strategy import AStarStrategy

from solver.maze_solver import MazeSolver


mazes = [
    "small.txt",
    "medium.txt",
    "large.txt",
    "no exit.txt",
    "empty.txt"
]

strategies = [
    BFS(),
    DFSStrategy(),
    AStarStrategy()
]

results = []

builder = TextFileMazeBuilder()


for maze_file in mazes:

    maze = builder.build_from_file(
        f"mazes/{maze_file}"
    )

    for strategy in strategies:

        solver = MazeSolver(
            maze,
            strategy
        )

        stats = solver.solve()

        stats.maze_name = maze_file

        results.append(stats)


with open(
    "experiments/results.csv",
    "w"
) as file:

    file.write(
        "maze,strategy,time_ms,visited_cells,path_length\n"
    )

    for stat in results:

        file.write(stat.to_csv_row())