Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- # 11*11 static array
- count = 0
- # Array to check if the tile is visited or not
- checked = np.zeros((11,11), dtype=bool)
- # create a static world
- # 11*11 static array
- multd = [[0,0,0,0,0,0,1,1,0,0,0],
- [0,0,0,0,0,0,1,1,0,0,0],
- [0,1,1,1,1,1,1,1,0,0,0],
- [0,0,0,0,0,1,1,0,0,0,0],
- [0,0,0,0,1,0,1,1,0,0,0],
- [0,1,1,1,1,1,1,1,0,0,0],
- [0,0,0,0,1,1,1,1,0,0,0],
- [0,0,0,0,0,1,1,0,0,0,0],
- [0,0,0,0,1,1,0,0,0,0,0],
- [0,0,0,0,0,1,1,1,0,0,0],
- [0,0,0,0,1,0,0,0,0,0,0]]
- def traverse(x, y,count):
- if x < 0 or x > 11:
- return
- if y < 0 or y > 11:
- return
- if checked[x][y] == True:
- return
- checked[x][y] = True
- if multd[x][y] == 1:
- count += 1
- print(count)
- traverse(x-1,y, count)
- #traverse(x-1,y-1,count)
- traverse(x+1,y, count)
- # traverse(x+1,y-1,count)
- traverse(x,y-1, count)
- #traverse(x+1,y+1,count)
- traverse(x,y+1, count)
- #traverse(x-1,y+1,count)
- return count
- traverse(5,5,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement