예제 #1
0
        /// <summary>
        /// generate maze and calls print for both BFS and DFS searching algorithms
        /// </summary>
        private static void testSearchAlgorithms()
        {
            int[]          size3D          = { 4, 6, 6 }; // (z,y,x)
            IMazeGenerator mazeGenerator3d = new MyMaze3dGenerator();
            ISearchable    maze            = new SearchableMaze3D(mazeGenerator3d.generate(size3D));

            print("BFS", new BFS(), maze);
            Console.WriteLine("\nPlease enter any key to continue\n");
            Console.ReadKey();
            print("DFS", new DFS(), maze);
        }
예제 #2
0
        /// <summary>
        /// Solve the maze 'mazeName' with BFS/DFS algorithm and saves the solution in the dictionary
        /// </summary>
        /// <param name="searching">Isearching algorithm to solve the maze with</param>
        /// <param name="mazeName">maze naze</param>
        private void solve(ISearchingAlgorithm searching, string mazeName)
        {
            ISearchable maze;

            try
            {
                m_mutexDictionary[mazeName].WaitOne();
                maze = new SearchableMaze3D(m_mazesDictionary[mazeName]);
            }
            catch (Exception)
            {
                m_controller.errOutput("The maze named: " + mazeName + "does not exist!\n");
                return;
            }
            Solution solution = searching.Solve(maze);

            m_solutionsDictionary[mazeName] = solution;
            m_mutexDictionary[mazeName].ReleaseMutex();
            m_controller.Output("Solution for " + mazeName + " is ready!\n");
        }