public void BreadthFirstSearch(TileBoard inputBoard)
 {
     openNodes = new NodeQueue();
     Start(inputBoard);
     Console.WriteLine("Breadth First Search: ");
     solution.Print();
     Console.WriteLine("----------------------------");
 }
 public void DepthFirstSearch(TileBoard inputBoard)
 {
     openNodes = new NodeStack();
     Start(inputBoard);
     Console.WriteLine("Depth First Search: ");
     solution.Print();
     Console.WriteLine("----------------------------");
 }
 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("----------------------------");
 }
 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("----------------------------");
 }
 public void DepthFirstSearch(TileBoard inputBoard)
 {
     openNodes = new NodeStack();
     Start(inputBoard);
     Console.WriteLine("Depth First Search: ");
     solution.Print();
     Console.WriteLine("----------------------------");
 }
 public void BreadthFirstSearch(TileBoard inputBoard)
 {
     openNodes = new NodeQueue();
     Start(inputBoard);
     Console.WriteLine("Breadth First Search: ");
     solution.Print();
     Console.WriteLine("----------------------------");
 }
 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;
 }
 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("----------------------------");
 }
        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("----------------------------");
        }
Beispiel #10
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;
     }
 }
        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;
        }
        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;
        }
        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();

            searches.BreadthFirstSearch(tileBoard.Copy());
            searches.DepthFirstSearch(tileBoard.Copy());
            searches.DepthLimitedSearch(tileBoard.Copy());
            searches.IterativeDeepeningSearch(tileBoard.Copy());
            searches.BidirectionalSearch(tileBoard.Copy());
        }
        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;
                    }
                }
            }
        }
        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();
            searches.BreadthFirstSearch(tileBoard.Copy());
            searches.DepthFirstSearch(tileBoard.Copy());
            searches.DepthLimitedSearch(tileBoard.Copy());
            searches.IterativeDeepeningSearch(tileBoard.Copy());
            searches.BidirectionalSearch(tileBoard.Copy());
        }
        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;
                }
            }
        }
 public bool Equals(TileBoard otherBoard)
 {
     return ToString().Equals(otherBoard.ToString());
 }
Beispiel #18
0
 public bool Equals(TileBoard otherBoard)
 {
     return(ToString().Equals(otherBoard.ToString()));
 }