You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you for your wonderful tutorial
For some reason, the function "get_keys_pressed" never gets fired..
Before I start programming the ML, I want the play randomly (Up down, left,right ) ...
frompygame.constantsimportK_DOWN, K_UP, K_LEFT, K_RIGHTfrompygame_playerimportPyGamePlayerimportrandomfromGame.SnakeimportUP, DOWN, LEFT, RIGHTclassSnakePlayer(PyGamePlayer):
def__init__(self):
""" Example class for playing Pong """super(SnakePlayer, self).__init__(
force_game_fps=10
) # we want to run at 10 frames per secondself.last_score=0.0defget_keys_pressed(self, screen_array, feedback):
# The code for running the actual learning agent would go here with the screen_array and feeback as the inputs# and an output for each key in the game, activating them if they are over some threshold.self._last_action=self._choose_next_action()
returnSnakePlayer._key_presses_from_action(self._last_action)
defget_feedback(self):
# import must be done here because otherwise importing would cause the game to start playingfromGame.SnakeimportGAME_SCORE# get the difference in score between this and the last runscore_change=GAME_SCORE-self.last_scoreself.last_score=GAME_SCOREreturnscore_change, score_change!=0def_choose_next_action(self):
**returnrandom.choice([UP, DOWN, LEFT, RIGHT])**if__name__=="__main__":
player=SnakePlayer()
player.start()
# importing will start the game playingimportGame.Snake
The text was updated successfully, but these errors were encountered:
@joseph-vedadi The exploration part is already done, you don't need to do it manually. Without the full code can't see why it isn't working... try to isolate where is the problem using breakpoints or prints.
Thank you for your wonderful tutorial
For some reason, the function "get_keys_pressed" never gets fired..
Before I start programming the ML, I want the play randomly (Up down, left,right ) ...
The text was updated successfully, but these errors were encountered: