Advertisement
Xlorddx

Untitled

Aug 19th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import random
  2.  
  3. def make_choice(x, y,field, num_of_steps=None):
  4.     actions = ["fire_up", "fire_down",
  5.                "fire_left", "fire_right",]
  6.     shagi = ["go_up","go_down",
  7.             "go_left","go_right"]
  8.    
  9.     width=len(field)
  10.     height=len(field[0])
  11.     my_history=field[x][y]['history']
  12.     num_of_steps= len(field[x][y]['history'])
  13.     for i in range (x-1,-1,-1):
  14.         if field[i][y] ==-1:
  15.             break
  16.         if field[i][y] not in [-1,0,1]:
  17.             return 'fire_left'
  18.     for i in range (x+1,width):
  19.         if field[i][y] ==-1:
  20.             break
  21.         if field[i][y] not in [-1,0,1]:
  22.             return 'fire_right'
  23.     for i in range (y-1,-1,-1):
  24.         if field[x][i]==-1:
  25.             break
  26.         if field[x][i] not in [-1,0,1]:
  27.             return 'fire_up'
  28.     for i in range (y+1,height):
  29.         if field[x][i]==-1:
  30.             break
  31.         if field[x][i] not in[-1,0,1]:
  32.             return 'fire_down'
  33.     return random.choice(shagi)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement