예제 #1
0
        static void Main(string[] args)
        {
            const string mazefile   = @"C:\Google Drive\School\2016 - 3 Fall\Cmps 390\Hw4\Files\MazeFile.txt"; //file reading from
            var          mazeMatrix = FileReader.ReadFile(mazefile);                                           //write file into 2d array

            Console.WriteLine("Maze Matrix");
            PrintOuts.PrintMatrix(mazeMatrix);
            Console.WriteLine();

            var edgeSet = Matrix.GetEdgeSet(mazeMatrix);    //obtain edge set from 2d array

            var matrixGraph = Matrix.FindHeadNode(edgeSet); //find root node for graph's Root

            Matrix.AttachNodesToRoot(matrixGraph, edgeSet); //fill in graph with starting point

            var dfs = new DepthFirstSearch();

            Console.WriteLine("Depth First Search");
            var DFSResult = dfs.DoTheThing(new SearchObjects()
            {
                CurrNode = matrixGraph, MazeMatrix = mazeMatrix
            }).MazeMatrix;

            Console.WriteLine();


            Console.WriteLine("Depth First Search Result");
            PrintOuts.PrintMatrix(DFSResult);
            Console.WriteLine();

            //Console.WriteLine("Breadth First Search");
            //Console.WriteLine();

            var bfs       = new BreathFirstSearch();
            var BFSResult = bfs.BFS(mazeMatrix, matrixGraph);

            //PrintOuts.PrintMatrix(BFSResult);
            //Console.WriteLine("Breadth First Search Result");
            //Console.WriteLine();


            Console.ReadLine();
        }
예제 #2
0
        public SearchObjects DoTheThing(SearchObjects obj)
        {
            if (obj.CurrNode.LeftNode != null && obj.MazeMatrix[obj.CurrNode.LeftNode.Row, obj.CurrNode.LeftNode.Column] == ' ')
            {
                obj.MazeMatrix[obj.CurrNode.LeftNode.Row, obj.CurrNode.LeftNode.Column] = '0';
            }
            if (obj.CurrNode.RightNode != null && obj.MazeMatrix[obj.CurrNode.RightNode.Row, obj.CurrNode.RightNode.Column] == ' ')
            {
                obj.MazeMatrix[obj.CurrNode.RightNode.Row, obj.CurrNode.RightNode.Column] = '0';
            }
            if (obj.CurrNode.UpNode != null && obj.MazeMatrix[obj.CurrNode.UpNode.Row, obj.CurrNode.UpNode.Column] == ' ')
            {
                obj.MazeMatrix[obj.CurrNode.UpNode.Row, obj.CurrNode.UpNode.Column] = '0';
            }
            if (obj.CurrNode.DownNode != null && obj.MazeMatrix[obj.CurrNode.DownNode.Row, obj.CurrNode.DownNode.Column] == ' ')
            {
                obj.MazeMatrix[obj.CurrNode.DownNode.Row, obj.CurrNode.DownNode.Column] = '0';
            }
            if (obj.MazeMatrix[obj.CurrNode.Row, obj.CurrNode.Column] == '0')
            {
                obj.MazeMatrix[obj.CurrNode.Row, obj.CurrNode.Column] = '1';
            }
            PrintOuts.PrintMatrix(obj.MazeMatrix);
            Console.WriteLine();

            if ((obj.CurrNode.LeftNode != null && obj.MazeMatrix[obj.CurrNode.LeftNode.Row, obj.CurrNode.LeftNode.Column] == 'F') || (obj.CurrNode.RightNode != null && obj.MazeMatrix[obj.CurrNode.RightNode.Row, obj.CurrNode.RightNode.Column] == 'F') || (obj.CurrNode.UpNode != null && obj.MazeMatrix[obj.CurrNode.UpNode.Row, obj.CurrNode.UpNode.Column] == 'F') || (obj.CurrNode.DownNode != null && obj.MazeMatrix[obj.CurrNode.DownNode.Row, obj.CurrNode.DownNode.Column] == 'F'))
            {
                return(obj);
            }
            else if (obj.CurrNode.LeftNode != null && obj.MazeMatrix[obj.CurrNode.LeftNode.Row, obj.CurrNode.LeftNode.Column] == '0')
            {
                var next = new SearchObjects()
                {
                    CurrNode = obj.CurrNode.LeftNode, MazeMatrix = obj.MazeMatrix
                };
                obj = DoTheThing(next);
            }
            else if (obj.CurrNode.RightNode != null && obj.MazeMatrix[obj.CurrNode.RightNode.Row, obj.CurrNode.RightNode.Column] == '0')
            {
                var next = new SearchObjects()
                {
                    CurrNode = obj.CurrNode.RightNode, MazeMatrix = obj.MazeMatrix
                };
                obj = DoTheThing(next);
            }
            else if (obj.CurrNode.UpNode != null && obj.MazeMatrix[obj.CurrNode.UpNode.Row, obj.CurrNode.UpNode.Column] == '0')
            {
                var next = new SearchObjects()
                {
                    CurrNode = obj.CurrNode.UpNode, MazeMatrix = obj.MazeMatrix
                };
                obj = DoTheThing(next);
            }
            else if (obj.CurrNode.DownNode != null &&
                     obj.MazeMatrix[obj.CurrNode.DownNode.Row, obj.CurrNode.DownNode.Column] == '0')
            {
                var next = new SearchObjects()
                {
                    CurrNode = obj.CurrNode.DownNode, MazeMatrix = obj.MazeMatrix
                };
                obj = DoTheThing(next);
            }
            else
            {
                obj.MazeMatrix[obj.CurrNode.Row, obj.CurrNode.Column] = '2';
                PrintOuts.PrintMatrix(obj.MazeMatrix);
                Console.WriteLine();
            }

            return(obj);
        }