luckymouse0 / snake-rl Goto Github PK
View Code? Open in Web Editor NEWPlaying Snake game with reinforcement learning, using TensorFlow and Pygame.
License: MIT License
Playing Snake game with reinforcement learning, using TensorFlow and Pygame.
License: MIT License
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.