-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBotClean.py
64 lines (48 loc) · 1.56 KB
/
BotClean.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
# Head ends here
def next_move(posr, posc, board):
if board[posr][posc] == 'd':
print("CLEAN")
return
dirty_cells = [(i, j) for i in range(len(board))
for j in range(len(board[0])) if board[i][j] == 'd']
best_cell, best_distance = None, float('inf')
for i, j in dirty_cells:
temp_distance = abs(posr - i) + abs(posc - j)
if temp_distance < best_distance:
best_cell = (i, j)
best_distance = temp_distance
# find the best move
if posr - best_cell[0] < 0:
print("DOWN")
elif posr - best_cell[0] > 0:
print("UP")
elif posc - best_cell[1] < 0:
print("RIGHT")
else:
print("LEFT")
return
# def next_move(posr, posc, board):
# next_move = ""
# mini_move = len(board[0])
# for cell_in_h in range(len(board[posr])):
# if(board[posr][cell_in_h] == "d"):
# h_move = cell_in_h - posc
# if(abs(h_move) < mini_move):
# mini_move = abs(h_move)
# if(h_move > 0):
# next_move = "RIGHT"
# if(h_move < 0):
# next_move = "LEFT"
# if(h_move == 0):
# next_move = "CLEAN"
# if(next_move != ""):
# print(next_move)
# else:
# print("DOWN")
# return
# Tail starts here
if __name__ == "__main__":
pos = [int(i) for i in input().strip().split()]
board = [[j for j in input().strip()] for i in range(5)]
next_move(pos[0], pos[1], board)