示例#1
0
        private void btnGenerateMap_Click(object sender, EventArgs e)
        {
            txtMap.Text = "";

            // Start with a clear map (don't add any obstacles)
            InitializeMap(7, 5, Point.Empty, Point.Empty, true);
            PathFinding       pathFinder = new PathFinding(searchParameters);
            PathFindingResult pathResult = pathFinder.FindPath();

            //txtMap.Text += ShowRoute("The algorithm should find a direct path without obstacles:", path);
            //txtMap.Text += Environment.NewLine;

            //// Now add an obstacle
            //InitializeMap(7, 5, Point.Empty, Point.Empty);
            //AddWallWithGap();
            //pathFinder = new PathFinding(searchParameters);
            //path = pathFinder.FindPath();
            //txtMap.Text += ShowRoute("The algorithm should find a route around the obstacle:", path);
            //txtMap.Text += Environment.NewLine;


            //// Create a barrier between the start and end points
            //InitializeMap(7, 5, Point.Empty, Point.Empty);
            //AddWallWithoutGap();
            //pathFinder = new PathFinding(searchParameters);
            //path = pathFinder.FindPath();
            //txtMap.Text += ShowRoute("The algorithm should not be able to find a route around the barrier:", path);
            //txtMap.Text += Environment.NewLine;


            //// Create a maze with custom start and end points
            //InitializeMap(7, 5, new Point(0, 4), new Point(6, 4));
            //AddWallWithMaze();
            //pathFinder = new PathFinding(searchParameters);
            //path = pathFinder.FindPath();
            //txtMap.Text += ShowRoute("The algorithm should be able to find a long route around the barrier:", path);
            //txtMap.Text += Environment.NewLine;


            //// Create a maze with custom start and end points
            //InitializeMap(7, 5, new Point(0, 4), new Point(4, 2));
            //AddWallWithSpinningMaze();
            //pathFinder = new PathFinding(searchParameters);
            //path = pathFinder.FindPath();
            //txtMap.Text += ShowRoute("The algorithm should be able to find a long route around the barrier:", path);
            //txtMap.Text += Environment.NewLine;


            // Create a larger maze with custom start and end points
            InitializeMap(70, 40, new Point(0, 0), new Point(69, 39), false);
            this.map     = GenerateMap.GenerateRandomMap(this.map, 70, 40, 40);
            pathFinder   = new PathFinding(searchParameters);
            pathResult   = pathFinder.FindPath();
            txtMap.Text += ShowRoute("The algorithm should be able to find a long route around the random blocks:", pathResult.Path);
            txtMap.Text += Environment.NewLine;

            //Console.WriteLine("Press any key to exit...");
            //Console.ReadKey();
        }
示例#2
0
        public void Test_RandomMap()
        {
            // Arrange
            int xMax = 10;
            int zMax = 10;

            string[,] map = new string[xMax, zMax];

            // Act
            map = GenerateMap.GenerateRandomMap(map, xMax, zMax, 50);
            GenerateMap.DebugPrintOutMap(map, xMax, zMax);

            // Assert
            Assert.IsTrue(map.Length > 0);
            //Assert.IsTrue(map[5, 5] == "HW");
            //Assert.IsTrue(map[3, 5] == "LW");
        }