Git Product home page Git Product logo

snakeai's Introduction

A Snake game | Snake AI

Overview

This project is part of my learning experience on machine learning and deep learning. The project is comprised of a regular snake game built with pygame. In addition an AI agent added using Deep Q Learning built using Pytorch. I wanted to learn how to use reinforcement learning in combination with a simple game like snake and improve on it to make it more robust in solving the snake game manouvering.

Setup

Python 3.8

I recommend installing Anaconda or venv and setting up a virtual environment before installing the packages

Requirements.txt file contains all the packages. Use pip install -r requirements.txt to install all the packages required for the project.

Running

Running the snakeGame.py file runs the regular Snake game. Use the directional arrow keys to play the game. The game currently terminates if you reach a game over status which is if the snake either hits the boundary of the window or hits itself.

Running the agent.py file starts the training of the QLearning model.

Bugs

The current AI agent is incapable of converging and falls into the trap of predicting the same move on a loop until it hits itself or the boundary. This maybe a problem with insufficient balance in the reward system.

TODO

  • Build more levels with additional boundaries and mazes for the snake to navigate before reaching the food.
  • Improve the AI to reach the food more efficiently.
  • Experiment with other algorithms.

Changelog

27/10/2022

Added a penalty for 100 moves without food and terminated the frame for 200 moves without food

snakeai's People

Contributors

puppetmaster12 avatar

Watchers

 avatar

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.