MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / AtariPlayer

Class AtariPlayer

examples/DeepQNetwork/atari.py:24–165  ·  view source on GitHub ↗

A wrapper for ALE emulator, with configurations to mimic DeepMind DQN settings. Info: score: the accumulated reward in the current game gameOver: True when the current game is Over

Source from the content-addressed store, hash-verified

22
23
24class AtariPlayer(gym.Env):
25 """
26 A wrapper for ALE emulator, with configurations to mimic DeepMind DQN settings.
27
28 Info:
29 score: the accumulated reward in the current game
30 gameOver: True when the current game is Over
31 """
32
33 def __init__(self, rom_file, viz=0,
34 frame_skip=4, nullop_start=30,
35 live_lost_as_eoe=True, max_num_frames=0,
36 grayscale=True):
37 """
38 Args:
39 rom_file: path to the rom
40 frame_skip: skip every k frames and repeat the action
41 viz: visualization to be done.
42 Set to 0 to disable.
43 Set to a positive number to be the delay between frames to show.
44 Set to a string to be a directory to store frames.
45 nullop_start: start with random number of null ops.
46 live_losts_as_eoe: consider lost of lives as end of episode. Useful for training.
47 max_num_frames: maximum number of frames per episode.
48 grayscale (bool): if True, return 2D image. Otherwise return HWC image.
49 """
50 super(AtariPlayer, self).__init__()
51 if not os.path.isfile(rom_file) and '/' not in rom_file:
52 rom_file = get_dataset_path('atari_rom', rom_file)
53 assert os.path.isfile(rom_file), \
54 "ROM {} not found. Please download at {}".format(rom_file, ROM_URL)
55
56 try:
57 ALEInterface.setLoggerMode(ALEInterface.Logger.Error)
58 except AttributeError:
59 if execute_only_once():
60 logger.warn("You're not using latest ALE")
61
62 # avoid simulator bugs: https://github.com/mgbellemare/Arcade-Learning-Environment/issues/86
63 with _ALE_LOCK:
64 self.ale = ALEInterface()
65 self.rng = get_rng(self)
66 self.ale.setInt(b"random_seed", self.rng.randint(0, 30000))
67 self.ale.setInt(b"max_num_frames_per_episode", max_num_frames)
68 self.ale.setBool(b"showinfo", False)
69
70 self.ale.setInt(b"frame_skip", 1)
71 self.ale.setBool(b'color_averaging', False)
72 # manual.pdf suggests otherwise.
73 self.ale.setFloat(b'repeat_action_probability', 0.0)
74
75 # viz setup
76 if isinstance(viz, six.string_types):
77 assert os.path.isdir(viz), viz
78 self.ale.setString(b'record_screen_dir', viz)
79 viz = 0
80 if isinstance(viz, int):
81 viz = float(viz)

Callers 3

get_playerFunction · 0.90
get_playerFunction · 0.90
atari.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…