← 开源
maurock

snake-ga

AI Agent that learns how to play Snake with Deep Q-Learning

TutorialsML/AI fundamentalsPython
在 GitHub 打开
增长势头
+024 小时新增 Star0.0%
539
Star
961
Fork
+1
本周
2
贡献者
创建于 2018-09-16 · 更新于 2026-10-09 · 今日第 17448 名
主要开发者
maurockamelkikh

maurock/snake-ga 排名第 17,448,有 539 个星标。

同类别比较

maurock/snake-ga 排名第 17,448,此处有 8 个同类条目;falloutdurham/beginners-pytorch-deep-learning 排名第 17,458。

同类别比较
名称排名指标
google-gemini/gemini-image-editing-nextjs-quickstart17,409
语言:
TypeScript
星标数:
541
分叉数:
113
简介:
Get started with native image generation and editing using Gemini 2.0 and Next.js
theainerd/MLInterview17,415
星标数:
541
分叉数:
177
简介:
:octocat: A curated awesome list of AI Startups in India & Machine Learning Interview Guide. Feel free to contribute!
blueberrymusic/Deep-Learning-A-Visual-Approach17,424
语言:
Jupyter Notebook
星标数:
540
分叉数:
164
简介:
All of the figures and notebooks for my deep learning book, for free!
mpaepper/content-chatbot17,430
语言:
Python
星标数:
540
分叉数:
52
简介:
Build a chatbot or Q&A bot of your website's content
falloutdurham/beginners-pytorch-deep-learning17,458
语言:
Jupyter Notebook
星标数:
538
分叉数:
282
简介:
Repository for scripts and notebooks from the book: Programming PyTorch for Deep Learning
gy910210/rnn-from-scratch17,474
语言:
Python
星标数:
537
分叉数:
152
简介:
Implementing Recurrent Neural Network from Scratch
jonbruner/generative-adversarial-networks17,478
语言:
Jupyter Notebook
星标数:
537
分叉数:
247
简介:
Introduction to generative adversarial networks, with code to accompany the O'Reilly tutorial on GANs
kuleshov/cornell-cs5785-2025-applied-ml17,482
语言:
Jupyter Notebook
星标数:
537
分叉数:
186
简介:
Lecture materials for Cornell CS5785 Applied Machine Learning (Fall 2024)
关键参数与规格
关键参数与规格
参数值
语言Python
类别Tutorials
子类别ML/AI fundamentals
关键词Gaming, RL
星标数539
分叉数961
贡献者2
创建日期2018-09-16
更新日期2026-10-09
1 天星标数0
7 天星标数1
排名17,448
上次排名17,235
排名变化-213
7 天星标排名11,433
上次 7 天星标排名11,494
7 天星标排名变化61
总星标排名18,266
上次总星标排名18,242
总星标排名变化-24
国家UK
README 摘录

Deep Reinforcement Learning Project: Train AI to play Snake *UPDATE:* This project has been recently updated and improved: It is now possible to optimize the Deep RL approach using Bayesian Optimization. The code of Deep Reinforcement Learning was ported from Keras/TF to Pytorch. To see the old version of the code in Keras/TF, please refer to this repository: snake-ga-tf. Introduction The goal of this project is to develop an AI Bot able to learn how to

play the popular game Snake from scratch. In order to do it, I implemented a Deep Reinforcement Learning algorithm. This approach consists in giving the system parameters related to its state, and a positive or negative reward based on its actions. No rules about the game are given, and initially the Bot has no information on what it needs to do. The goal for the system is to figure it out and elaborate a strategy to maximize the score - or

the reward. \ We are going to see how a Deep Q-Learning algorithm learns how to play Snake, scoring up to 50 points and showing a solid strategy after only 5 minutes of training. \ Additionally, it is possible to run the Bayesian Optimization method to find the optimal parameters of the Deep neural network, as well as some parameters of the Deep RL approach. 6 with the pygame library installed, as well as Pytorch. If you encounter any error with

, you might need to install Visual C++ 2015-2019 (or simply downgrade your pytorch version, it should be fine). To train the agent, set in the file snakeClass. py: The parameters of the Deep neural network can be changed in *snakeClass. py* by modifying the dictionary in the function If you run snakeClass. py from the command line, you can set the arguments and . This way, the game display is not shown and the training phase is faster. Optimize Deep

RL with Bayesian Optimization To optimize the Deep neural network and additional parameters, run: This method uses Bayesian optimization to optimize some parameters of Deep RL. The parameters and the features' search space can be modified in *bayesOpt. For Mac users It seems there is a OSX specific problem, since many users cannot see the game running. To fix this problem, in update_screen(), add this line.

常见问题

记录了多少星标和分叉?

maurock/snake-ga 有 539 个星标和 961 个分叉。

仓库排名是多少?

maurock/snake-ga 排名第 17,448。

记录的语言和类别是什么?

maurock/snake-ga 有 539 个星标,语言为 Python,类别为 Tutorials。

哪个仓库排名最接近?

maurock/snake-ga 与 falloutdurham/beginners-pytorch-deep-learning 比较,后者排名第 17,458,有 538 个星标。

README

Deep Reinforcement Learning

Project: Train AI to play Snake

UPDATE:

This project has been recently updated and improved:

  • It is now possible to optimize the Deep RL approach using Bayesian Optimization.
  • The code of Deep Reinforcement Learning was ported from Keras/TF to Pytorch. To see the old version of the code in Keras/TF, please refer to this repository: snake-ga-tf.

Introduction

The goal of this project is to develop an AI Bot able to learn how to play the popular game Snake from scratch. In order to do it, I implemented a Deep Reinforcement Learning algorithm. This approach consists in giving the system parameters related to its state, and a positive or negative reward based on its actions. No rules about the game are given, and initially the Bot has no information on what it needs to do. The goal for the system is to figure it out and elaborate a strategy to maximize the score - or the reward.
We are going to see how a Deep Q-Learning algorithm learns how to play Snake, scoring up to 50 points and showing a solid strategy after only 5 minutes of training.
Additionally, it is possible to run the Bayesian Optimization method to find the optimal parameters of the Deep neural network, as well as some parameters of the Deep RL approach.

Install

This project requires Python 3.6 with the pygame library installed, as well as Pytorch. If you encounter any error with torch=1.7.1, you might need to install Visual C++ 2015-2019 (or simply downgrade your pytorch version, it should be fine).
The full list of requirements is in requirements.txt.

git clone git@github.com:maurock/snake-ga.git

Run

To run and show the game, executes in the snake-ga folder:

python snakeClass.py

Arguments description:

  • --display - Type bool, default True, display or not game view
  • --speed - Type integer, default 50, game speed

The default configuration loads the file weights/weights.h5 and runs a test.

To train the agent, set in the file snakeClass.py:

  • params['train'] = True The parameters of the Deep neural network can be changed in snakeClass.py by modifying the dictionary params in the function define_parameters()

If you run snakeClass.py from the command line, you can set the arguments --display=False and --speed=0. This way, the game display is not shown and the training phase is faster.

Optimize Deep RL with Bayesian Optimization

To optimize the Deep neural network and additional parameters, run:

python snakeClass.py --bayesianopt=True

This method uses Bayesian optimization to optimize some parameters of Deep RL. The parameters and the features' search space can be modified in bayesOpt.py by editing the optim_params dictionary in optimize_RL.

For Mac users

It seems there is a OSX specific problem, since many users cannot see the game running. To fix this problem, in update_screen(), add this line.

def update_screen():
    pygame.display.update()   

    pygame.event.get() # <--- Add this line ###
排名相邻
同类项目