Skip to content

Instantly share code, notes, and snippets.

@imakin
Last active December 15, 2016 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imakin/0e46da6ec1ed36ae7d28da3df37dffeb to your computer and use it in GitHub Desktop.
Save imakin/0e46da6ec1ed36ae7d28da3df37dffeb to your computer and use it in GitHub Desktop.
def next_move(posx, posy, dimx, dimy, board):
if board[posy][posx]=="d":
print("CLEAN")
return
shortest_path = 5000
shortest_coord = (-1,-1)
for y in range(len(board)):
for x in range(len(board[y])):
if board[y][x]=="d":
effort = ((posy-y)**2+(posx-x)**2)**0.5
if effort< shortest_path:
shortest_path = effort
shortest_coord = (y,x)
if shortest_coord != (-1,-1):
y,x = shortest_coord
if abs(posx-x)>=abs(posy-y):
if x<posx:
print("LEFT")
else:
print("RIGHT")
else:
if y<posy:
print("UP")
else:
print("DOWN")
return
print("HOI")
return
if __name__=="__main__":
pos = [int(i) for i in input().strip().split()]
dim = [int(i) for i in input().strip().split()]
board = [ [j for j in input().strip()] for i in range(dim[0])]
next_move(pos[1], pos[0], dim[0], dim[1], board)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment