Exemplo n.º 1
0
        private void Start(TileBoard inputBoard)
        {
            //initialize new solution
            solution            = new Solution();
            solution.StartBoard = inputBoard.Copy();
            solution.StartTime();

            //initialize new visited nodes table
            visitedNodes = new Dictionary <string, BoardNode>();

            //add input board to open node list
            var startNode = new BoardNode(null, inputBoard, '!');

            visitedNodes.Add(inputBoard.ToString(), startNode);
            solution.ExpandedNodes++;
            openNodes.Push(startNode);

            //for bidirectional search, add end node to reverse open list
            if (bidirectional)
            {
                var endBoard = new TileBoard("_12345678");
                var endNode  = new BoardNode(null, endBoard, '!');
                endNode.Reverse = true;
                visitedNodes.Add(endBoard.ToString(), endNode);
                solution.ExpandedNodes++;
                openNodesReverse.Push(endNode);
            }

            //start solving
            while (true)
            {
                if (Solve())
                {
                    break;
                }
                if (bidirectional)
                {
                    if (Solve(true))
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            TileBoard tileBoard;

            //if (DEBUG)
            //{
            //    string filePath;
            //    if (args.Length == 0)
            //        filePath = "input.txt";
            //    else
            //        filePath = args[0];
            //    string input = "_12345678";

            //    try
            //    {
            //        var sr = new StreamReader(filePath);
            //        input = sr.ReadToEnd();
            //        input = input.Replace("\r\n", "");
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e.Message);
            //        Console.ReadLine();
            //        return;
            //    }

            //    tileBoard = new TileBoard(input);
            //}

            //if (!DEBUG)
            //{

            //}

            tileBoard = new TileBoard();
            tileBoard.Randomize('_');
            var searches = new Searches();

            Console.WriteLine("==============================Breadth-First Search=========================");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");

            searches.BreadthFirstSearch(tileBoard.Copy());
            Console.WriteLine("==============================Depth-First Search=========================");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            searches.DepthFirstSearch(tileBoard.Copy());

            Console.WriteLine("==============================Uniform-Cost Search=========================");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            UcsImplementation.Execute();

            Console.WriteLine("==============================Depth-Limited Search=========================");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            searches.DepthLimitedSearch(tileBoard.Copy());
            Console.WriteLine("==============================Iterative-Deepening Search=========================");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            searches.IterativeDeepeningSearch(tileBoard.Copy());
            Console.WriteLine("==============================Bi-directional Search=========================");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            Console.WriteLine("============================== ============================== ");
            searches.BidirectionalSearch(tileBoard.Copy());


            Console.ReadLine();
        }