-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpitfall_random.py
More file actions
67 lines (64 loc) · 2.8 KB
/
pitfall_random.py
File metadata and controls
67 lines (64 loc) · 2.8 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
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
import retro
game = 'Pitfall-Atari2600'
scenario = 'scenario'
record = True
verbose = 1
quiet = 0
obs_type = 'image'
players = 1
'''
parser.add_argument('--game', default=GAME, help='the name or path for the game to run')
parser.add_argument('--state', help='the initial state file to load, minus thes extension')
parser.add_argument('--scenario', '-s', default='scenario', help='the scenario file to load, minus the extension')
parser.add_argument('--record', '-r', action='store_true', help='record bk2 movies')
parser.add_argument('--verbose', '-v', action='count', default=1, help='increase verbosity (can be specified multiple times)')
parser.add_argument('--quiet', '-q', action='count', default=0, help='decrease verbosity (can be specified multiple times)')
parser.add_argument('--obs-type', '-o', default='image', choices=['image', 'ram'], help='the observation type, either `image` (default) or `ram`')
parser.add_argument('--players', '-p', type=int, default=1, help='number of players/agents (default: 1)')
args = parser.parse_args()
'''
obs_type = retro.Observations.IMAGE if obs_type == 'image' else retro.Observations.RAM
env = retro.make(game, retro.State.DEFAULT, scenario=scenario, record=record, players=players, obs_type=obs_type)
verbosity = verbose - quiet
try:
while True:
ob = env.reset()
t = 0
totrew = [0] * players
while True:
ac = env.action_space.sample()
ob, rew, done, info = env.step(ac)
t += 1
if t % 1 == 0:
if verbosity > 1:
infostr = ''
if info:
infostr = ', info: ' + ', '.join(['%s=%i' % (k, v) for k, v in info.items()])
print(('t=%i' % t) + infostr)
env.render()
if players == 1:
rew = [rew]
for i, r in enumerate(rew):
totrew[i] += r
if verbosity > 0:
if r > 0:
print('t=%i p=%i got reward: %g, current reward: %g' % (t, i, r, totrew[i]))
if r < 0:
print('t=%i p=%i got penalty: %g, current reward: %g' % (t, i, r, totrew[i]))
if done:
env.render()
try:
if verbosity >= 0:
if players > 1:
print("done! total reward: time=%i, reward=%r" % (t, totrew))
else:
print("done! total reward: time=%i, reward=%d" % (t, totrew[0]))
input("press enter to continue")
print()
else:
input("")
except EOFError:
exit(0)
break
except KeyboardInterrupt:
exit(0)