-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfloodfill.py
58 lines (42 loc) · 907 Bytes
/
floodfill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import numpy as np
grid = 6
a = np.zeros((grid,grid))
n = 1 #goal value
a[2,3] = n #setting location of goal
#print(a)
while n < 12:
for i in range(0,grid):
for j in range(0,grid):
print('n is ' +str(n))
print('i is ' + str(i))
print('j is ' + str(j)+'\n')
if a[i,j] == n:
print('yes')
if (i+1)<grid:
#Check South side
if a[i+1,j] != 1 and a[i+1,j] == 0:
print('1')
a[i+1,j] = n+1
print(a)
if (i-1)>-1:
#check North
if a[i-1,j] != 1 and a[i-1,j] == 0:
print('2')
a[i-1,j] = n+1
print(a)
if(j+1)< grid:
#check east
print('no')
if a[i,j+1] != 1 and a[i,j+1] == 0:
print('3')
a[i,j+1] = n+1
print(a)
if (j-1)>-1:
#check weset
if a[i,j-1] != 1 and a[i,j-1] == 0:
print('4')
a[i,j-1] = n+1
print(a)
n+=1
print('final array')
print(a)