Skip to content

This repository contains the implementation of a Snake game with an AI agent using the Monte Carlo Tree Search (MCTS) algorithm.

Notifications You must be signed in to change notification settings

SantosProgramming/SnakeAIpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snake Game AI

Overview

This repository contains the implementation of a Snake game with an AI agent using the Monte Carlo Tree Search (MCTS) algorithm. The project is organized into the following files:

  • game.py: Implements the Snake game logic.
  • helper.py: Provides helper functions for visualization during training.
  • model.py: Defines the neural network model for Q-learning and the QTrainer class for training.
  • agent.py: Contains the Agent class responsible for training the AI using Q-learning.

Snake Game AI

Requirements

  • Python 3
  • Pygame
  • Matplotlib
  • Torch

Getting Started

  1. Clone the repository:

    git clone https://github.com/SantosProgramming/SnakeAIpy
    cd SnakeAIpy
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the game:

    python agent.py

How to Play

To train the Snake game AI, execute the agent.py file:

python agent.py

This will start the training process, and you can observe the game's progress through the visualization.

Files

game.py

Contains the implementation of the Snake game, including the game state, game logic, and AI-controlled Snake.

helper.py

Provides a plotting function (plot) for visualizing the training progress during the AI training.

model.py

Defines the neural network model (Linear_QNet) for Q-learning and the QTrainer class for training the model.

agent.py

Contains the Agent class responsible for training the Snake game AI using Q-learning. It includes methods for getting the game state, training the model, and making decisions.

Acknowledgments

The implementation of the Snake game AI is inspired by various online resources and tutorials. Special thanks to the open-source community for providing valuable insights and knowledge.

Feel free to explore, modify, and enhance the code as needed!

About

This repository contains the implementation of a Snake game with an AI agent using the Monte Carlo Tree Search (MCTS) algorithm.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages