@@ -33,30 +33,34 @@ class NoopResetEnv(gym.Wrapper):
3333 """
3434
3535 def __init__ (self , env , noop_max = 30 ):
36+ """Initialize the no-op reset wrapper."""
3637 super ().__init__ (env )
3738 self .noop_max = noop_max
3839 self .noop_action = 0
3940 assert env .unwrapped .get_action_meanings ()[0 ] == "NOOP"
4041
4142 def reset (self , * , seed = None , options = None ):
43+ """Reset the environment after a random number of no-op actions."""
4244 obs , info = self .env .reset (seed = seed , options = options )
4345 noops = self .unwrapped .np_random .integers (1 , self .noop_max + 1 )
4446 for _ in range (noops ):
45- obs , _ , terminated , truncated , info = self .env .step (self .noop_action )
47+ obs , _ , terminated , truncated , info = self .env .step (
48+ self .noop_action
49+ )
4650 if terminated or truncated :
4751 obs , info = self .env .reset ()
4852 return obs , info
4953
5054
5155class MaxAndSkipEnv (gym .Wrapper ):
52- """Return only every `skip`-th frame (frameskipping) using most recent raw
53- observations (for max pooling across time steps)
56+ """Return every `skip`-th frame with max pooling over recent frames.
5457
5558 :param gym.Env env: the environment to wrap.
5659 :param int skip: number of `skip`-th frame.
5760 """
5861
5962 def __init__ (self , env , skip = 4 ):
63+ """Initialize the instance."""
6064 super ().__init__ (env )
6165 self ._skip = skip
6266
@@ -85,11 +89,13 @@ class EpisodicLifeEnv(gym.Wrapper):
8589 """
8690
8791 def __init__ (self , env ):
92+ """Initialize episodic-life tracking."""
8893 super ().__init__ (env )
8994 self .lives = 0
9095 self .was_real_done = True
9196
9297 def step (self , action ):
98+ """Step the environment and treat life loss as episode end."""
9399 obs , reward , terminated , truncated , info = self .env .step (action )
94100 self .was_real_done = terminated or truncated
95101 # check current lives, make loss of life terminal, then update lives to
@@ -129,11 +135,13 @@ class FireResetEnv(gym.Wrapper):
129135 """
130136
131137 def __init__ (self , env ):
138+ """Initialize the fire-reset wrapper."""
132139 super ().__init__ (env )
133140 assert env .unwrapped .get_action_meanings ()[1 ] == "FIRE"
134141 assert len (env .unwrapped .get_action_meanings ()) >= 3
135142
136143 def reset (self , * , seed = None , options = None ):
144+ """Reset the environment and apply the fire action."""
137145 self .env .reset (seed = seed , options = options )
138146 obs , _ , terminated , truncated , info = self .env .step (1 )
139147 if terminated or truncated :
@@ -148,6 +156,7 @@ class WarpFrame(gym.ObservationWrapper):
148156 """
149157
150158 def __init__ (self , env ):
159+ """Initialize grayscale frame warping."""
151160 super ().__init__ (env )
152161 self .size = 84
153162 self .observation_space = gym .spaces .Box (
@@ -158,9 +167,11 @@ def __init__(self, env):
158167 )
159168
160169 def observation (self , frame ):
161- """Returns the current observation from a frame"""
170+ """Returns the current observation from a frame. """
162171 frame = cv2 .cvtColor (frame , cv2 .COLOR_RGB2GRAY )
163- return cv2 .resize (frame , (self .size , self .size ), interpolation = cv2 .INTER_AREA )
172+ return cv2 .resize (
173+ frame , (self .size , self .size ), interpolation = cv2 .INTER_AREA
174+ )
164175
165176
166177class ScaledFloatFrame (gym .ObservationWrapper ):
@@ -170,6 +181,7 @@ class ScaledFloatFrame(gym.ObservationWrapper):
170181 """
171182
172183 def __init__ (self , env ):
184+ """Initialize the instance."""
173185 super ().__init__ (env )
174186 low = np .min (env .observation_space .low )
175187 high = np .max (env .observation_space .high )
@@ -183,6 +195,7 @@ def __init__(self, env):
183195 )
184196
185197 def observation (self , observation ):
198+ """Scale an observation to the [0, 1] range."""
186199 return (observation - self .bias ) / self .scale
187200
188201
@@ -193,6 +206,7 @@ class ClipRewardEnv(gym.RewardWrapper):
193206 """
194207
195208 def __init__ (self , env ):
209+ """Initialize reward clipping."""
196210 super ().__init__ (env )
197211 self .reward_range = (- 1 , 1 )
198212
@@ -209,6 +223,7 @@ class FrameStack(gym.Wrapper):
209223 """
210224
211225 def __init__ (self , env , n_frames ):
226+ """Initialize the frame stack buffer."""
212227 super ().__init__ (env )
213228 self .n_frames = n_frames
214229 self .frames = deque ([], maxlen = n_frames )
@@ -221,12 +236,14 @@ def __init__(self, env, n_frames):
221236 )
222237
223238 def reset (self , * , seed = None , options = None ):
239+ """Reset the environment and refill the frame stack."""
224240 obs , info = self .env .reset (seed = seed , options = options )
225241 for _ in range (self .n_frames ):
226242 self .frames .append (obs )
227243 return self ._get_ob (), info
228244
229245 def step (self , action ):
246+ """Step the environment and append the latest frame."""
230247 obs , reward , terminated , truncated , info = self .env .step (action )
231248 self .frames .append (obs )
232249 return self ._get_ob (), reward , terminated , truncated , info
0 commit comments