Beispiel #1
0
    private void SetupFloodFill()
    {
        floodFill   = new FloodCell[Maze.MazeSize.x, Maze.MazeSize.y];
        floodStatus = FloodStatus.Find;

        for (int y = 0; y < Maze.MazeSize.y; y++)
        {
            for (int x = 0; x < Maze.MazeSize.x; x++)
            {
                floodFill[x, y]          = new FloodCell(x, y);
                floodFill[x, y].textMesh = GameObject.Find(x + "," + y).GetComponentInChildren <TextMesh>();
            }
        }

        previousCell = null;
    }
Beispiel #2
0
    private void ModifiedFloodFillStep()
    {
        var groundTag = DetectGround(paint: false);

        if (groundTag == "End" && floodStatus == FloodStatus.Find)
        {
            floodStatus = FloodStatus.Return;
        }
        else if (groundTag == "Start" && floodStatus == FloodStatus.Return)
        {
            floodStatus  = FloodStatus.Finished;
            pauseExplore = true;
            return;
        }

        if (floodStatus == FloodStatus.Find)
        {
            CalculateModifiedFloodFill(Maze.GetEndCells());
        }
        else if (floodStatus == FloodStatus.Return)
        {
            CalculateModifiedFloodFill(new Maze.Coord(0, 0));
        }

        var front = orientation;
        var left  = GetOrientation(orientation, -1);
        var right = GetOrientation(orientation, 1);

        int deltaRotation = 1;

        var hasFrontWall = cells[xPos, yPos].HasWall(GetWallFromMouseOrientation(front));
        var hasLeftWall  = cells[xPos, yPos].HasWall(GetWallFromMouseOrientation(left));
        var hasRightWall = cells[xPos, yPos].HasWall(GetWallFromMouseOrientation(right));

        int lowestFlood = Int32.MaxValue;

        Maze.Cell cell = null;

        cell = GetAdjacentCell(front);
        if (!hasFrontWall && cell != null)
        {
            var adjacentFlood = floodFill[cell.x, cell.y].value;
            if (adjacentFlood < lowestFlood)
            {
                lowestFlood   = adjacentFlood;
                deltaRotation = 0;
            }
        }

        cell = GetAdjacentCell(left);
        if (!hasLeftWall && cell != null)
        {
            var adjacentFlood = floodFill[cell.x, cell.y].value;
            if (adjacentFlood < lowestFlood)
            {
                lowestFlood   = adjacentFlood;
                deltaRotation = -1;
            }
        }

        cell = GetAdjacentCell(right);
        if (!hasRightWall && cell != null)
        {
            var adjacentFlood = floodFill[cell.x, cell.y].value;
            if (adjacentFlood < lowestFlood)
            {
                lowestFlood   = adjacentFlood;
                deltaRotation = 1;
            }
        }

        if (previousCell != null)
        {
            var adjacentFlood = floodFill[previousCell.x, previousCell.y].value;
            if (adjacentFlood < lowestFlood)
            {
                lowestFlood   = adjacentFlood;
                deltaRotation = -2;
            }
        }

        previousCell = cells[xPos, yPos];

        Rotate(deltaRotation);
        forceMove = true;
    }