def wrapped_mario_env_optical():
    """
    **Overview**:
        Wrap mario environment with optical flow wrapper.
    """
    # Original environment declaration.
    env = gym_super_mario_bros.make("SuperMarioBros-1-1-v0")
    return DingEnvWrapper(
        # Restrict action space to 2 discrete action: right and jump (A).
        JoypadSpace(env, [["right"], ["right", "A"]]),
        cfg={
            'env_wrapper': [
                # Return the max value of states in adjacent 4 frames. This works like a max-pooling in temporal dimension.
                lambda env: MaxAndSkipWrapper(env, skip=4),
                # Resize (bilinear interpolation) the image size into 84 x 84 and convert RGB to GREY.
                lambda env: WarpFrameWrapper(env, size=84),
                # Add optical flow information.
                lambda env: OpticalFlowWrapper(env),
                # Normalize the state value into [0, 1]. $$scaled\_x = \frac {x - \min(x)} {\max(x) - \min (x)} $$
                lambda env: ScaledFloatFrameWrapper(env),
                # Calculate episode return for evaluation.
                lambda env: EvalEpisodeReturnEnv(env),
            ]
        }
    )

    **Overview**:
        Wrap mario environment with optical flow wrapper.
    
chapter3_obs/mario_wrapper.py