Giter Club home page Giter Club logo

snake-rl's People

Contributors

luckymouse0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

snake-rl's Issues

get_keys_pressed does not get fired

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 ) ...

from pygame.constants import K_DOWN, K_UP, K_LEFT, K_RIGHT
from pygame_player import PyGamePlayer
import random
from Game.Snake import UP, DOWN, LEFT, RIGHT


class SnakePlayer(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 second
        self.last_score = 0.0

    def get_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()
        return SnakePlayer._key_presses_from_action(self._last_action)

    def get_feedback(self):
        # import must be done here because otherwise importing would cause the game to start playing
        from Game.Snake import GAME_SCORE

        # get the difference in score between this and the last run
        score_change = GAME_SCORE - self.last_score
        self.last_score = GAME_SCORE
        return score_change, score_change != 0

    def _choose_next_action(self):
        **return random.choice([UP, DOWN, LEFT, RIGHT])**


if __name__ == "__main__":
    player = SnakePlayer()
    player.start()
    # importing will start the game playing
    import Game.Snake

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.