程序员c/c++编程学习基地

用C/C++编写贪吃蛇人工智能游戏

2019-10-31  本文已影响0人  Python编程导师

Snake-AI,这是一个用 C/C++ 语言编写的贪吃蛇游戏的人工智能。

AI 的目的是让蛇尽可能的吃更多的食物,直到吃满整个地图。想参与这个项目,请查看todos。

Demo

image

使用方法

编译与运行:

<pre style="margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: inherit; vertical-align: baseline; word-break: break-word; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">

$ make
$ make run

</pre>

为了解详细使用方法, 请查看主函数main()

算法介绍

  1. 计算从蛇S1的头部到达食物的最短路径P1
  2. 派一条与蛇S1完全一样的虚拟蛇S2沿路径P1吃掉食物。
  3. 计算从蛇S2的头部到其尾部的最长路径P2。如果路径P2存在,将移动方向D设置为路径P1的第一个方向,否则进行步骤4。
  4. 计算从蛇S1的头部到达其尾部的最长路径P3。如果P3存在,将移动方向D设置为路径P3的第一个方向,否则进行步骤5。
  5. 将移动方向D设置为离食物最远的方向。
image image

网友评论:

image

最后,如果你想学C/C++,可以加入qq群:825414254获取素材开发工具和听课权限!

image
上一篇 下一篇

猜你喜欢

热点阅读