-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovement.py
101 lines (73 loc) · 2.61 KB
/
movement.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from setup import *
def log_movement(state, direction):
if state == 1:
print(f"SUCCESS: mice move {direction.upper()} | pos: {mouse}")
elif state == 0:
print(f"FAILURE: mice move {direction.upper()} | pos: {mouse}")
def check_tile(x, y):
if (finish[0] == x) and (finish[1] == y):
return 'finish'
elif maze[y][x] == 0:
return 'open'
elif maze[y][x] == 1:
return 'wall'
else:
return 'error'
def move(direction):
current_x = mouse[0]
current_y = mouse[1]
if direction == 'right':
new_x = current_x + 1
if check_tile(new_x, current_y) == 'open':
mouse[0] = new_x
log_movement(1, direction)
elif check_tile(new_x, current_y) == 'wall':
log_movement(0, direction)
elif check_tile(new_x, current_y) == 'finish':
print("SUCCESS: finish reached!")
exit()
elif check_tile(new_x, current_y) == 'error':
print("FAILURE: unknown tile")
exit()
elif direction == 'left':
new_x = current_x - 1
if check_tile(new_x, current_y) == 'open':
mouse[0] = new_x
log_movement(1, direction)
elif check_tile(new_x, current_y) == 'wall':
log_movement(0, direction)
elif check_tile(new_x, current_y) == 'finish':
print("SUCCESS: finish reached!\n")
exit()
elif check_tile(new_x, current_y) == 'error':
print("FAILURE: unknown tile")
exit()
elif direction == 'up':
new_y = current_y - 1
if check_tile(current_x, new_y) == 'open':
mouse[1] = new_y
log_movement(1, direction)
elif check_tile(current_x, new_y) == 'wall':
log_movement(0, direction)
elif check_tile(current_x, new_y) == 'finish':
print("SUCCESS: finish reached!")
exit()
elif check_tile(current_x, new_y) == 'error':
print("FAILURE: unknown tile")
exit()
elif direction == 'down':
new_y = current_y + 1
if check_tile(current_x, new_y) == 'open':
mouse[1] = new_y
log_movement(1, direction)
elif check_tile(current_x, new_y) == 'wall':
log_movement(0, direction)
elif check_tile(current_x, new_y) == 'finish':
print("SUCCESS: finish reached!")
exit()
elif check_tile(current_x, new_y) == 'error':
print("FAILURE: unknown tile")
exit()
def reset_pos(start_pos):
mouse[0] = start_pos[0]
mouse[1] = start_pos[1]