Skip to content

Commit

Permalink
first go
Browse files Browse the repository at this point in the history
  • Loading branch information
aboundy authored and iron-bound committed Oct 30, 2023
1 parent 9506f14 commit e5e2a06
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
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)

0 comments on commit e5e2a06

Please sign in to comment.