示例#1
0
 public Maze(MazeState aStartState) : this(aStartState, null)
 {
     _goalStates = new MazeState[] { new MazeState(MazeGenerator.GenerateGoalState(aStartState)) };
 }
示例#2
0
        static void Main(string[] args)
        {
            //Search Algorithm Information: https://www.geeksforgeeks.org/a-search-algorithm/ (Heuristic Calculations and more)

            //Check command-line args
            if (args.Length < 3)
            {
                Console.WriteLine("Required args: <mapconfig file> <search method> <variable move cost>");
                Console.WriteLine("Map Config File: Enter filename with configuration OR enter 0 for random mazes");
                Console.WriteLine("Search methods: DFS, BFS, AS, GBFS, CUS1");
                Console.WriteLine("Variable move cost: 0 = false, 1 = true;");
                System.Environment.Exit(0);
            }

            //assign args to variables
            string file   = args[0];
            string method = args[1];

            SearchMethod.VariableCost = args[2] == "1" ? true : false;
            bool runtest = file == "0" ? true : false; //runtest if file == 0

            //initalize Test Object
            MazeTest mazeTest = new MazeTest(400); //(50*50)/2

            //create maze object
            Maze maze = new Maze(null, null);

            if (File.Exists(file))
            {
                StreamReader  rdr           = new StreamReader(file);
                MazeGenerator mazeGenerator = new MazeGenerator();
                maze = mazeGenerator.GetMaze(rdr);

                Output(maze, method);
            }
            else if (runtest)
            {
                int sizeIncrement = 20;
                for (int i = 0; i < 45; i++)
                {
                    if (i > sizeIncrement)
                    {
                        sizeIncrement += 5;
                    }

                    Console.WriteLine($"Test iteration no: {i + 1}");
                    MazeState randomState = new MazeState(MazeGenerator.GenerateRandomMaze(sizeIncrement));
                    maze = new Maze(randomState);

                    Output(maze, method);

                    mazeTest.LogTest(maze.StartState.State.GetLength(0) * maze.StartState.State.GetLength(1), maze.FinalPathCost, maze.IterationCount);
                }

                mazeTest.OutputResults();
            }
            else
            {
                Console.WriteLine($"The file: {file} was not found. Please try again!");
                Environment.Exit(1);
            }
        }