예제 #1
0
        int numTileNeighbors(Cell c)
        {
            int count = 0;

            foreach (Vector3 v in c.getNeighbors())
            {
                if (cells[v].getCellType() == cellType.tile)
                {
                    count++;
                }
            }
            return(count);
        }
예제 #2
0
        void MazeInit()
        {
            HashSet <Cell> frontier = new HashSet <Cell>();
            Cell           start    = cells[new Vector3(Random.Range(1, columns), Random.Range(1, rows), 0)];

            Debug.Log(start.getPosition());
            frontier.Add(start);
            while (frontier.Count > 0)
            {
                //Pick a random element of the set
                Cell[] currFrontier = new Cell[frontier.Count];
                frontier.CopyTo(currFrontier);
                Cell curr = getLowestWeight(currFrontier);
                //Remove the current cell from the frontier
                frontier.Remove(curr);

                curr.beenVisited = true;
                //Set the active cell to an inner tile
                if (curr.getCellType() != cellType.outerWall)
                {
                    if (numTileNeighbors(curr) <= 1)
                    {
                        curr.setCellType(cellType.tile);
                        foreach (Vector3 nnv in curr.getNeighbors())
                        {
                            Cell next = cells[nnv];
                            if (next.getCellType() == cellType.innerWall && next.beenVisited == false)
                            {
                                frontier.Add(next);
                            }
                        }
                    }
                }
                //Add neighbors with 1 or fewer tile neighbors to the frontier
            }
        }