Created
May 5, 2013 23:59
-
-
Save jamiees2/5522641 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/python | |
dirts = [] | |
finished = False | |
selected = -1 | |
def find_all_dirts(board): | |
global dirts | |
n = len(board) | |
m = len(board[0]) | |
for x in range(n): | |
for y in range(m): | |
if board[x][y] == 'd': | |
dirts.append((x, y)) | |
global finished | |
finished = True | |
def find_dirt(x, y): | |
min_dist = 10**2#something huge | |
for i in xrange(len(dirts)): | |
dirt_x, dirt_y = dirts[i] | |
dist_x = x - dirt_x if x > dirt_x else dirt_x - x | |
dist_y = y - dirt_y if y > dirt_y else dirt_y - y | |
dist = dist_x + dist_y | |
if dist < min_dist: | |
min_idx = i | |
min_dist = dist | |
global selected | |
selected = min_idx | |
# Head ends here | |
def next_move(x, y, board): | |
global selected | |
if finished == False: | |
find_all_dirts(board) | |
if selected == -1: | |
find_dirt(x,y) | |
dirt_x, dirt_y = dirts[selected] | |
if x == dirt_x and y == dirt_y: | |
print "CLEAN" | |
dirts.pop(selected) | |
selected = -1 | |
elif dirt_x > x: | |
print "DOWN" | |
elif x > dirt_x: | |
print "UP" | |
elif y > dirt_y: | |
print "LEFT" | |
elif dirt_y > y: | |
print "RIGHT" | |
# Tail starts here | |
if __name__ == "__main__": | |
pos = [int(i) for i in raw_input().strip().split()] | |
board = [[j for j in raw_input().strip()] for i in range(5)] | |
next_move(pos[0], pos[1], board) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment