Skip to content

sudharsan-007/RL-DQN-Snake-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reinforcement Learning Snake Game - DQN

By Sudharsan Ananth

Table of Contents
  1. Introduction
  2. Dependencies
  3. Prerequisites
  4. Run the game
  5. License

Introduction

In this project I have created a DQN agent to train in a snake game environment. The objective of the snake is to collide(eat) all the food that is placed randomly in the environment.

Untrained agent.

untrained snake agent

Trained agent.

trained snake agent

Dependencies

This project is built with the below given major frameworks and libraries. The code is primarily based on python. And the environment is created using Anaconda.

Prerequisites

  1. Python 3.7 (skip if downloading conda)
  2. Conda (Either miniconda or Ananconda)

Run the game

Simply clone the repo cd into the right directory and run agent using the below commands. Step-by-Step instructions given below. Simply change the directory and run agent.py from the directory RL_car_game. You will be able to see the agent training and getting better in minutes.

  1. Clone the repository using

    git clone https://github.com/sudharsan-007/RL-DQN-Snake-Game.git
  2. cd into the directory RL-DQN-Snake-Game

    cd RL-DQN-Snake-Game
  3. Recommended: create a conda environment

    # We require python>=3.7
    conda create -n rl_snake_game python=3.7 numpy matplotlib 
    conda activate rl_snake_game
  4. Install pygame

    pip install pygame
    pip install ipython
    pip install matplotlib
  5. Install pyTorch (CPU verison). Please refer pytorch website to get right version for GPU.

    # https://pytorch.org/get-started/locally/
    conda install pytorch torchvision torchaudio cpuonly -c pytorch
  6. If the above code does not work for you try this(skip this step 5 worked).

    pip3 install torch torchvision torchaudio
  7. Run agent.py from this directory and from inside this environment

    python agent.py
  8. To run the environment without Reinforcement Agent and the agent controllable by WASD keys

    python snake_game.py

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

About

Reinforcement Learning DQL Agent to win every snake game.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages