-
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.
- Loading branch information
Showing
7 changed files
with
107 additions
and
45 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Gym is made for single agents envs, therefore only one player is supported | ||
# MAYBE a multi agent version (likly following PettingZoo's API) will be made eventually | ||
|
||
# from gymnasium.envs.registration import register | ||
|
||
# register(id="retropy/RetroGym-v0", entry_point="retropy.frontends.gym.gym:RetroGym") |
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 +1,39 @@ | ||
# gymnasium wrapper with discrete inputs | ||
# gymnasium wrapper with | ||
# - discrete inputs | ||
|
||
from .gym import RetroGym | ||
from ...utils.input import GamePadInput | ||
|
||
import gymnasium as gym | ||
from gymnasium import spaces, ActionWrapper | ||
|
||
# https://gymnasium.farama.org/tutorials/gymnasium_basics/implementing_custom_wrappers/ | ||
|
||
|
||
class DiscreteInputs(ActionWrapper): | ||
""" | ||
Map discrete actions into controller inputs. | ||
Example: | ||
>>> env = RetroGym(core, rom) | ||
>>> action_map = [["A"], ["B"], ["LEFT"], ["RIGHT", "A"], ["LEFT_X"]] | ||
>>> env = DiscreteInputs(env, action_map) | ||
>>> print(env.action_space) # -> Discrete(5) | ||
""" | ||
|
||
def __init__(self, env: RetroGym, map: list[list[str]]): | ||
super().__init__(env) | ||
self.map = map | ||
self.action_space = spaces.Discrete(len(self.map)) | ||
|
||
def action(self, action: int): | ||
inputs = self.map[action] | ||
|
||
action = [0] * len(GamePadInput) | ||
for i, input in enumerate(GamePadInput): | ||
if input in inputs: | ||
action[i] = 1 | ||
|
||
print(action) | ||
|
||
return action |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
__core = "C:/Users/Gerald/AppData/Local/RetroArch/cores/" | ||
|
||
__game = "C:/Users/Gerald/AppData/Local/RetroArch/roms/" | ||
|
||
SYSTEMS = { | ||
"GBA": (__core + "mgba_libretro.dll", __game + "Tetris.gb"), | ||
"N64": (__core + "parallel_n64_libretro.dll", __game + "Super Mario 64.n64"), | ||
} | ||
|
||
__all__ = ["SYSTEMS"] |
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