Skip to content

Simple AI agent that beats the classic game "Snake".

License

Notifications You must be signed in to change notification settings

Lovi-0/Snake-ai-pytorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snake AI Training Project

logo

Overview

This project implements a reinforcement learning approach to train an AI agent to play the classic Snake game using Deep Q-Learning (DQN).

Features

  • Manual gameplay mode
  • AI training with Deep Q-Network
  • Dynamic speed control
  • Automatic model weight saving and loading
  • Pygame-based visualization

Requirements

  • Python 3.8+
  • Libraries:
    • pygame
    • torch
    • numpy

Project Structure

  • normalGame.py: Manual gameplay mode
  • train.py: AI training script
  • Src/snake_trainer.py: Main training logic
  • Src/snake_enviroment.py: Game environment
  • Src/model/_3.py: DQN model definition

Training Process

  • Uses epsilon-greedy exploration strategy
  • Implements experience replay
  • Periodically updates target network
  • Saves model weights every 100 episodes

How to Run

Manual Gameplay

python normalGame.py

Train AI

python train.py

Training Controls

  • Up/Down Arrow: Adjust training speed
  • Spacebar: Pause/Resume training

Model Saving

  • Weights automatically saved in model_weights/
  • Latest weights loaded at training start

License

MIT License

About

Simple AI agent that beats the classic game "Snake".

Topics

Resources

License

Stars

Watchers

Forks

Languages