Esempio n. 1
0
    private void CreatePathsToAllGreenTiles(Grid <Tile> grid, int iteration = 0)
    {
        //WARNING: DO NOT ADD LOGS WITHOUT PERFORMANCE CONSIDERATION
        //This function can get called a lot. If there are a lot of logs, it can freeze the game.

        iteration++;

        var allGreenTiles   = GetAllGreenTiles(grid);
        var randomGreenTile = allGreenTiles.Values.ToList()[Random.Range(0, allGreenTiles.Count)];

        //Try to visit every single grass tile using breadth first search.
        var breadthsFirstSearch = new BreadthFirstSearch(grid, true);

        breadthsFirstSearch.Execute(randomGreenTile, int.MaxValue, new List <TileType> {
            TileType.Grass
        });
        var visitedTiles = breadthsFirstSearch.GetVisitedTiles();

        visitedTiles[(randomGreenTile.GridX, randomGreenTile.GridY)] = randomGreenTile;