Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import numpy as np
  2.  
  3.  
  4. # 11*11 static array
  5. count = 0
  6. # Array to check if the tile is visited or not
  7. checked = np.zeros((11,11), dtype=bool)
  8.  
  9. # create a static world
  10. # 11*11 static array
  11. multd = [[0,0,0,0,0,0,1,1,0,0,0],
  12. [0,0,0,0,0,0,1,1,0,0,0],
  13. [0,1,1,1,1,1,1,1,0,0,0],
  14. [0,0,0,0,0,1,1,0,0,0,0],
  15. [0,0,0,0,1,0,1,1,0,0,0],
  16. [0,1,1,1,1,1,1,1,0,0,0],
  17. [0,0,0,0,1,1,1,1,0,0,0],
  18. [0,0,0,0,0,1,1,0,0,0,0],
  19. [0,0,0,0,1,1,0,0,0,0,0],
  20. [0,0,0,0,0,1,1,1,0,0,0],
  21. [0,0,0,0,1,0,0,0,0,0,0]]
  22.  
  23. def traverse(x, y,count):
  24. if x < 0 or x > 11:
  25. return
  26. if y < 0 or y > 11:
  27. return
  28. if checked[x][y] == True:
  29. return
  30. checked[x][y] = True
  31. if multd[x][y] == 1:
  32. count += 1
  33. print(count)
  34. traverse(x-1,y, count)
  35. #traverse(x-1,y-1,count)
  36. traverse(x+1,y, count)
  37. # traverse(x+1,y-1,count)
  38. traverse(x,y-1, count)
  39. #traverse(x+1,y+1,count)
  40. traverse(x,y+1, count)
  41. #traverse(x-1,y+1,count)
  42. return count
  43.  
  44. traverse(5,5,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement