Skip to content

DmFors/ml-rl-snake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snake Game: training using Q-learning (Reinforcement Learning Algorithm)

This repository contains a Snake Game implemented using Python and PyTorch, showcasing reinforcement learning techniques. The goal of this project is to train an AI agent to play the classic Snake game using Q-learning.

YouTube link

ml-rl-snake.mp4

Prerequisites

Before you begin, ensure you have met the following requirements:

  • python 3.x
  • pygame
  • pytorch (>=1.0.0)
  • numpy
  • matplotlib (for plotting results)

Installation

Clone the repository to your local machine:

git clone https://github.com/dmfors/ml-rl-snake.git
cd ml-rl-snake

Install the required dependencies:

pip install pygame torch numpy matplotlib

Project Structure

The project consists of the following files:

  • game.py: Implements the Snake Game logic
  • model.py: Contains the Q-learning neural network model (Linear_Qnet class) and the Q-learning trainer (QTrainer class)
  • agent.py: The main entry point for training the AI agent
  • helper.py: Provides a utility function for plotting a training statistics

Usage

To train the AI agent to play the Snake Game, run the following command:

python agent.py

The training process will start, and you can monitor the agent's progress on the gameplay on the left and the learning graph on the right.

Results

During training, the project will record the agent's score and plot it using Matplotlib. You can visualize how the agent's efficiency improves over time.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages