from builders.text_file_builder import TextFileMazeBuilder

from strategies.bfs import BFSStrategy
from strategies.dfs import DFSStrategy
from strategies.astar import AStarStrategy

from experiments.benchmark import BenchmarkRunner
from experiments.plots import ChartBuilder


builder = TextFileMazeBuilder()

maze_files = [
    "small.txt",
    "medium.txt",
    "large.txt",
    "empty.txt",
    "blocked.txt"
]

all_results = []

for maze_file in maze_files:

    print()
    print("Loading:", maze_file)

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

    runner = BenchmarkRunner(
        maze,
        [
            BFSStrategy(),
            DFSStrategy(),
            AStarStrategy()
        ],
        cycles=10
    )

    results = runner.launch()

    for row in results:
        row["maze"] = maze_file

    all_results.extend(results)

runner.exportCSV(
    "experiments/results.csv",
    all_results
)

print()
print("CSV created")

charts = ChartBuilder(
    "experiments/results.csv"
)

print("Time chart...")
charts.buildTimeChart()

print("Visited chart...")
charts.buildVisitedChart()

print("Path chart...")
charts.buildPathChart()

print("Done")