Skip to content
JD edited this page Oct 2, 2023 · 4 revisions

Project Wiki - Snake Game with DQN Agent

Table of Contents

  1. Introduction
  2. Getting Started
  3. How to Play
  4. Project Structure
  5. Training the DQN Agent
  6. Visualization and Logging
  7. Contributing
  8. License

1. Introduction

This project implements the classic Snake game with 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. In this wiki, you'll find information on how to get started, play the game, understand the project structure, train the DQN agent, and contribute to the project.

2. Getting Started

Prerequisites

Before you get started, make sure you have the following prerequisites installed on your system:

  • Python 3.x
  • pip (Python package manager)

Installation

To install the required Python libraries, run the following command:

pip install numpy tensorflow tqdm colorama matplotlib psutil

3. 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.

4. 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.

5. Training the DQN Agent

Training Parameters 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:

  • EPISODES: The number of training episodes.
  • REPLAY_MEMORY_SIZE: The size of the replay memory.
  • UPDATE_TARGET_EVERY: The target network update frequency.
  • epsilon: Epsilon-greedy exploration starting value.
  • EPSILON_DECAY: The rate at which epsilon decays.
  • MIN_EPSILON: The minimum value where epsilon decay stops. Other training and game parameters.

Modifying Training

Feel free to modify these parameters to experiment with training dynamics and agent performance. Training episodes allow the agent to learn and improve its performance.

6. 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.

7. 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.

Reporting Issues

If you encounter bugs, issues, or unexpected behavior, please report them on the project's GitHub issues page. Provide detailed information about the problem and any relevant error messages.

Proposing Enhancements

If you have ideas for enhancements or new features, create enhancement proposals in the project's issues section. Discuss your proposals with the community.

Submitting Pull Requests

If you want to contribute code to the project, submit pull requests for review. Ensure that your code follows the project's coding guidelines and style.

8. 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!

Clone this wiki locally