Skip to content

chenxingxu3/snake-ai-pytorch

 
 

Repository files navigation

Optimizing Game Strategies through Reinforcement Learning: A Case Study of the Snake Game

English日本語 (Japanese)简体中文 (Simplified Chinese)

Overview

This research focuses on the application of reinforcement learning to the development of game strategies, using the classic game of Snake as a case study. The goals of the research include developing AI agents that can effectively play the game, comparing the effectiveness of different reinforcement learning algorithms, and exploring the potential of these techniques in the broader AI domain. Three algorithms, DQN, Double DQN, and Dueling DQN, were used to train the AI agents in a simulated environment, and several performance metrics were set. The research aims to deepen the understanding of the application of reinforcement learning in game strategy development, provide a framework for more complex scenarios, and drive the development of more adaptive AI systems.

Viewing Code Implemented by Different Algorithms

You can view the code for different algorithm implementations by switching branches:

Creating a runtime environment in CONDA

Creating an environment from snake-ai-pytorch.yml file:

conda env create -f snake-ai-pytorch.yml

Activate the new environment: conda activate snake-ai-pytorch

Verify that the new environment was installed correctly:

conda env list

You can also useconda info --envs

For more information, please visit: CONDA User guide > Managing environments

Creating a runtime environment in ANACONDA [recommended]

ANACONDA download at https://www.anaconda.com/download

Start ANACONDA.NAVIGATOR and import snake-ai-pytorch.yml in Environments > Import

Run the game and start the training process

Run agent.py using Python:

python agent.py

Screenshot of the game running:

Results of the training

You can view the training results in the results directory.

Video recording of training process (1,000 episodes)

Referenced code

The design of the Snake game and the implementation of the DQN algorithm references code from the following project:

GitHub - patrickloeber/snake-ai-pytorch

The implementation of Double DQN and Dueling DQN algorithms references code from the following project:

GitHub - p-christ/Deep-Reinforcement-Learning-Algorithms-with-PyTorch: PyTorch implementations of deep reinforcement learning algorithms and environments

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 98.6%
  • Python 1.4%