Last active
December 15, 2016 07:59
-
-
Save imakin/0e46da6ec1ed36ae7d28da3df37dffeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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