-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHumanPlayer.py
More file actions
31 lines (23 loc) · 827 Bytes
/
HumanPlayer.py
File metadata and controls
31 lines (23 loc) · 827 Bytes
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
import cv2
from object_collector.envs import Actions
from object_collector.envs import ObjectCollectorEnv
import keyboard
if __name__ == "__main__":
env = ObjectCollectorEnv(n_objectives=1)
env.reset()
while True:
state = env.map_state.get_current_state(env.agent)
cv2.imshow("game", state)
cv2.waitKey(1)
if keyboard.read_key() == "w":
obs, r, d, i = env.step(Actions.MOVE_ORIENTATION)
elif keyboard.read_key() == "a":
obs, r, d, i = env.step(Actions.TURN_LEFT)
elif keyboard.read_key() == "d":
obs, r, d, i =env.step(Actions.TURN_RIGHT)
state = env.map_state.get_current_state(env.agent)
cv2.imshow("game", state)
cv2.waitKey(1)
print(f"Reward: {r}")
if d:
env.reset()