Skip to content

Commit

Permalink
works now
Browse files Browse the repository at this point in the history
  • Loading branch information
jjshoots committed Feb 23, 2024
1 parent 9f4d030 commit 904c5df
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 24 deletions.
152 changes: 140 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
## ALE

ale
build
doc/examples/*Example

## Generic

# Emacs temp files
*~
.*
*#
# Don't save roms in repo
*.bin
*.tar.gz

# Auto-generated dependency files
.deps
Expand All @@ -20,15 +16,147 @@ doc/examples/*Example
*.o
*.d

# Compiled Dynamic libraries
*.so

# Compiled Static libraries
*.lai
*.la
*.a

# Python
*.pyc
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ classifiers = [
]
dependencies = [
"numpy",
"requests",
"importlib-metadata>=4.10.0; python_version < '3.10'",
"importlib-resources; python_version < '3.9'",
"typing-extensions; python_version < '3.11'"
Expand Down
3 changes: 2 additions & 1 deletion src/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@

register_v0_v4_envs()
register_v5_envs()
except ImportError:
except ImportError as e:
print(e)
pass
2 changes: 1 addition & 1 deletion src/python/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _register_rom_configs(

# Register the environment
gymnasium.register(
id=f"{prefix}{name}{flavour.suffix}-{config.version}",
id=f"ALE/{prefix}{name}{flavour.suffix}-{config.version}",
entry_point="ale_py.env:AtariEnv",
kwargs=dict(
game=rom,
Expand Down
24 changes: 14 additions & 10 deletions src/python/roms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Extract each valid ROM into each dir in installation_dirs
def _download_roms():
# this is a map of {rom.bin : md5 checksum}
all_roms = json.load(open(Path(__file__).parent / "md5.yaml"))
all_roms = json.load(open(Path(__file__).parent / "md5.json"))

# use requests to download the base64 file
url = "https://gist.githubusercontent.com/jjshoots/61b22aefce4456920ba99f2c36906eda/raw/00046ac3403768bfe45857610a3d333b8e35e026/Roms.tar.gz.b64"
Expand All @@ -31,10 +31,14 @@ def _download_roms():
if not (member.isfile() and member.name.endswith(".bin")):
continue

# grab the rom name from the member name
# by default, the roms have the hierarchy ROM/rom_name/rom_name.bin
rom_name = member.name.split("/")[-1]

# assert that this member.name should be supported
assert (
member.name in all_roms
), f"File {member.name} not supported. Please report this to a dev."
rom_name in all_roms
), f"File {rom_name} not supported. Please report this to a dev."

# extract the rom file from the archive
rom_bytes = tar_fp.extractfile(member).read() # pyright: ignore[reportOptionalMemberAccess]
Expand All @@ -46,14 +50,14 @@ def _download_roms():

# assert that the hash matches
assert (
md5_hash == all_roms[member.name]
), f"Rom {member.name}'s hash does not match what was expected. Please report this to a dev."
md5_hash == all_roms[rom_name]
), f"Rom {rom_name}'s hash does not match what was expected. Please report this to a dev."

# save this rom
rom_path = Path(__file__).parent / member.name
rom_path = Path(__file__).parent / rom_name
open(rom_path, "wb").write(rom_bytes)

print(f"Downloaded and unpacked {member.name}.")
print(f"Downloaded and unpacked {rom_name}.")


def get_rom_path(name: str) -> Path | None:
Expand All @@ -62,8 +66,8 @@ def get_rom_path(name: str) -> Path | None:
bin_file = f"{name}.bin"
bin_path = Path(__file__).parent / bin_file

# check if it exists within the md5.yaml
all_roms = json.load(open(Path(__file__).parent / "md5.yaml"))
# check if it exists within the md5.json
all_roms = json.load(open(Path(__file__).parent / "md5.json"))
if bin_file not in all_roms:
warnings.warn(f"Rom {name} not supported.")
return None
Expand All @@ -80,5 +84,5 @@ def get_rom_path(name: str) -> Path | None:

def get_all_rom_ids() -> list[str]:
"""Returns a list of all available rom_ids, ie: ['tetris', 'pong', 'zaxxon', ...]."""
all_roms = json.load(open(Path(__file__).parent / "md5.yaml"))
all_roms = json.load(open(Path(__file__).parent / "md5.json"))
return [key.split(".")[0] for key in all_roms.keys()]
4 changes: 4 additions & 0 deletions src/python/roms/md5.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"casino.bin": "b816296311019ab69a21cb9e9e235d12",
"centipede.bin": "91c2098e88a6b13f977af8c003e0bca5",
"chopper_command.bin": "c1cb228470a87beb5f36e90ac745da26",
"combat.bin": "0ef64cdbecccb7049752a3de0b7ade14",
"crazy_climber.bin": "55ef7b65066428367844342ed59f956c",
"crossbow.bin": "8cd26dcf249456fe4aeb8db42d49df74",
"darkchambers.bin": "106855474c69d08c8ffa308d47337269",
Expand Down Expand Up @@ -49,6 +50,7 @@
"ice_hockey.bin": "a4c08c4994eb9d24fb78be1793e82e26",
"jamesbond.bin": "e51030251e440cffaab1ac63438b44ae",
"journey_escape.bin": "718ae62c70af4e5fd8e932fee216948a",
"joust.bin": "3276c777cbe97cdd2b4a63ffc16b7151",
"kaboom.bin": "5428cdfada281c569c74c7308c7f2c26",
"kangaroo.bin": "4326edb70ff20d0ee5ba58fa5cb09d60",
"keystone_kapers.bin": "6c1f3f2e359dbf55df462ccbcdd2f6bf",
Expand All @@ -60,6 +62,7 @@
"laser_gates.bin": "8e4cd60d93fcde8065c1a2b972a26377",
"lost_luggage.bin": "2d76c5d1aad506442b9e9fb67765e051",
"mario_bros.bin": "e908611d99890733be31733a979c62d8",
"maze_craze.bin": "ed2218b3075d15eaa34e3356025ccca3",
"miniature_golf.bin": "df62a658496ac98a3aa4a6ee5719c251",
"montezuma_revenge.bin": "3347a6dd59049b15a38394aa2dafa585",
"mr_do.bin": "aa7bb54d2c189a31bb1fa20099e42859",
Expand Down Expand Up @@ -99,6 +102,7 @@
"video_chess.bin": "f0b7db930ca0e548c41a97160b9f6275",
"video_cube.bin": "3f540a30fdee0b20aed7288e4a5ea528",
"video_pinball.bin": "107cc025334211e6d29da0b6be46aec7",
"warlords.bin": "cbe5a166550a8129a5e6d374901dffad",
"wizard_of_wor.bin": "7e8aa18bc9502eb57daaf5e7c1e94da7",
"word_zapper.bin": "ec3beb6d8b5689e867bafb5d5f507491",
"yars_revenge.bin": "c5930d0e8cdae3e037349bfa08e871be",
Expand Down

0 comments on commit 904c5df

Please sign in to comment.