Пример #1
0
 public void DepthLimitedSearch(TileBoard inputBoard)
 {
     openNodes = new NodeDepthStack(27, false);
     Start(inputBoard);
     Console.WriteLine("Depth Limited Search: (with a depth limit of 27)");
     solution.Print();
     Console.WriteLine("----------------------------");
 }
Пример #2
0
 public void DepthFirstSearch(TileBoard inputBoard)
 {
     openNodes = new NodeStack();
     Start(inputBoard);
     Console.WriteLine("Depth First Search: ");
     solution.Print();
     Console.WriteLine("----------------------------");
 }
Пример #3
0
 public void BreadthFirstSearch(TileBoard inputBoard)
 {
     openNodes = new NodeQueue();
     Start(inputBoard);
     Console.WriteLine("Breadth First Search: ");
     solution.Print();
     Console.WriteLine("----------------------------");
 }
Пример #4
0
        public void IterativeDeepeningSearch(TileBoard inputBoard)
        {
            var dataStructure = new NodeDepthStack(1, true);

            openNodes = dataStructure;
            Start(inputBoard);
            Console.WriteLine("Iterative Deepening Search: (Final depth was " + dataStructure.Depth + " )");
            solution.Print();
            Console.WriteLine("----------------------------");
        }
Пример #5
0
        public void BidirectionalSearch(TileBoard inputBoard)
        {
            bidirectional = true;

            openNodes        = new NodeQueue();
            openNodesReverse = new NodeQueue();

            Start(inputBoard);
            Console.WriteLine("Bidirectional Search: ");
            solution.Print();
            Console.WriteLine("----------------------------");

            bidirectional = false;
        }
Пример #6
0
 public BoardNode(BoardNode previous, TileBoard board, char TileMoved)
 {
     this.Previous  = previous;
     this.Board     = board;
     this.TileMoved = TileMoved;
     if (previous == null)
     {
         Cost = 0;
     }
     else
     {
         Cost = previous.Cost + 1;
     }
 }
Пример #7
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;
                    }
                }
            }
        }
Пример #8
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();
        }
Пример #9
0
 public bool Equals(TileBoard otherBoard)
 {
     return(ToString().Equals(otherBoard.ToString()));
 }