private LabyrinthDungeon CreateDenseMaze(int rows, int columns, double changeDirectionModifier)
		{
			var map = new LabyrinthDungeon(rows, columns);
			map.MarkCellsUnvisited();
			var currentLocation = map.PickRandomCellAndMarkItVisited(_random);
			var previousDirection = Direction.North;

			while (!map.AllCellsVisited)
			{
				var directionPicker = new DirectionPicker(_random, previousDirection, changeDirectionModifier);
				var direction = directionPicker.GetNextDirection();

				while (!map.HasAdjacentCellInDirection(currentLocation, direction) || map.AdjacentCellInDirectionIsVisited(currentLocation, direction))
				{
					if (directionPicker.HasNextDirection)
					{
						direction = directionPicker.GetNextDirection();
					}
					else
					{
						currentLocation = map.GetRandomVisitedCell(currentLocation, _random); // get a new previously visited location
						directionPicker = new DirectionPicker(_random, previousDirection, changeDirectionModifier); // reset the direction picker
						direction = directionPicker.GetNextDirection(); // get a new direction.
					}
				}

				currentLocation = map.CreateCorridor(currentLocation, direction);

				map.FlagCellAsVisited(currentLocation);
				previousDirection = direction;
			}

			return map;
		}
Example #2
0
        private LabyrinthDungeon CreateDenseMaze(int rows, int columns, double changeDirectionModifier)
        {
            var map = new LabyrinthDungeon(rows, columns);

            map.MarkCellsUnvisited();
            var currentLocation   = map.PickRandomCellAndMarkItVisited(_random);
            var previousDirection = Direction.North;

            while (!map.AllCellsVisited)
            {
                var directionPicker = new DirectionPicker(_random, previousDirection, changeDirectionModifier);
                var direction       = directionPicker.GetNextDirection();

                while (!map.HasAdjacentCellInDirection(currentLocation, direction) || map.AdjacentCellInDirectionIsVisited(currentLocation, direction))
                {
                    if (directionPicker.HasNextDirection)
                    {
                        direction = directionPicker.GetNextDirection();
                    }
                    else
                    {
                        currentLocation = map.GetRandomVisitedCell(currentLocation, _random);                       // get a new previously visited location
                        directionPicker = new DirectionPicker(_random, previousDirection, changeDirectionModifier); // reset the direction picker
                        direction       = directionPicker.GetNextDirection();                                       // get a new direction.
                    }
                }

                currentLocation = map.CreateCorridor(currentLocation, direction);

                map.FlagCellAsVisited(currentLocation);
                previousDirection = direction;
            }

            return(map);
        }