Deep Reinforcement Learning製作遊戲AI初探

參考github案例,通過 Deep Reinforcement Learning(DQN算法)訓練能玩貪喫蛇的AI。
 

環境搭建

基於python + tensorflow + Keras搭建訓練環境
 
1、安裝python 3.6,pip鏡像源爲https://pypi.tuna.tsinghua.edu.cn/simple
2、從pip鏡像源手動安裝以下內容:tensorflow 1.13.2、protobuf 3.19.5、h5py 2.10.0、Keras 2.0.0。手動安裝原因爲github案例爲2018年版本,直接安裝最新py庫存大量報錯。
3、拉取github案例 https://github.com/YuriyGuts/snake-ai-reinforcement 到本地
4、打開案例的requirements.txt文件,刪除tensorflow、protobuf、h5py、keras依賴項。第2步已手動安裝。
5、切換到案例目錄,執行 pip install --upgrade -r requirements.txt
 
現在環境準備好了,接下來就是訓練了。

訓練

打開cmd,切換到案例目錄,輸入py.exe train.py --level "snakeai/levels/10x10-blank.json" --num-episodes 30000
3000的含義是訓練30000個樣本,訓練開始後如下圖
 
默認是CPU計算,i7 9700K級別訓練30000場耗時約8小時
 
訓練完成後得到的dqn-final.model文件爲DQN模型了,接下來我們可以看AI玩的效果
 

試玩

打開cmd切換到案例目錄,輸入py.exe play.py --interface gui --agent dqn --model “dqn-final.model”--level "snakeai/levels/10x10-blank.json" --num-episodes 10 
 
enjoy yourself~
 
參考資料:
1、Introduction to DQN https://zhuanlan.zhihu.com/p/145102068
2、nake-ai-reinforcement https://github.com/YuriyGuts/snake-ai-reinforcement
3、Introduction to Deep Reinforcement Learning https://zhuanlan.zhihu.com/p/25239682
4、Dota 2 with Large Scale Deep Reinforcement Learning
5、Mastering Complex Control in MOBA Games with Deep Reinforcement Learning
6、https://blog.csdn.net/weixin_45590789/article/details/105666453
7、https://cloud.tencent.com/developer/article/1860809
8、 https://zhuanlan.zhihu.com/p/62225540
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章