Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. def laba(Maze,pozIn,pozOut):
  2. weight=0
  3. Task=[[pozIn[0],pozIn[1],pozIn[2]]]
  4. print(Task[0][2])
  5. Back=Task
  6. for i in range(len(Maze)*len(Maze[0])):
  7. weight+=1
  8. Task=Task[len(Task):]
  9. Task=Back
  10. Back=Back[len(Back):]
  11. for i in range (0,len(Task)):
  12. if Task[i][2]==0: print(':(')
  13. if Maze[Task[i][0]+1][Task[i][1]]==0:
  14. Maze[Task[i][0]+1][Task[i][1]]=weight
  15. Back.append([Task[i][0]+1,Task[i][1],1])
  16. if [Task[i][0]+1,Task[i][1]]==pozOut:
  17. return 0
  18. if Maze[Task[i][0]-1][Task[i][1]]==0:
  19. Maze[Task[i][0]-1][Task[i][1]]=weight
  20. Back.append([Task[i][0]-1,Task[i][1],1])
  21. if [Task[i][0]-1,Task[i][1]]==pozOut:
  22. return 0
  23. if Maze[Task[i][0]][Task[i][1]+1]==0:
  24. Maze[Task[i][0]][Task[i][1]+1]=weight
  25. Back.append([Task[i][0],Task[i][1]+1,1])
  26. if [Task[i][0],Task[i][1]+1]==pozOut:
  27. return 0
  28. if Maze[Task[i][0]][Task[i][1]-1]==0:
  29. Maze[Task[i][0]][Task[i][1]-1]=weight
  30. Back.append([Task[i][0],Task[i][1]-1,1])
  31. if [Task[i][0],Task[i][1]-1]==pozOut:
  32. return 0
  33.  
  34.  
  35.  
  36.  
  37. def main():
  38. Maze =[
  39. [-1,-1,-1,-1,-1,-1,-1],
  40. [-1, 0, 0, 0, 0, 0,-1],
  41. [-1, 0, 0, 0, 0, 0,-1],
  42. [-1, 0, 0, 0, 0, 0,-1],
  43. [-1, 0, 0, 0, 0, 0,-1],
  44. [-1,-1,-1,-1,-1,-1,-1]
  45. ]
  46. pozIn=[2,1,0]
  47. pozOut=[4,4]
  48.  
  49. laba(Maze,pozIn,pozOut)
  50. Maze[pozIn[0]][pozIn[1]]=0
  51. for i in range(0,len(Maze)):
  52. print (Maze[i])
  53.  
  54. if __name__ == '__main__':
  55. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement