贪吃蛇游戏的人工智能Snake-AI.zip

上传者: 39840515 | 上传时间: 2021-09-25 23:38:35 | 文件大小: 1.68MB | 文件类型: ZIP
Snake-AI,这是一个用 C/C 语言编写的贪吃蛇游戏的人工智能。AI 的目的是让蛇尽可能的吃更多的食物,直到吃满整个地图。想参与这个项目,请查看todos。Demo使用方法编译与运行:$ make
$ make run为了解详细使用方法, 请查看主函数main()算法介绍函数Snake.decideNext(): 计算蛇S1的下一个移动方向D计算从蛇S1的头部到达食物的最短路径P1。派一条与蛇S1完全一样的虚拟蛇S2沿路径P1吃掉食物。计算从蛇S2的头部到其尾部的最长路径P2。如果路径P2存在,将移动方向D设置为路径P1的第一个方向,否则进行步骤4。计算从蛇S1的头部到达其尾部的最长路径P3。如果P3存在,将移动方向D设置为路径P3的第一个方向,否则进行步骤5。将移动方向D设置为离食物最远的方向。函数Map.findMinPath(): 计算两个位置间的最短路径算法建立在BFS的基础上。为了使路径尽可能直,每次遍历邻接点时,在当前移动方向上的位置会被优先遍历。效果展示:(绿色区域为搜索算法扫描到的区域,红色区域为最后计算出的最短路径,每个位置上的数字表示了从起始位置开始到该位置的最短距离)函数Map.findMaxPath(): 计算两个位置间的最长路径算法建立在DFS与贪心算法的基础上。每次遍历邻接点时,离目标位置最远(使用曼哈顿距离估计)的位置将会被优先遍历到。另外,为了使路径尽可能直,如果两个位置到目标位置的距离相等,在当前移动方向上的位置将被优先遍历到。这个问题是一个NP完全问题,此算法得出的结果路径只是一个近似最长路径。效果展示:(绿色区域为搜索算法扫描到的区域,红色区域为最后计算出的最长路径,每个位置上的数字表示了从该位置开始到目标位置的估计距离)


标签:Snake

文件下载

资源详情

[{"title":"( 59 个子文件 1.68MB ) 贪吃蛇游戏的人工智能Snake-AI.zip","children":[{"title":"snake-master","children":[{"title":".gitattributes <span style='color:#111;'> 47B </span>","children":null,"spread":false},{"title":"run.py <span style='color:#111;'> 967B </span>","children":null,"spread":false},{"title":"requirements.txt <span style='color:#111;'> 34B </span>","children":null,"spread":false},{"title":".travis.yml <span style='color:#111;'> 221B </span>","children":null,"spread":false},{"title":"LICENSE <span style='color:#111;'> 1.05KB </span>","children":null,"spread":false},{"title":"tools","children":[{"title":"print_ckpt.py <span style='color:#111;'> 822B </span>","children":null,"spread":false},{"title":"plot_dqn_compare.py <span style='color:#111;'> 5.61KB </span>","children":null,"spread":false},{"title":"plot_dqn_history.py <span style='color:#111;'> 529B </span>","children":null,"spread":false}],"spread":true},{"title":"README.md <span style='color:#111;'> 2.25KB </span>","children":null,"spread":false},{"title":"docs","children":[{"title":"images","children":[{"title":"demo_shortest.gif <span style='color:#111;'> 376.22KB </span>","children":null,"spread":false},{"title":"demo_longest.gif <span style='color:#111;'> 306.57KB </span>","children":null,"spread":false},{"title":"build_hamilton.png <span style='color:#111;'> 13.12KB </span>","children":null,"spread":false},{"title":"build_longest.png <span style='color:#111;'> 8.99KB </span>","children":null,"spread":false},{"title":"demo_AI_Hamilton.gif <span style='color:#111;'> 622.04KB </span>","children":null,"spread":false},{"title":"dqn_net.png <span style='color:#111;'> 116.53KB </span>","children":null,"spread":false},{"title":"solver_greedy.gif <span style='color:#111;'> 232.68KB </span>","children":null,"spread":false},{"title":"solver_dqn.gif <span style='color:#111;'> 86.24KB </span>","children":null,"spread":false},{"title":"graph_dqn_8_legends.png <span style='color:#111;'> 32.17KB </span>","children":null,"spread":false},{"title":"graph_dqn_4_legends.png <span style='color:#111;'> 151.83KB </span>","children":null,"spread":false},{"title":"demo_AI_search.gif <span style='color:#111;'> 521.39KB </span>","children":null,"spread":false},{"title":"take_shortcuts.png <span style='color:#111;'> 59.31KB </span>","children":null,"spread":false},{"title":"hamilton_cycle.png <span style='color:#111;'> 11.62KB </span>","children":null,"spread":false},{"title":"demo_AI_perfect.gif <span style='color:#111;'> 608.74KB </span>","children":null,"spread":false},{"title":"dqn_compute.png <span style='color:#111;'> 52.63KB </span>","children":null,"spread":false},{"title":"solver_hamilton.gif <span style='color:#111;'> 298.29KB </span>","children":null,"spread":false},{"title":"grid.png <span style='color:#111;'> 747B </span>","children":null,"spread":false}],"spread":false},{"title":"algorithms.md <span style='color:#111;'> 10.71KB </span>","children":null,"spread":false}],"spread":true},{"title":"appveyor.yml <span style='color:#111;'> 341B </span>","children":null,"spread":false},{"title":"tests","children":[{"title":"base","children":[{"title":"test_pos.py <span style='color:#111;'> 1.35KB </span>","children":null,"spread":false},{"title":"test_direc.py <span style='color:#111;'> 369B </span>","children":null,"spread":false},{"title":"test_snake.py <span style='color:#111;'> 7.08KB </span>","children":null,"spread":false},{"title":"test_map.py <span style='color:#111;'> 2.51KB </span>","children":null,"spread":false},{"title":"test_point.py <span style='color:#111;'> 289B </span>","children":null,"spread":false}],"spread":true},{"title":"util","children":[{"title":"test_sumtree.py <span style='color:#111;'> 2.51KB </span>","children":null,"spread":false}],"spread":true},{"title":"gui","children":[{"title":"test_gui.py <span style='color:#111;'> 3.93KB </span>","children":null,"spread":false}],"spread":true},{"title":"solver","children":[{"title":"test_path.py <span style='color:#111;'> 1.73KB </span>","children":null,"spread":false},{"title":"test_hamilton.py <span style='color:#111;'> 693B </span>","children":null,"spread":false}],"spread":false}],"spread":true},{"title":".gitignore <span style='color:#111;'> 115B </span>","children":null,"spread":false},{"title":"snake","children":[{"title":"base","children":[{"title":"__init__.py <span style='color:#111;'> 258B </span>","children":null,"spread":false},{"title":"map.py <span style='color:#111;'> 3.70KB </span>","children":null,"spread":false},{"title":"pos.py <span style='color:#111;'> 2.62KB </span>","children":null,"spread":false},{"title":"point.py <span style='color:#111;'> 677B </span>","children":null,"spread":false},{"title":"snake.py <span style='color:#111;'> 6.40KB </span>","children":null,"spread":false},{"title":"direc.py <span style='color:#111;'> 659B </span>","children":null,"spread":false}],"spread":true},{"title":"__init__.py <span style='color:#111;'> 78B </span>","children":null,"spread":false},{"title":"util","children":[{"title":"sumtree.py <span style='color:#111;'> 1.82KB </span>","children":null,"spread":false},{"title":"__init__.py <span style='color:#111;'> 75B </span>","children":null,"spread":false}],"spread":false},{"title":"gui.py <span style='color:#111;'> 9.70KB </span>","children":null,"spread":false},{"title":"game.py <span style='color:#111;'> 8.25KB </span>","children":null,"spread":false},{"title":"solver","children":[{"title":"path.py <span style='color:#111;'> 5.17KB </span>","children":null,"spread":false},{"title":"base.py <span style='color:#111;'> 625B </span>","children":null,"spread":false},{"title":"dqn","children":[{"title":"history.py <span style='color:#111;'> 6.94KB </span>","children":null,"spread":false},{"title":"__init__.py <span style='color:#111;'> 21.92KB </span>","children":null,"spread":false},{"title":"logger.py <span style='color:#111;'> 260B </span>","children":null,"spread":false},{"title":"snakeaction.py <span style='color:#111;'> 1.09KB </span>","children":null,"spread":false},{"title":"memory.py <span style='color:#111;'> 1.49KB </span>","children":null,"spread":false}],"spread":false},{"title":"__init__.py <span style='color:#111;'> 249B </span>","children":null,"spread":false},{"title":"greedy.py <span style='color:#111;'> 1.47KB </span>","children":null,"spread":false},{"title":"hamilton.py <span style='color:#111;'> 2.90KB </span>","children":null,"spread":false}],"spread":false}],"spread":true}],"spread":false}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明