Git Product home page Git Product logo

ai-snake-game's Introduction

AI Playing Snake Game

繁體中文 | English | 日本語

Using the PPO algorithm combined with the CNN architecture, we achieve AI agent control of the Snake game.

The basic structure of the game is located in game.py, and wapper.py is used to package the environment for model operation.
The code for training and testing the model is located in train.py and test.py.
The final trained model is in the model/ folder, while models during training are in the cnn_log/log/ folder.
cnn_log/logs/PPO_0/ contains tensorboard logs of the training process.

Results

On a $12×12$ board:

  • After 50 million steps: the average length of the snake reaches 74
  • After 100 million steps: the average length of the snake reaches 98

File Structure

│
├─model
├─cnn_log
│  ├──log
│  └──logs/PPO_0
│ game.py
│ test.py
│ train.py
│ wrapper.py
│ snake.yml
│

Environment Setup

Developed using Python in an Anaconda environment.

conda create --name Snake python=3.10.14
conda activate Snake
conda install pytorch=2.2.2 torchvision pytorch-cuda -c pytorch -c nvidia
conda install tensorflow
pip install pygame==2.5.2 gym==0.26.2 gymnasium==0.29.1 stable-baselines3==2.3.2 tensorboard==2.9.1

or use the packaged environment snake.yml

conda env create --file snake.yml --name Snake

Acknowledgements

Inspired by this Video.
Thanks for the explanation and analysis of many knowledge points.

ai-snake-game's People

Contributors

part-time-ray 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.