Flood Fill
The algorithm checks the current item
neighbors.
A = [
list('||||||||||||||||||||||||||||||'),
list('|| || |||'),
list('|| ||||| || ||||'),
list('|||||| || || || ||||||'),
list('|||| || || || |||'),
list('||| |||||| || |||'),
list('|||||||| ||||||||||'),
list('||||||||||||||||||||||||||||||'),
]
def show_list(A):
width = len(A[0])
height = len(A)
for y in range(height):
for x in range(width):
print(A[y][x], end=)
print('')
print('')
def flood_fill(A, start):
y, x = start
A[y][x] = '0'
top = y-1, x
right = y, x+1
bottom = y+1, x
left = y, x-1
y, x = top
if A[y][x] == ' ':
A[y][x] = '0'
flood_fill(A, top)
y, x = right
if A[y][x] == ' ':
A[y][x] = '0'
flood_fill(A, right)
y, x = bottom
if A[y][x] == ' ':
A[y][x] = '0'
flood_fill(A, bottom)
y, x = left
if A[y][x] == ' ':
A[y][x] = '0'
flood_fill(A, left)
return A
flood_fill(A, (1, 4))
show_list(A)