private MazeGenerationResults InitializeTree(ICollection <Point> path, MazeGenerationResults results, Tree tree)
        {
            Point startingPoint;
            ICell startingCell;

            do
            {
                // TODO: This one is retarded. Need to think of a better way.
                startingPoint = MazeGenerationUtils.PickStartingPoint(Map, RNG);
                startingCell  = Map.GetCell(startingPoint);
            } while (startingCell.State == CellState.Empty);
            path.Add(startingPoint);
            ChangeCell(results, startingPoint, CellState.Empty, CellDisplayState.Path);
            CellsTreeDict.Add(startingPoint, tree);
            return(results);
        }
Exemplo n.º 2
0
        public override MazeGenerationResults Generate()
        {
            var results = new MazeGenerationResults();

            if (!Map.Infinite)
            {
                // TODO: Ending generation sometimes ends prematurely. Find out why and fix.
                if (RemainingPoints.Count == 0)
                {
                    results.ResultsType = GenerationResultsType.GenerationCompleted;
                    return(results);
                }
            }

            if (CurrentPoint == null)
            {
                CurrentPoint = MazeGenerationUtils.PickStartingPoint(Map, RNG);
                var cell = Map.GetCell(CurrentPoint);

                cell.State        = CellState.Empty;
                cell.DisplayState = CellDisplayState.Path;

                results.Add(new MazeGenerationResult(CurrentPoint, cell.State, cell.DisplayState));
                return(results);
            }

            var doLooping = RNG.NextDouble() < Looping;
            var offsets   = CurrentPoint.GetAxisOffsets();

            Point pathToCellPoint = null;
            Point otherCellPoint  = null;

            while (offsets.Count > 0)
            {
                var offsetIndex = RNG.Next(0, offsets.Count);
                var offset      = offsets[offsetIndex];
                pathToCellPoint = CurrentPoint + offset;
                otherCellPoint  = CurrentPoint + offset * 2;
                var cellExists = Map.CellExists(otherCellPoint);
                if (cellExists)
                {
                    break;
                }
                offsets.RemoveAt(offsetIndex);
            }

            var otherCell  = Map.GetCell(otherCellPoint);
            var pathToCell = Map.GetCell(pathToCellPoint);

            if (doLooping || otherCell.State == CellState.Filled)
            {
                otherCell.State  = CellState.Empty;
                pathToCell.State = CellState.Empty;
            }

            RemainingPoints.Remove(otherCellPoint);

            otherCell.DisplayState  = otherCell.State == CellState.Empty ? CellDisplayState.Path : CellDisplayState.Wall;
            pathToCell.DisplayState = pathToCell.State == CellState.Empty ? CellDisplayState.Path : CellDisplayState.Wall;

            var otherResult = new MazeGenerationResult(otherCellPoint, otherCell.State, otherCell.DisplayState);
            var pathResult  = new MazeGenerationResult(pathToCellPoint, pathToCell.State, pathToCell.DisplayState);

            results.Results.Add(otherResult);
            results.Results.Add(pathResult);

            CurrentPoint = otherCellPoint;

            return(results);
        }