public AlgorithmRunResults GenerateMaze(IMazeCarver maze, MazeGenerationSettings settings)
        {
            var pointsAndDirections = new List <DirectionAndPoint>();

            _mazeHelper.DoForEachPoint(maze.Size, p =>
            {
                maze.JumpToPoint(p);
                var directions = _directions.Where(maze.CanCarveInDirection).ToList();
                _arrayHelper.Shuffle(directions);
                if (directions.Any())
                {
                    var first = directions.First();
                    pointsAndDirections.Add(new DirectionAndPoint {
                        Direction = first, MazePoint = maze.CurrentPoint
                    });
                    maze.CarveInDirection(first);
                }
            });

            return(new AlgorithmRunResults
            {
                Carver = maze,
                DirectionsCarvedIn = pointsAndDirections
            });
        }
Esempio n. 2
0
        public AlgorithmRunResults RecursiveBackTracker(IMazeCarver carver)
        {
            var pointsAndDirections = new List <DirectionAndPoint>();
            var directions          = carver.CarvableDirections().ToList();

            _arrayHelper.Shuffle(directions);
            var currentPoint = carver.CurrentPoint;

            foreach (var direction in directions)
            {
                carver.JumpInDirection(direction);
                var carvedDirections = carver.AlreadyCarvedDirections();
                if (!carvedDirections.Any())
                {
                    pointsAndDirections.Add(new DirectionAndPoint {
                        Direction = direction, MazePoint = currentPoint
                    });
                    var oppositeDirection = _directionsFlagParser.OppositeDirection(direction);
                    carver.CarveInDirection(oppositeDirection);
                    RecursiveBackTracker(carver);
                }
                carver.JumpToPoint(currentPoint);
            }
            return(new AlgorithmRunResults
            {
                Carver = carver,
                DirectionsCarvedIn = pointsAndDirections
            });
        }
Esempio n. 3
0
        private int CheckPoint(MazePoint point, IMazeCarver carver, int numberOfWalls, Direction preferredDirection = Direction.None)
        {
            carver.JumpToPoint(point);
            var directions = carver.CarvableDirections().ToList();

            _arrayHelper.Shuffle(directions);
            if (directions.Any())
            {
                var selectedDirection = directions.Contains(preferredDirection)
                    ? preferredDirection
                    : directions.First();
                carver.CarveInDirection(selectedDirection);
                numberOfWalls--;
            }
            return(numberOfWalls);
        }
        public AlgorithmRunResults GenerateMaze(IMazeCarver maze, MazeGenerationSettings settings)
        {
            var pointAndDirection = new List <DirectionAndPoint>();
            var randomPoint       = _randomPointGenerator.RandomPoint(maze.Size);

            maze.JumpToPoint(randomPoint);
            var activeCells = new LinkedList <MazePoint>();

            activeCells.AddLast(randomPoint);
            while (activeCells.Any())
            {
                var currentPoint = activeCells.Last.Value;
                maze.JumpToPoint(currentPoint);
                var carvableDirections = maze.CarvableDirections().ToList();
                _arrayHelper.Shuffle(carvableDirections);
                var carved = false;
                foreach (var direction in carvableDirections)
                {
                    maze.JumpInDirection(direction);
                    var carvedDirections = maze.AlreadyCarvedDirections();
                    if (!carvedDirections.Any())
                    {
                        pointAndDirection.Add(new DirectionAndPoint {
                            Direction = direction, MazePoint = currentPoint
                        });
                        var oppositeDirection = _directionsFlagParser.OppositeDirection(direction);
                        maze.CarveInDirection(oppositeDirection);
                        activeCells.AddLast(maze.CurrentPoint);
                        carved = true;
                        break;
                    }
                    maze.JumpToPoint(currentPoint);
                }
                if (!carved)
                {
                    activeCells.RemoveLast();
                }
            }
            return(new AlgorithmRunResults
            {
                Carver = maze,
                DirectionsCarvedIn = pointAndDirection
            });
        }
Esempio n. 5
0
        private AlgorithmRunResults GenerateMaze(IMazeCarver maze, List <GrowingTreeStrategy> strategies)
        {
            var pointsAndDirections = new List <DirectionAndPoint>();
            var randomPoint         = _randomPointGenerator.RandomPoint(maze.Size);
            var activeCells         = new List <MazePoint> {
                randomPoint
            };

            while (activeCells.Any())
            {
                var currentPoint = GetNextPoint(activeCells, strategies);
                maze.JumpToPoint(currentPoint);
                var carvableDirections = maze.CarvableDirections().ToList();
                _arrayHelper.Shuffle(carvableDirections);
                var carved = false;
                foreach (var direction in carvableDirections)
                {
                    maze.JumpInDirection(direction);
                    var carvedDirections = maze.AlreadyCarvedDirections();
                    if (!carvedDirections.Any())
                    {
                        pointsAndDirections.Add(new DirectionAndPoint {
                            Direction = direction, MazePoint = currentPoint
                        });
                        var oppositeDirection = _directionsFlagParser.OppositeDirection(direction);
                        maze.CarveInDirection(oppositeDirection);
                        activeCells.Add(maze.CurrentPoint);
                        carved = true;
                        break;
                    }
                    maze.JumpToPoint(currentPoint);
                }
                if (!carved)
                {
                    activeCells.Remove(currentPoint);
                }
            }
            return(new AlgorithmRunResults
            {
                Carver = maze,
                DirectionsCarvedIn = pointsAndDirections
            });
        }