I have a Matrix[x][y] of ints that are either 1 or 0 in C#. I need to count how many 0 are in an island, and I was thinking of using a flood fill algorithm but I don't know how to write it. Any ideas?
this is what I did
void FloodFill(int r, int c)
{
player = FindObjectOfType<Player>();
r = Mathf.RoundToInt(player.coords.x);
c = Mathf.RoundToInt(player.coords.y);
if (matrix[r][c] == 1)
{
count++;
FloodFill(r + 1 , c);
FloodFill(r , c + 1);
FloodFill(r - 1 , c);
FloodFill(r , c - 1);
}
}
I don't think is right though.