Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up seed and add test #53

Open
wants to merge 1 commit into
base: 0.5-cleanup
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ __pycache__/

# C extensions
*.so
*.c

# Distribution / packaging
.Python
Expand Down
12 changes: 7 additions & 5 deletions pufferlib/environments/pokemon_red_updated.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

import sys
import uuid
import os
from math import floor, sqrt
import uuid
from math import floor
import json
from pathlib import Path

Expand Down Expand Up @@ -38,7 +37,7 @@ def __init__(
extra_buttons=False,
explore_weight=3 # 2.5
):
self.s_path = Path(f'session_{str(uuid.uuid4())[:8]}')
self.s_path = Path(f'runs/session_{str(uuid.uuid4())[:8]}')
self.gb_path=str(Path(__file__).parent / 'pokemon_red.gb')
self.init_state=str(Path(__file__).parent / 'has_pokedex_nballs.state')

Expand All @@ -63,7 +62,7 @@ def __init__(
self.extra_buttons = extra_buttons
self.instance_id = str(uuid.uuid4())[:8]

self.s_path.mkdir(exist_ok=True)
self.s_path.mkdir(parents=True, exist_ok=True)
self.reset_count = 0
self.all_runs = []

Expand Down Expand Up @@ -133,7 +132,10 @@ def __init__(
self.reset()

def reset(self, seed=None):
# Gym v26 favours `Env.reset(seed=seed)` this allows seeding to only be changed on environment reset.
# https://gymnasium.farama.org/content/migration-guide/#seed-and-random-number-generator
self.seed = seed

# restart game, skipping credits
self.initial_state.seek(0)
self.pyboy.load_state(self.initial_state)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_pokemon_red_step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pdb import set_trace as T
import numpy as np
from pufferlib.environments import PokemonRed

env = PokemonRed()
r_ob, r_info = env.reset()
isinstance(r_ob, np.ndarray)
isinstance(r_info, dict)

for i in range(100):
action = env.action_space.sample()
ob, reward, terminal, truncated, info = env.step(action)
print(f'Step: {i}, Info: {info}')

# check datatype output
isinstance(ob, np.ndarray)
isinstance(reward, float)
isinstance(terminal, bool)
isinstance(truncated, bool)