Git Product home page Git Product logo

pythonsnake's Introduction

pythonSnake

                /^\/^\           ███████╗███╗   ██╗ █████╗ ██╗  ██╗███████╗    ██████╗  ██████╗ ███╗   ██╗        . ~ ------- ~ .
              __|_| O|  \        ██╔════╝████╗  ██║██╔══██╗██║ ██╔╝██╔════╝    ██╔══██╗██╔═══██╗████╗  ██║      .'  .~ _____ ~-. `.
       \/    /~    \_/    \      ███████╗██╔██╗ ██║███████║█████╔╝ █████╗█████╗██║  ██║██║   ██║██╔██╗ ██║    /   /             `.`.
        \____|__________/   _    ╚════██║██║╚██╗██║██╔══██║██╔═██╗ ██╔══╝╚════╝██║  ██║██║▄▄ ██║██║╚██╗██║   /   /                `'
                \_______         ███████║██║ ╚████║██║  ██║██║  ██╗███████╗    ██████╔╝╚██████╔╝██║ ╚████║ /    |
                        \ __     ╚══════╝╚═╝  ╚═══╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝    ╚═════╝  ╚══▀▀═╝ ╚═╝  ╚═══╝

Snake Game with Deep Q-Network (DQN) Agent

Introduction

This project is an implementation of the classic Snake game using a Deep Q-Network (DQN) reinforcement learning agent. The DQN agent learns to play the game by interacting with the environment, making decisions, and updating its Q-values based on rewards.

Table of Contents

How to Play

The Snake game can be played as follows:

  • The snake starts with a length of 5 segments.
  • The goal is to collect fruits (green cells) to increase the snake's length.
  • Avoid running into walls and the snake's own body.
  • The game ends if the snake collides with a wall or itself.

Project Structure

The project consists of the following key components:

  • DQNAgent.py: The DQN agent implementation for training and making decisions.
  • snakeGame.py: The Snake game simulator.
  • archiver.py: A class for archiving game statistics and generating plots.
  • logger.py: A logger class for recording game and agent information.
  • snakeDQN.py: The main script for training the DQN agent and running game episodes.
  • plots/: A directory for storing generated plots.
  • LICENSE: The project's open-source license file.

Getting Started

  1. Clone this repository to your local machine:
git clone https://github.com/JDatPNW/pythonSnake
cd snake-dqn
  1. Ensure you have the required Python libraries installed. You can install them using pip:
pip install numpy tensorflow tqdm colorama matplotlib psutil
  1. Start the Snake game with the DQN agent by running the following command:
python snakeDQN.py
  1. Follow the console log to observe the training process and agent's performance.

Training the DQN Agent

The DQN agent uses reinforcement learning to improve its performance over time. Key training parameters and settings can be customized in snakeDQN.py. These include:

  • The number of training episodes (EPISODES).
  • The replay memory size (REPLAY_MEMORY_SIZE).
  • The target network update frequency (UPDATE_TARGET_EVERY).
  • Epsilon-greedy exploration settings (epsilon, EPSILON_DECAY, MIN_EPSILON).
  • Other training and game parameters.
  • Feel free to modify these parameters to experiment with training dynamics and agent performance.

Visualization and Logging

The project includes utilities for visualizing and logging the game and agent performance:

  • The archiver.py class generates plots to visualize statistics, including average rewards, steps, and fruit counts.
  • The logger.py class logs game and agent information, making it easy to track the agent's behavior during training.

Plots are saved in the plots/ directory, and log information is displayed in the console.

Contributing

Contributions to this project are welcome! You can contribute by reporting issues, proposing enhancements, or submitting pull requests. Please review the project's contribution guidelines for details.

License

This project is open-source and available under the MIT License. You are free to use, modify, and distribute this code as allowed by the license.

Have fun playing Snake and training your DQN agent!

pythonsnake's People

Contributors

jdatpnw avatar

Stargazers

Nurullah Ayvalık avatar

Watchers

 avatar  avatar Nurullah Ayvalık avatar

Forkers

cnu-dns-lab

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.