Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            // the maze size 100x100
            int col = 100;
            int row = 100;

            // create maze with DFSMazeGenerator
            DFSMazeGenerator generator = new DFSMazeGenerator();
            Maze             maze      = generator.Generate(col, row);

            // print the maze
            Console.Write(maze.ToString());

            // adapt the maze and solve it with BFS
            ISearchable <Position> adapter     = new MazeAdapter(maze);
            ISearcher <Position>   bfsSearcher = new BestFirstSearch <Position>();

            bfsSearcher.Search(adapter);

            int bfsNumOfStases = bfsSearcher.GetNumberOfNodesEvaluated();

            // solve the maze with DFS
            ISearcher <Position> dfsSearcher = new DepthFirstSearch <Position>();

            dfsSearcher.Search(adapter);

            int dfsNumOfStases = dfsSearcher.GetNumberOfNodesEvaluated();

            // print the num of evalueted nodes for BFS and DFS
            Console.WriteLine("number of BFS states:" + bfsNumOfStases);
            Console.WriteLine("number of DFS states:" + dfsNumOfStases);

            Console.Read();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// CompareSolvers is a static function that compare between BFS and DFS
        /// </summary>
        public static void CompareSolvers()
        {
            // generate maze
            DFSMazeGenerator mazeGenerator = new DFSMazeGenerator();
            Maze             maze          = mazeGenerator.Generate(100, 100);

            Console.WriteLine(maze.ToString());

            // solve using BFS and DFS
            MazeAdapter    mazeAdapter = new MazeAdapter(maze);
            BFS <Position> bfs         = new BFS <Position>();
            DFS <Position> dfs         = new DFS <Position>();

            bfs.Search(mazeAdapter);
            dfs.Search(mazeAdapter);

            // print the amount of nodes evaluated
            Console.WriteLine("BFS evaluated nodes: " + bfs.GetNumberOfNodesEvaluated());
            Console.WriteLine("DFS evaluated nodes: " + dfs.GetNumberOfNodesEvaluated());
        }