Git Product home page Git Product logo

ai_plays_snake's Introduction

AI plays snake game

Neural Network Trained using Genetic Algorithm which acts as the brain for the snake.

The snake looks in the 8 direction for food, body part and the boundary which acts as the 24 input for the Neural Network.

Getting Started

Prerequisites

To install the dependencies, run on terminal :

python3 -m pip -r requirements.txt

Project Structure

├── Arena.py            # class that helps in setting the boundary and parameters of the arena
├── brain.py            # class that deals with the neural network
├── colors.py           # consists of colors used in the whole project
├── game.py             # lets the saved snakes to run in 
├── samples
│   ├── generation23.gif    
│   └── generation6.gif
├── input.py            # parametes to apply genetic algorithm on your own
├── README.md
├── requirements.txt    # python dependencies required
├── saved
│   └── top_snakes.pickle   # saved list of objects of snake class for each generation
└── snake.py            # class snake that handles all properties of snake

Testing

To test the Genetic Algorithm, alter the parameters inside the input.py, then run the following command specifying the path to save the optimised result as a pickle file (a list is stored, containing the best snake from each generation):

python3 Genetic_algo.py --output saved/test.pickle 

Playing

To run the snakes saved previously, run the following commands specifying the path to the saved file :

python3 game.py --input saved/test.pickle

Acknowledgement

ai_plays_snake's People

Contributors

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