-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement preprocessing of the environment
- Loading branch information
Showing
3 changed files
with
20 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
from gym.wrappers import gray_scale_observation | ||
from gymnasium.wrappers import gray_scale_observation | ||
from stable_baselines3.common.vec_env import VecFrameStack, DummyVecEnv | ||
from matplotlib import pyplot as plt | ||
from config.gym import ZeldaGymEnv | ||
from gym.spaces import Box | ||
|
||
|
||
def Preprocess(config: dict) -> DummyVecEnv: | ||
def PreprocessEnv(config: dict) -> VecFrameStack: | ||
""" | ||
Preprocesses the environment for reinforcement learning. | ||
Args: | ||
config (dict): Configuration parameters for the environment. | ||
Returns: | ||
VecFrameStack: Preprocessed environment with stacked frames. | ||
""" | ||
|
||
env = ZeldaGymEnv(config, debug=True) | ||
env = gray_scale_observation.GrayScaleObservation(env, keep_dim=True) | ||
# env = DummyVecEnv([lambda: env]) | ||
# env = VecFrameStack(env, n_stack=4, channel_order='last') | ||
env = DummyVecEnv([lambda: env]) | ||
env = VecFrameStack(env, n_stack=4) | ||
|
||
return env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
from config.preprocess import Preprocess | ||
from config.preprocess import PreprocessEnv | ||
|
||
if __name__ == "__main__": | ||
config = { | ||
'rom_path': 'roms/ZeldaLinksAwakening.gb', | ||
'state_path': 'roms/ZeldaLinksAwakening.gb.state' | ||
} | ||
|
||
env = Preprocess(config) | ||
|
||
env = PreprocessEnv(config) | ||
done = True | ||
for step in range(100000): | ||
if done: | ||
env.reset() | ||
observation, reward, done, truncated, info = env.step( | ||
env.action_space.sample()) | ||
print(observation.shape) | ||
observation, reward, done, info = env.step( | ||
[env.action_space.sample()]) | ||
env.render() | ||
env.close() |