Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def make_choice(x,y,field):
- actions = ["fire_up", "fire_down",
- "fire_left", "fire_right",
- "go_up","go_down",
- "go_left","go_right"]
- q = []
- q.append((x+1,y,'go_right'))
- q.append((x,y-1,'go_up'))
- q.append((x-1,y,'go_left'))
- q.append((x,y+1,'go_down'))
- while len(q)>0:
- i, j, parent = q[0]
- del q[0]
- if i < 0 or i >= len(field):
- continue
- if j < 0 or j >= len(field[0]):
- continue
- if field[i][j]==-1 or field[i][j] not in [-1,1,0]:
- continue
- if field[i][j]==1:
- return parent
- field[i][j]=-1
- q.append((i+1,j,parent))
- q.append((i,j-1,parent))
- q.append((i-1,j,parent))
- q.append((i,j+1,parent))
- if __name__ == "__main__":
- T = {"life": 10}
- my_field = [
- [0,0,0,0],
- [0,T,0,0],
- [0,0,T,1],
- [0,0,0,0]
- ]
- my_x = 1
- my_y = 1
- res = make_choice(my_x, my_y, my_field)
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement