From 536aa4a96029e8ec975b642aa98e38cedc00caa2 Mon Sep 17 00:00:00 2001 From: thatguy11325 <148832074+thatguy11325@users.noreply.github.com> Date: Sun, 17 Mar 2024 22:35:27 -0400 Subject: [PATCH] button api --- pokemonred_puffer/environment.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/pokemonred_puffer/environment.py b/pokemonred_puffer/environment.py index 8619a50..9afdaf4 100644 --- a/pokemonred_puffer/environment.py +++ b/pokemonred_puffer/environment.py @@ -112,15 +112,7 @@ WindowEvent.PRESS_BUTTON_START, ] -RELEASE_ACTIONS = [ - WindowEvent.RELEASE_ARROW_DOWN, - WindowEvent.RELEASE_ARROW_LEFT, - WindowEvent.RELEASE_ARROW_RIGHT, - WindowEvent.RELEASE_ARROW_UP, - WindowEvent.RELEASE_BUTTON_A, - WindowEvent.RELEASE_BUTTON_B, - WindowEvent.RELEASE_BUTTON_START, -] +VALID_ACTIONS_STR = ["down", "left", "right", "up", "a", "b", "start"] ACTION_SPACE = spaces.Discrete(len(VALID_ACTIONS)) @@ -515,11 +507,8 @@ def run_action_on_emulator(self, action): self.action_hist[action] += 1 # press button then release after some steps # TODO: Add video saving logic - self.pyboy.send_input(VALID_ACTIONS[action]) - self.pyboy.tick(8, render=False) - if action < len(RELEASE_ACTIONS): - self.pyboy.send_input(RELEASE_ACTIONS[action]) - self.pyboy.tick(self.action_freq - 8, render=True) + self.pyboy.button(VALID_ACTIONS_STR[action], delay=8) + self.pyboy.tick(24, render=True) if self.save_video and self.fast_video: self.add_video_frame()