-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from Kautenja/4.0.1
4.0.1
- Loading branch information
Showing
20 changed files
with
284 additions
and
282 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
"""Registration code of Gym environments in this package.""" | ||
from .smb_env import SuperMarioBrosEnv | ||
from .smb_stage_env import SuperMarioBrosStageEnv | ||
from ._registration import make | ||
|
||
|
||
# define the outward facing API of this package | ||
__all__ = [ | ||
make.__name__, | ||
SuperMarioBrosEnv.__name__, | ||
SuperMarioBrosStageEnv.__name__, | ||
] |
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 was deleted.
Oops, something went wrong.
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 @@ | ||
"""Methods for ROM file management.""" | ||
from .decode_target import decode_target | ||
from .rom_path import rom_path | ||
|
||
|
||
# explicitly define the outward facing API of this package | ||
__all__ = [ | ||
decode_target.__name__, | ||
rom_path.__name__, | ||
] |
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,71 @@ | ||
"""A method to decode target values for a ROM stage environment.""" | ||
|
||
|
||
def decode_target(target, lost_levels): | ||
""" | ||
Return the target area for target world and target stage. | ||
Args: | ||
target_world (None, int): the world to target | ||
target_stage (None, int): the stage to target | ||
lost_levels (bool): whether to use lost levels game | ||
Returns (int): | ||
the area to target to load the target world and stage | ||
""" | ||
# Type and value check the lost levels parameter | ||
if not isinstance(lost_levels, bool): | ||
raise TypeError('lost_levels must be of type: bool') | ||
# if there is no target, the world, stage, and area targets are all None | ||
if target is None: | ||
return None, None, None | ||
elif not isinstance(target, tuple): | ||
raise TypeError('target must be of type tuple') | ||
# unwrap the target world and stage | ||
target_world, target_stage = target | ||
# Type and value check the target world parameter | ||
if not isinstance(target_world, int): | ||
raise TypeError('target_world must be of type: int') | ||
else: | ||
if lost_levels: | ||
if not 1 <= target_world <= 12: | ||
raise ValueError('target_world must be in {1, ..., 12}') | ||
elif not 1 <= target_world <= 8: | ||
raise ValueError('target_world must be in {1, ..., 8}') | ||
# Type and value check the target level parameter | ||
if not isinstance(target_stage, int): | ||
raise TypeError('target_stage must be of type: int') | ||
else: | ||
if not 1 <= target_stage <= 4: | ||
raise ValueError('target_stage must be in {1, ..., 4}') | ||
|
||
# no target are defined for no target world or stage situations | ||
if target_world is None or target_stage is None: | ||
return None | ||
# setup target area if target world and stage are specified | ||
target_area = target_stage | ||
# setup the target area depending on whether this is SMB 1 or 2 | ||
if lost_levels: | ||
# setup the target area depending on the target world and stage | ||
if target_world in {1, 3}: | ||
if target_stage >= 2: | ||
target_area = target_area + 1 | ||
elif target_world >= 5: | ||
# TODO: figure out why all worlds greater than 5 fail. | ||
# target_area = target_area + 1 | ||
# for now just raise a value error | ||
worlds = set(range(5, 12 + 1)) | ||
msg = 'lost levels worlds {} not supported'.format(worlds) | ||
raise ValueError(msg) | ||
else: | ||
# setup the target area depending on the target world and stage | ||
if target_world in {1, 2, 4, 7}: | ||
if target_stage >= 2: | ||
target_area = target_area + 1 | ||
|
||
return target_world, target_stage, target_area | ||
|
||
|
||
# explicitly define the outward facing API of this module | ||
__all__ = [decode_target.__name__] |
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,53 @@ | ||
"""A method to load a ROM path.""" | ||
import os | ||
|
||
|
||
# a dictionary mapping ROM paths first by lost levels, then by ROM hack mode | ||
_ROM_PATHS = { | ||
# the dictionary of lost level ROM paths | ||
True: { | ||
'vanilla': 'super-mario-bros-2.nes', | ||
'downsample': 'super-mario-bros-2-downsample.nes', | ||
}, | ||
# the dictionary of Super Mario Bros. 1 ROM paths | ||
False: { | ||
'vanilla': 'super-mario-bros.nes', | ||
'pixel': 'super-mario-bros-pixel.nes', | ||
'rectangle': 'super-mario-bros-rectangle.nes', | ||
'downsample': 'super-mario-bros-downsample.nes', | ||
} | ||
} | ||
|
||
|
||
def rom_path(lost_levels, rom_mode): | ||
""" | ||
Return the ROM filename for a game and ROM mode. | ||
Args: | ||
lost_levels (bool): whether to use the lost levels ROM | ||
rom_mode (str): the mode of the ROM hack to use as one of: | ||
- 'vanilla' | ||
- 'pixel' | ||
- 'downsample' | ||
- 'vanilla' | ||
Returns (str): | ||
the ROM path based on the input parameters | ||
""" | ||
# Type and value check the lost levels parameter | ||
if not isinstance(lost_levels, bool): | ||
raise TypeError('lost_levels must be of type: bool') | ||
# try the unwrap the ROM path from the dictionary | ||
try: | ||
rom = _ROM_PATHS[lost_levels][rom_mode] | ||
except KeyError: | ||
raise ValueError('rom_mode ({}) not supported!'.format(rom_mode)) | ||
# get the absolute path for the ROM | ||
rom = os.path.join(os.path.dirname(os.path.abspath(__file__)), rom) | ||
|
||
return rom | ||
|
||
|
||
# explicitly define the outward facing API of this module | ||
__all__ = [rom_path.__name__] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.