Example #1
0
    void DepthFirstGenerator()
    {
        Stack <GameObject>   cellsStack   = new Stack <GameObject>();
        HashSet <GameObject> visitedCells = new HashSet <GameObject>();

        GameObject startingCell = this.GetRandomCell();

        cellsStack.Push(startingCell);
        visitedCells.Add(startingCell);

        while (cellsStack.Count > 0)
        {
            //Debug.Log("Generation");
            //Debug.Log(cellsStack.Count);
            GameObject currentCell      = cellsStack.Peek();
            CellModel  currentCellModel = currentCell.GetComponent <CellModel>();
            GameObject linkCell         = currentCellModel.GetRandomUnvisitedSibling(visitedCells);

            if (linkCell == null)
            {
                cellsStack.Pop();
                continue;
            }

            visitedCells.Add(linkCell);
            cellsStack.Push(linkCell);
            currentCellModel.MakeLink(linkCell);
            //yield return new WaitForSeconds(1f);
        }
        //StopCoroutine("DepthFirstGenerator");
    }