snake-ai  by linyiLYi

AI agent for playing the game "Snake"

created 2 years ago
1,745 stars

Top 25.1% on sourcepulse

GitHubView on GitHub
Project Summary

This project provides an AI agent capable of playing the classic Snake game, trained using deep reinforcement learning. It offers two agent implementations: a Multi-Layer Perceptron (MLP) and a Convolutional Neural Network (CNN), with the CNN version achieving higher scores. The project is suitable for researchers and developers interested in applying RL to game environments.

How It Works

The AI agents are trained using the Stable-Baselines3 library, a popular framework for deep reinforcement learning. The CNN agent utilizes a convolutional neural network architecture, inspired by the approach in the Nature paper "Human-level control through deep reinforcement learning," to process the game state. The MLP agent uses a simpler feedforward neural network. Both agents learn to play Snake by interacting with the game environment, which is built using the Pygame library and compatible with OpenAI Gym.

Quick Start & Requirements

  • Install: Create a conda environment (conda create -n SnakeAI python=3.8.16), activate it (conda activate SnakeAI), install PyTorch with CUDA support if using GPU (conda install pytorch=2.0.0 torchvision pytorch-cuda=11.8 -c pytorch -c nvidia), and install dependencies (pip install -r requirements.txt).
  • Prerequisites: Python 3.8.16, Anaconda, PyTorch (GPU recommended for training), Pygame, OpenAI Gym, Stable-Baselines3.
  • Running the Game: cd main && python .\snake_game.py
  • Testing Agents: cd main && python test_cnn.py or python test_mlp.py
  • Training: cd main && python train_cnn.py or python train_mlp.py
  • Viewing Curves: cd main && tensorboard --logdir=logs/
  • Docs: README

Highlighted Details

  • Offers both CNN and MLP based RL agents for Snake.
  • Includes scripts for training, testing, and visualizing training progress via Tensorboard.
  • Provides utility scripts for checking GPU status and compressing code for LLM interaction.
  • Trained models for different stages are available in trained_models_cnn/ and trained_models_mlp/.

Maintenance & Community

The project appears to be a personal project with no explicit mention of maintainers, community channels, or a roadmap.

Licensing & Compatibility

The README does not explicitly state a license.

Limitations & Caveats

The project is primarily tested on Windows 11, and compatibility with other operating systems is not guaranteed. The README does not specify the license, which could impact commercial use or integration into closed-source projects.

Health Check
Last commit

1 year ago

Responsiveness

1 week

Pull Requests (30d)
0
Issues (30d)
0
Star History
33 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.