def floodfill(col,rowb,neigh,bombpos):
#neigh is number of bombs (neighbors) around the position (row,col)
try:
neigh[rowb][col]
bombpos[rowb][col]
visit[rowb][col]
except IndexError:
return
#if the position is an isolated position, i.e. there are no bombs adjacent to it;
if neigh[rowb][col] == 0:
pygame.draw.rect(screen, (55, 55, 55), (1 + col * 30, 1 + rowb * 30, 28, 28))
floodfill(col - 1, rowb, neigh, bombpos)
floodfill(col, rowb - 1, neigh, bombpos)
floodfill(col + 1, rowb, neigh, bombpos)
floodfill(col, rowb + 1, neigh, bombpos)
floodfill(col - 1, rowb-1, neigh, bombpos)
floodfill(col+1, rowb + 1, neigh, bombpos)
floodfill(col + 1, rowb-1, neigh, bombpos)
floodfill(col-1, rowb + 1, neigh, bombpos)
I'm trying to recreate the minesweeper flood fill algorithm, so I have a flood fill function in which I recursively pick all the boxes around the ones that have a neighbor value of 0, meaning they are not touching any bombs. I understand why this is an infinite recursion, and that I must somehow use a visit matrix that detects which position has been tested so I can end eventually end the recursion. I have tried implementing a "visit" matrix which would be switched to true for a position (row,col) if the position is used in the recursion, but I could not get it to work at all. How could I implement the visit matrix in this code in order to get the proper flood fill algorithm used in minesweeper?