Advertisement
AltronZ

zaptnakbot

Jul 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. def make_choice(x,y,field):
  2. actions = ["fire_up", "fire_down",
  3. "fire_left", "fire_right",
  4. "go_up","go_down",
  5. "go_left","go_right"]
  6.  
  7. q = []
  8. q.append((x+1,y,'go_right'))
  9. q.append((x,y-1,'go_up'))
  10. q.append((x-1,y,'go_left'))
  11. q.append((x,y+1,'go_down'))
  12. while len(q)>0:
  13. i, j, parent = q[0]
  14. del q[0]
  15.  
  16.  
  17. if i < 0 or i >= len(field):
  18. continue
  19. if j < 0 or j >= len(field[0]):
  20. continue
  21. if field[i][j]==-1 or field[i][j] not in [-1,1,0]:
  22. continue
  23. if field[i][j]==1:
  24. return parent
  25. field[i][j]=-1
  26. q.append((i+1,j,parent))
  27. q.append((i,j-1,parent))
  28. q.append((i-1,j,parent))
  29. q.append((i,j+1,parent))
  30.  
  31.  
  32.  
  33.  
  34.  
  35. if __name__ == "__main__":
  36. T = {"life": 10}
  37. my_field = [
  38. [0,0,0,0],
  39. [0,T,0,0],
  40. [0,0,T,1],
  41. [0,0,0,0]
  42. ]
  43. my_x = 1
  44. my_y = 1
  45. res = make_choice(my_x, my_y, my_field)
  46. print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement