/// <summary> /// method that creates a maze and solves it by dfs and bfs /// </summary> public static void CompareSolvers() { DFSMazeGenerator maze = new DFSMazeGenerator(); Maze currentMaze = maze.Generate(100, 100); Console.WriteLine(currentMaze.ToString()); MazeSearcher newMaze = new MazeSearcher(currentMaze); ISearcher <Position> bfsSearch = new Bfs <Position>(); ISearcher <Position> dfsSearch = new Dfs <Position>(); Solution <Position> solBfs = bfsSearch.search(newMaze); Solution <Position> solDfs = dfsSearch.search(newMaze); //printing the num of evaluated nodes Console.WriteLine("bfs " + bfsSearch.EvaluatedNodes); Console.WriteLine("dfs " + dfsSearch.EvaluatedNodes); Console.ReadLine(); }
/// <summary> /// Solves the game according the type of algorithm /// </summary> /// <param name="name">The name of the maze.</param> /// <param name="algorithm">The algorithm we want to solve by.</param> /// <returns> /// a string of the solution /// </returns> public string solve(string name, ISearcher <Position> algorithm) { if (!allMazes.ContainsKey(name)) { return("the maze doesn't exist in the server"); } if (solutions.ContainsKey(name)) { return(solutions[name]); } else { Maze currentMaze = allMazes[name]; MazeSearcher newMaze = new MazeSearcher(currentMaze); Solution <Position> sol = algorithm.search(newMaze); //translate the solution to string string solString = solutionToString(sol); solutions.Add(name, solString); return(solString); } }