-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomAgent.py
More file actions
36 lines (26 loc) · 1.15 KB
/
randomAgent.py
File metadata and controls
36 lines (26 loc) · 1.15 KB
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
import retro
import time
def main():
"""
This script runs a random agent in the Super Mario Bros. environment.
Its purpose is to verify that your ROM and environment are working correctly
before we start a long training session.
"""
# Creates the Super Mario Bros. environment.
# render_mode="human" creates a window for you to see the game.
env = retro.make(game="SuperMarioBros-Nes", state="Level1-1", render_mode="human")
# Reset the environment to get the initial state.
env.reset()
# Loop forever to keep playing.
while True:
# env.action_space.sample() picks a random valid action.
action = env.action_space.sample()
# Apply the action to the game and get the results (returns 5 values).
observation, reward, terminated, truncated, info = env.step(action)
# If the episode is over (Mario dies or level ends), reset the environment.
if terminated or truncated:
env.reset()
# Add a small delay to make the game watchable at a human speed. e.g. 120 FPS.
time.sleep(1/120)
if __name__ == "__main__":
main()