本文為續篇,前篇為:
再探 遊戲 《 2048 》 —— AI方法—— 緣起、緣滅(1) —— Firefox浏覽器下自動運作遊戲篇
==================================================
《2048》遊戲線上試玩位址:
https://play2048.co/
該遊戲的解法比較不錯的資料為外網的一個讨論文章:
What is the optimal algorithm for the game 2048?
其中,投票率最高的解決方法是啟發式AI算法:

該啟發式AI方法的github代碼位址:
https://github.com/nneonneo/2048-ai
該代碼clone在國内gitee代碼庫上:
https://gitee.com/devilmaycry812839668/highest_vote_2048_ai
==========================================
下載下傳代碼:
從master分支中checkout代碼:
在maser分支中,編譯代碼( ubuntu系統中 ):
./configure
make
-----------------------------------------------------
源代碼中寫明可以通過Firefox浏覽器或者Chrome浏覽器進行遊戲互動,但是實際中我隻成功測試Firefox浏覽器,Chrome浏覽器不知道什麼原因沒搞定,是以介紹下Firefox浏覽器中的設定:
使用Firefox浏覽器進行調試需要設定浏覽器:
浏覽位址框中輸入 about:config
設定選項:
- devtools.debugger.prompt-connection 為 false
- devtools.debugger.remote-enabled 為 true
- devtools.chrome.enabled 為 true
設定好Firefox後需要關閉浏覽器。
通過指令啟動浏覽器:
firefox --start-debugger-server 32000
在浏覽器中輸入網址: https://play2048.co/
(注意,這裡我們必須保證Firefox浏覽器隻打開這一個頁面,測試過程中發現如果有兩個頁面的存在是不能與之互動的)
運作剛才編譯的代碼:
python3 2048.py -b firefox
此時我們可以看到浏覽器中的《2048》在自動運作,證明代碼可以正常運作。