首页 > 其他分享 >再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)

时间:2022-11-16 23:31:43浏览次数:120  
标签:浏览器 游戏 缘灭 AI 代码 2048 https Firefox

本文为续篇,前篇为:

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇

 

 

 

==================================================

 

 

《2048》游戏在线试玩地址:

​https://play2048.co/​

 

 

该游戏的解法比较不错的资料为外网的一个讨论帖子:

 

What is the optimal algorithm for the game 2048?

 

 

 

 

 

其中,投票率最高的解决方法是启发式AI算法:

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)_git

 

 

 

该启发式AI方法的github代码地址:

​https://github.com/nneonneo/2048-ai​

 

 

 

该代码clone在国内gitee代码库上:

​https://gitee.com/devilmaycry812839668/highest_vote_2048_ai​

 

 

 

==========================================

 

 

下载代码:

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)_firefox_02

 

 

 

 

 

从master分支中checkout代码:

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)_杂谈_03

 

 

 

 

 

在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

 

 

 

 

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)_firefox_04

 

 

 

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)_git_05

 

 

 

 

 

设置好Firefox后需要关闭浏览器。  

 

 

 

 

通过命令启动浏览器:

firefox --start-debugger-server 32000

 

 

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)_git_06

 

 

 

 

 

 

在浏览器中输入网址:     ​​https://play2048.co/​

(注意,这里我们必须保证Firefox浏览器只打开这一个页面,测试过程中发现如果有两个页面的存在是不能与之交互的)

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)_杂谈_07

 

 

 

 

 

 

运行刚才编译的代码:

python3 2048.py -b firefox

 

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)_github_08

 

 

 

 

 

此时我们可以看到浏览器中的《2048》在自动运行,证明代码可以正常运行。

再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(1) —— Firefox浏览器下自动运行游戏篇 (续)_github_09

 

 

 

 

=========================================================

 

标签:浏览器,游戏,缘灭,AI,代码,2048,https,Firefox
From: https://blog.51cto.com/u_15642578/5857899

相关文章