示例#1
0
        public MazeCell GetNextNeighbour(MazeCell cell, Random rand)
        {
            List <MazeCell> list = new List <MazeCell>();

            if (cell.X > 0 && !this.CellGrid[cell.X - 1][cell.Y].Visited)
            {
                list.Add(this.CellGrid[cell.X - 1][cell.Y]);
            }
            if (cell.X < this.CellGrid.Count - 1 && !this.CellGrid[cell.X + 1][cell.Y].Visited)
            {
                list.Add(this.CellGrid[cell.X + 1][cell.Y]);
            }
            if (cell.Y > 0 && !this.CellGrid[cell.X][cell.Y - 1].Visited)
            {
                list.Add(this.CellGrid[cell.X][cell.Y - 1]);
            }
            if (cell.Y < this.CellGrid[cell.X].Count - 1 && !this.CellGrid[cell.X][cell.Y + 1].Visited)
            {
                list.Add(this.CellGrid[cell.X][cell.Y + 1]);
            }
            if (list.Count > 0)
            {
                return(list[rand.Next(0, list.Count)]);
            }
            return(null);
        }
示例#2
0
 public AbstractRuleSet GenerateRuleSet(int seed)
 {
     solutionWeights.Clear();
     queryPropertyWeights.Clear();
     rand = new Random(seed);
     return(CreateRules(seed == RuleManager.DefaultSeed));
 }
        private static void PopulateMaze(Maze maze, Random rand, int numCells)
        {
            Stack <MazeCell> cellStack = new Stack <MazeCell>();
            int      x    = rand.Next(0, numCells);
            int      y    = rand.Next(0, numCells);
            MazeCell cell = maze.GetCell(x, y);

            MazeBuilder.VisitCell(cell, cellStack, maze, rand);
        }
        public static Maze BuildMaze(int numCells, Random rand)
        {
            Maze maze = new Maze();

            maze.Size     = numCells;
            maze.CellGrid = new List <List <MazeCell> >();
            for (int i = 0; i < numCells; i++)
            {
                List <MazeCell> list = new List <MazeCell>();
                maze.CellGrid.Add(list);
                for (int j = 0; j < numCells; j++)
                {
                    MazeCell mazeCell = new MazeCell(i, j);
                    list.Add(mazeCell);
                    if (i > 0)
                    {
                        bool flag = rand.NextDouble() < 0.0;
                        if (flag)
                        {
                            mazeCell.HideLeft = true;
                            maze.CellGrid[i - 1][j].HideRight = true;
                        }
                    }
                    if (j > 0)
                    {
                        bool flag2 = rand.NextDouble() < 0.0;
                        if (flag2)
                        {
                            mazeCell.HideAbove = true;
                            maze.CellGrid[i][j - 1].HideBelow = true;
                        }
                    }
                }
            }
            MazeBuilder.PopulateMaze(maze, rand, numCells);
            return(maze);
        }
        private static void VisitCell(MazeCell cell, Stack <MazeCell> cellStack, Maze maze, Random rand)
        {
            cell.Visited = true;
            MazeCell mazeCell = maze.GetNextNeighbour(cell, rand);

            if (mazeCell != null)
            {
                MazeCell.RemoveWalls(cell, mazeCell);
                cellStack.Push(cell);
                MazeBuilder.VisitCell(mazeCell, cellStack, maze, rand);
            }
            else if (cellStack.Count > 0)
            {
                mazeCell = cellStack.Pop();
                MazeBuilder.VisitCell(mazeCell, cellStack, maze, rand);
            }
        }