-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
56 lines (47 loc) · 1.4 KB
/
bot.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
from maze import runMaze
from maze_functions import get_instructions
import pydirectinput
import time
WALK_SPEED = 4.317
def moveRight(duration):
pydirectinput.keyDown("d")
time.sleep(duration/WALK_SPEED)
pydirectinput.keyUp("d")
def moveLeft(duration):
pydirectinput.keyDown("a")
time.sleep(duration/WALK_SPEED)
pydirectinput.keyUp("a")
def moveBack(duration):
pydirectinput.keyDown("s")
time.sleep(duration/WALK_SPEED)
pydirectinput.keyUp("s")
def moveFront(duration):
pydirectinput.keyDown("w")
time.sleep(duration/WALK_SPEED)
pydirectinput.keyUp("w")
path = runMaze()
instructions = get_instructions(path)
time.sleep(3)
# for smoother walk
def getDistance(instructions):
counter = 0
current_character = instructions[counter]
if instructions[:-1] == instructions[1:]:
return current_character, len(instructions)
else:
while current_character == instructions[counter]:
counter += 1
return current_character, counter
while len(instructions) > 0:
instruction, duration = getDistance(instructions)
if instruction == 'R':
moveRight(duration)
elif instruction == 'L':
moveLeft(duration)
elif instruction == 'D':
moveBack(duration)
elif instruction == 'U':
moveFront(duration)
else:
print("Unknown instruction")
instructions = instructions[duration:]