Skip to content

AnishMulay/Snake-Ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Snake Playing AI

an artificial intelligence agent which learns to play the game snake with deep Q learning


Table of Contents


Description

Snake is a video game idea in which the player controls a line that increases in length, with the line itself serving as a key barrier. This type of game environment, where the rewards to the player are well defined beforehand is perfect for training an agent with the help of reinforcement learning. This project provides the basic code for an agent which starts off with a random strategy and slowly becomes better by playing many games.

Requirements

  • python
  • pygame
  • pytorch package
  • Ipython package
  • matplotlib

How To Use

Installing the necessary packages

Pytorch

   pip install torch torchvision

Pygame

   pip install pygame

Ipython

   pip install ipython

Matplotlib

   pip install matplotlib

This project was created on Scrapy python 3.9.5, but any subsequent versions will also work.

Running the project

To train the agent you just need to navigate to the project folder where the file agent.py is located and then simply run the file on the terminal

   python agent.py

Two displays will open up on running this file. One is the environment where the game is played in real time and you can watch as the agent learns to play the game. The other display shows us how the agent is improving over time with statistics like the highest score, most recent score and the average score of all the games played upto that point.

Modifying the agent

If you want to experiment with the behaviour of the agent, you can open the agent.py file in any editor and you will find some variables listed whose values, if changed will have an impact on the performance of the agent. This can be used to eventually find the optimum values for these parameteres.


Author Info

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published