GithubHelp home page GithubHelp logo

snake-ai-pytorch's Introduction

Teach AI To Play Snake! Reinforcement Learning With PyTorch and Pygame

In this Python Reinforcement Learning Tutorial series we teach an AI to play Snake! We build everything from scratch using Pygame and PyTorch. The tutorial consists of 4 parts:

You can find all tutorials on my channel: Playlist

  • Part 1: I'll show you the project and teach you some basics about Reinforcement Learning and Deep Q Learning.
  • Part 2: Learn how to setup the environment and implement the Snake game.
  • Part 3: Implement the agent that controls the game.
  • Part 4: Implement the neural network to predict the moves and train it.

snake-ai-pytorch's People

Contributors

michaelseguin avatar patrickloeber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snake-ai-pytorch's Issues

training is slow, why?

Game 484 Score 11 Record: 69

after so many failures, only got a record 69, any way to improve it? or is it possible to achieve better?

Fail to allocate bitmap

when running the agent everything works as expected, however once the games/iterations start reaching higher numbers (around 100-300 commonly around 200) the program closes itself and i get a "Fail to allocate bitmap" in the visual studio code debugger. is there a solution to fix this or continue the program in the event of this failure? thank you

Model isn't loaded from file

Love what you've done with the python snake stuff, but i've noticed if you run the ai again, it doesn't use what it's already learnt and start from there again. Is there an easy way to get this implemented? I'm not great at python but i'd be happy to give it a go if i'm pointed in the right direction?

Error when snake dies

Hello, everytime my snake dies the following error message shows up and my programm crashes:

grafik

Threading issue

Fatal Python error: PyEval_RestoreThread: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: initialized

Current thread 0x00001324 (most recent call first):
File "d:\snake-ai-pytorch\game.py", line 67 in play_step
File "d:\snake-ai-pytorch\agent.py", line 118 in train
File "d:\snake-ai-pytorch\agent.py", line 147 in

Games Crash

Game 15 Score 0 Record: 1
Figure(1280x960)
zsh: trace trap "/Users/onurcirag/Downloads/Programming BIT/Sneak AI/SneakAI/bin/python"
(SneakAI)

Everything works well but after game 10-20 the game does Crash and the only error code is zsh: trace trap does anyone know how I could fix it?

License

hey! is this code MIT licensed? I would love to use it

How to fix AI snake deadend trap?

Hi, im trying to solve that snake deadend trap, but I couldn't figure it out, here is my fork with some fixes and enhancements https://github.com/PayteR/snake-ai-pytorch

I created the is_collision_predict function inspired by is_collision. There I added detection if when snake turns into some direction and his body is there then it returns True https://github.com/PayteR/snake-ai-pytorch/blob/ab13675964f179179d77987c8a6e386d92a6b60b/game.py#L117 Code is ugly little bit but is believe it's correct.

Now i had worse results than without it, how is that? I didn't added any new param, I just notice algorithm that there is danger if turns to the deadend. Thx for suggestions.

cpu to gpu

It has been implemented with cpu, I want to implement this project with gpu, how should I do it, please advise

Calculate Accuracy

I was wondering how to check the accuracy of the model? Please note that this is not necessarily an issue.

Model crashing after running for a little bit

Hi. I tried to write this code for myself, but every time the program is run, it runs for 7-9 iterations, and then python crashes, showing the following error:

Screenshot 2024-05-14 at 7 00 49 PM

Screenshot 2024-05-14 at 7 00 49 PM

This error persists, even after i cloned the repository and ran it in the virtual env. All required packages are installed, and everything runs perfectly as expected right up to the moment before error. Does anyone have any idea on how to fix this? This is run on MacOS 14, and VSCode

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.