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

pygame.error: posted event keycode must be int #70

Open
SamWqc opened this issue Dec 15, 2020 · 0 comments
Open

pygame.error: posted event keycode must be int #70

SamWqc opened this issue Dec 15, 2020 · 0 comments

Comments

@SamWqc
Copy link

SamWqc commented Dec 15, 2020

MacBook Air --MAC OS 10.14.6
Python3.73 64bit
Wrappered the environment:
`#Code based on https://github.com/KibaAmor/rl-code/blob/master/demos/dqn_flappybird/flappybird_wrapper.py
import numpy as np
from gym import Env, spaces
from ple import PLE
from ple.games import FlappyBird

class FlappyBirdWrapper(Env):
def init(self, **kwargs):
self.game = FlappyBird()
self.p = PLE(self.game, **kwargs)
self.action_set = self.p.getActionSet()

    # 
    self.observation_space = spaces.Discrete(3)
    # 
    self.action_space = spaces.Discrete(2)

def _get_obs(self):
    # 
    state = self.game.getGameState()
    # 
    dist_to_pipe_horz = state["next_pipe_dist_to_player"]
    dist_to_pipe_bottom = state["player_y"] - state["next_pipe_top_y"]

    velocity = state['player_vel']
    return np.array([dist_to_pipe_horz, dist_to_pipe_bottom, velocity])

def reset(self):
    self.p.reset_game()
    return self._get_obs()

def step(self, action):
    reward = self.p.act(self.action_set[action])
    obs = self._get_obs()
    done = self.p.game_over()
    return obs, reward, done, dict()

def seed(self, *args, **kwargs):
    pass

def render(self, *args, **kwargs):
    pass`

Error happened when running:
File "/Users/Sam/Desktop/MSACoures/WorkShop/RL_FlappyBird/Test.py", line 31, in <module> watch() File "/Users/Sam/Desktop/MSACoures/WorkShop/RL_FlappyBird/Test.py", line 19, in watch next_state, reward, done, _ = env.step(action) File "/Users/Sam/Desktop/MSACoures/WorkShop/RL_FlappyBird/Env.py", line 34, in step reward = self.p.act(self.action_set[action]) File "/Users/Sam/PyGame-Learning-Environment/ple/ple.py", line 376, in act return sum(self._oneStepAct(action) for i in range(self.frame_skip)) File "/Users/Sam/PyGame-Learning-Environment/ple/ple.py", line 376, in <genexpr> return sum(self._oneStepAct(action) for i in range(self.frame_skip)) File "/Users/Sam/PyGame-Learning-Environment/ple/ple.py", line 395, in _oneStepAct self._setAction(action) File "/Users/Sam/PyGame-Learning-Environment/ple/ple.py", line 411, in _setAction self.game._setAction(action, self.last_action) File "/Users/Sam/PyGame-Learning-Environment/ple/games/base/pygamewrapper.py", line 79, in _setAction pygame.event.post(ku) pygame.error: posted event keycode must be int

And I found the last action may be '[]', error happens here
if last_action is None: last_action = self.NOOP

if last_action is None or last_action==[]:` fixed the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant