Beispiel #1
0
        /// <summary>
        /// Compare the solvers we created by using the adapter desing pattern between
        /// the maze and searchable.
        /// </summary>
        static void CompareSolvers()
        {
            DFSMazeGenerator       dfsMaze = new DFSMazeGenerator();
            Maze                   maze    = dfsMaze.Generate(100, 100);
            ISearchable <Position> adapt   = new MazeToSearchableAdapter(maze);
            BFSSearcher <Position> bfs     = new BFSSearcher <Position>();
            DFSSearcher <Position> dfs     = new DFSSearcher <Position>();

            //Console.WriteLine(maze);
            bfs.Search(adapt);
            Console.WriteLine("Best First Search evaluated {0} nodes.", bfs.GetNumberOfNodesEvaluated());
            dfs.Search(adapt);
            Console.WriteLine("DFS evaluated {0} nodes.", dfs.GetNumberOfNodesEvaluated());
        }
Beispiel #2
0
        /// <summary>
        /// Compares the solvers.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="col">The col.</param>
        public static void CompareSolvers(int row, int col)
        {
            DFSMazeGenerator generator = new DFSMazeGenerator();
            Maze             maze      = generator.Generate(row, col);

            Console.WriteLine(maze.ToString());
            ISearchable <Position> searchable = new MazeAdapter(maze);

            ISearcher <Position> searcher = new BFSSearcher <Position>();
            Solution <Position>  solution = searcher.Search(searchable);

            Console.WriteLine("BFS solved the maze with {0} evaluated nodes",
                              searcher.GetNumberOfNodesEvaluated());

            searcher = new DFSSearcher <Position>();
            solution = searcher.Search(searchable);
            Console.WriteLine("DFS solved the maze with {0} evaluated nodes",
                              searcher.GetNumberOfNodesEvaluated());

            Console.WriteLine("");
        }
Beispiel #3
0
    static void Main(string[] args)
    {
        ISearcher <int> ser = new DFSSearcher <int>();

        Dictionary <State <int>, List <State <int> > > Adj = new Dictionary <State <int>, List <State <int> > >();
        State <int> one   = new State <int>(1);
        State <int> two   = new State <int>(2);
        State <int> three = new State <int>(3);
        State <int> four  = new State <int>(4);
        State <int> five  = new State <int>(5);
        State <int> six   = new State <int>(6);
        State <int> seven = new State <int>(7);

        Adj[one] = new List <State <int> > {
            two, three
        };
        Adj[two] = new List <State <int> > {
            four, five
        };
        Adj[three] = new List <State <int> > {
            two, six
        };
        Adj[four] = new List <State <int> >();
        Adj[five] = new List <State <int> > {
            six
        };
        Adj[six] = new List <State <int> > {
            seven
        };
        Adj[seven] = new List <State <int> > {
            three
        };

        TestSearchable <int> test1 = new TestSearchable <int>(one, six, Adj);
        Solution <int>       sol   = ser.Search(test1);

        printSol(sol);
    }