Skip to content

Commit

Permalink
Simplify installation and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavian Hautbois committed Feb 21, 2018
1 parent f6a516e commit 9d86380
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pip install git+https://github.com/sicara/gym-super-mario.git

```python
import gym
import ppaquette_gym_super_mario
import super_mario
```

To show the emulator window fullscreen add an environment variable `export FULLSCREEN=true`
Expand Down
2 changes: 0 additions & 2 deletions ppaquette_gym_super_mario/package_info.py

This file was deleted.

21 changes: 7 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
from setuptools import setup, find_packages
import sys, os
from setuptools import setup

# Don't import gym module here, since deps may not be installed
for package in find_packages():
if '_gym_' in package:
sys.path.insert(0, os.path.join(os.path.dirname(__file__), package))
from package_info import USERNAME, VERSION

setup(name='{}-{}'.format(USERNAME, 'gym-super-mario'),
version=VERSION,
setup(name='super-mario',
version='1.0.0',
description='Gym User Env - 32 levels of Super Mario Bros',
url='https://github.com/ppaquette/gym_super_mario',
url='https://github.com/sicara/gym_super_mario',
author='Philip Paquette',
author_email='[email protected]',
license='MIT License',
packages=[package for package in find_packages() if package.startswith(USERNAME)],
package_data={ '{}_{}'.format(USERNAME, 'gym_super_mario'): ['lua/*.lua', 'roms/*.nes' ] },
packages=['super_mario'],
package_data={ 'super_mario': ['lua/*.lua', 'roms/*.nes' ] },
zip_safe=False,
install_requires=[ 'gym>=0.9.7' ],
install_requires=['gym>=0.9.7'],
)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from gym.envs.registration import register
from .package_info import USERNAME
from .nes_env import NesEnv, MetaNesEnv
from .super_mario_bros import SuperMarioBrosEnv, MetaSuperMarioBrosEnv

Expand All @@ -20,8 +19,8 @@
tile_suffix = '-Tiles' if draw_tiles == 1 else ''

register(
id='{}/meta-SuperMarioBros{}-v0'.format(USERNAME, tile_suffix),
entry_point='{}_gym_super_mario:MetaSuperMarioBrosEnv'.format(USERNAME),
id='meta-SuperMarioBros{}-v0'.format(tile_suffix),
entry_point='super_mario:MetaSuperMarioBrosEnv',
max_episode_steps=9999999,
reward_threshold=32000,
kwargs={ 'draw_tiles': draw_tiles, 'average_over': 3, 'passing_grade': 600, 'min_tries_for_avg': 3 },
Expand All @@ -31,8 +30,8 @@
for (world_number, level_number, area_number, max_distance) in SMB_LEVELS:
level = (world_number - 1) * 4 + (level_number - 1)
register(
id='{}/SuperMarioBros-{}-{}{}-v0'.format(USERNAME, world_number, level_number, tile_suffix),
entry_point='{}_gym_super_mario:SuperMarioBrosEnv'.format(USERNAME),
id='SuperMarioBros-{}-{}{}-v0'.format(world_number, level_number, tile_suffix),
entry_point='super_mario:SuperMarioBrosEnv',
max_episode_steps=10000,
reward_threshold=(max_distance - 40),
kwargs={ 'draw_tiles': draw_tiles, 'level': level },
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions super_mario/wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import time
from functools import wraps

_total_time_call_stack = [0]

def _log(message):
print('[BetterTimeTracker] {function_name} {total_time:.3f} {partial_time:.3f}'.format(**message))


def better_time_tracker(log_fun=_log):
def _better_time_tracker(fn):
@wraps(fn)
def wrapped_fn(*args, **kwargs):
global _total_time_call_stack
_total_time_call_stack.append(0)

start_time = time.time()

try:
result = fn(*args, **kwargs)
finally:
elapsed_time = time.time() - start_time
inner_total_time = _total_time_call_stack.pop()
partial_time = elapsed_time - inner_total_time

_total_time_call_stack[-1] += elapsed_time

# log the result
log_fun({
'function_name': fn.__name__,
'total_time': elapsed_time,
'partial_time': partial_time,
})

return result

return wrapped_fn
return _better_time_tracker
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
ignore = D100
max-line-length = 160

0 comments on commit 9d86380

Please sign in to comment.