Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_B))
elif c == "z":
self.events.append(WindowEvent(WindowEvent.STATE_SAVE))
elif c == "x":
self.events.append(WindowEvent(WindowEvent.STATE_LOAD))
elif c == " ":
self.events.append(WindowEvent(WindowEvent.RELEASE_SPEED_UP))
elif c == chr(8):
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_SELECT))
elif c == chr(13):
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_START))
elif c == "o":
self.events.append(WindowEvent(WindowEvent.SCREENSHOT_RECORD))
else:
if c == "a":
self.events.append(WindowEvent(WindowEvent.PRESS_BUTTON_A))
elif c == "s":
self.events.append(WindowEvent(WindowEvent.PRESS_BUTTON_B))
elif c == chr(27):
self.events.append(WindowEvent(WindowEvent.QUIT))
elif c == " ":
self.events.append(WindowEvent(WindowEvent.PRESS_SPEED_UP))
elif c == "i":
self.events.append(WindowEvent(WindowEvent.SCREEN_RECORDING_TOGGLE))
elif c == chr(8):
self.events.append(WindowEvent(WindowEvent.PRESS_BUTTON_SELECT))
elif c == chr(13):
self.events.append(WindowEvent(WindowEvent.PRESS_BUTTON_START))
def _glkeyboardspecial(self, c, x, y, up):
if up:
if c == GLUT_KEY_UP:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_UP))
if c == GLUT_KEY_DOWN:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_DOWN))
if c == GLUT_KEY_LEFT:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_LEFT))
if c == GLUT_KEY_RIGHT:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_RIGHT))
else:
if c == GLUT_KEY_UP:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_UP))
if c == GLUT_KEY_DOWN:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_DOWN))
if c == GLUT_KEY_LEFT:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_LEFT))
if c == GLUT_KEY_RIGHT:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_RIGHT))
def _glkeyboard(self, c, x, y, up):
if up:
if c == "a":
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_A))
elif c == "s":
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_B))
elif c == "z":
self.events.append(WindowEvent(WindowEvent.STATE_SAVE))
elif c == "x":
self.events.append(WindowEvent(WindowEvent.STATE_LOAD))
elif c == " ":
self.events.append(WindowEvent(WindowEvent.RELEASE_SPEED_UP))
elif c == chr(8):
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_SELECT))
elif c == chr(13):
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_START))
elif c == "o":
self.events.append(WindowEvent(WindowEvent.SCREENSHOT_RECORD))
else:
if c == "a":
self.events.append(WindowEvent(WindowEvent.PRESS_BUTTON_A))
elif c == "s":
self.events.append(WindowEvent(WindowEvent.PRESS_BUTTON_B))
elif c == chr(27):
def _glkeyboard(self, c, x, y, up):
if up:
if c == "a":
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_A))
elif c == "s":
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_B))
elif c == "z":
self.events.append(WindowEvent(WindowEvent.STATE_SAVE))
elif c == "x":
self.events.append(WindowEvent(WindowEvent.STATE_LOAD))
elif c == " ":
self.events.append(WindowEvent(WindowEvent.RELEASE_SPEED_UP))
elif c == chr(8):
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_SELECT))
elif c == chr(13):
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_START))
elif c == "o":
self.events.append(WindowEvent(WindowEvent.SCREENSHOT_RECORD))
else:
if c == "a":
self.events.append(WindowEvent(WindowEvent.PRESS_BUTTON_A))
elif c == "s":
self.events.append(WindowEvent(WindowEvent.PRESS_BUTTON_B))
elif c == chr(27):
self.events.append(WindowEvent(WindowEvent.QUIT))
elif c == " ":
self.events.append(WindowEvent(WindowEvent.PRESS_SPEED_UP))
elif c == "i":
if up:
if c == GLUT_KEY_UP:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_UP))
if c == GLUT_KEY_DOWN:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_DOWN))
if c == GLUT_KEY_LEFT:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_LEFT))
if c == GLUT_KEY_RIGHT:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_RIGHT))
else:
if c == GLUT_KEY_UP:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_UP))
if c == GLUT_KEY_DOWN:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_DOWN))
if c == GLUT_KEY_LEFT:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_LEFT))
if c == GLUT_KEY_RIGHT:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_RIGHT))
def _glkeyboardspecial(self, c, x, y, up):
if up:
if c == GLUT_KEY_UP:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_UP))
if c == GLUT_KEY_DOWN:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_DOWN))
if c == GLUT_KEY_LEFT:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_LEFT))
if c == GLUT_KEY_RIGHT:
self.events.append(WindowEvent(WindowEvent.RELEASE_ARROW_RIGHT))
else:
if c == GLUT_KEY_UP:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_UP))
if c == GLUT_KEY_DOWN:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_DOWN))
if c == GLUT_KEY_LEFT:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_LEFT))
if c == GLUT_KEY_RIGHT:
self.events.append(WindowEvent(WindowEvent.PRESS_ARROW_RIGHT))
def _glkeyboard(self, c, x, y, up):
if up:
if c == "a":
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_A))
elif c == "s":
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_B))
elif c == "z":
self.events.append(WindowEvent(WindowEvent.STATE_SAVE))
elif c == "x":
self.events.append(WindowEvent(WindowEvent.STATE_LOAD))
elif c == " ":
self.events.append(WindowEvent(WindowEvent.RELEASE_SPEED_UP))
elif c == chr(8):
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_SELECT))
elif c == chr(13):
self.events.append(WindowEvent(WindowEvent.RELEASE_BUTTON_START))
elif c == "o":
self.events.append(WindowEvent(WindowEvent.SCREENSHOT_RECORD))
else:
if c == "a":
def __init__(self, pyboy, observation_type="tiles", action_type="toggle", simultaneous_actions=False, **kwargs):
# Build pyboy game
self.pyboy = pyboy
if str(type(pyboy)) != "":
raise TypeError("pyboy must be a Pyboy object")
# Build game_wrapper
self.game_wrapper = pyboy.game_wrapper()
if self.game_wrapper is None:
raise ValueError(
"You need to build a game_wrapper to use this function. Otherwise there is no way to build a reward function automaticaly."
)
self.last_fitness = self.game_wrapper.fitness
# Building the action_space
self._DO_NOTHING = WindowEvent.PASS
self._buttons = [
WindowEvent.PRESS_ARROW_UP, WindowEvent.PRESS_ARROW_DOWN, WindowEvent.PRESS_ARROW_RIGHT,
WindowEvent.PRESS_ARROW_LEFT, WindowEvent.PRESS_BUTTON_A, WindowEvent.PRESS_BUTTON_B,
WindowEvent.PRESS_BUTTON_SELECT, WindowEvent.PRESS_BUTTON_START
]
self._button_is_pressed = {button: False for button in self._buttons}
self._buttons_release = [
WindowEvent.RELEASE_ARROW_UP, WindowEvent.RELEASE_ARROW_DOWN, WindowEvent.RELEASE_ARROW_RIGHT,
WindowEvent.RELEASE_ARROW_LEFT, WindowEvent.RELEASE_BUTTON_A, WindowEvent.RELEASE_BUTTON_B,
WindowEvent.RELEASE_BUTTON_SELECT, WindowEvent.RELEASE_BUTTON_START
]
self._release_button = {button: r_button for button, r_button in zip(self._buttons, self._buttons_release)}
self.actions = [self._DO_NOTHING] + self._buttons
if action_type == "all":