A*寻路算法(8个方向)带debug

您所在的位置:网站首页 alienworm这个游戏怎么玩 A*寻路算法(8个方向)带debug

A*寻路算法(8个方向)带debug

2023-10-05 06:24| 来源: 网络整理| 查看: 265

本垃圾的博客链接

思路可以参考这个https://blog.csdn.net/h348592532/article/details/44421753

如果有不对的请联系我(之前那个版本有点问题我改了一下)

寻路时:

紫色'.'表示在closeSet里的节点,红色'#'表示在openSet里的节点

寻路成功时:

下面那行对应键盘上的'QWEADZXC'

测试例子 20  .................... .................... ...##############... ................#... ................#... ................#... ................#... ................#... ................#... s...............#... ................#... ................#... ...##############... .................e.. .................... .................... .................... .................... .................... ....................

#include #include #include #include #include #include using namespace std; const int maxn = 100; struct node{ int x, y; int f, g, h; char dir; node(){ f = 0; g = 0; h = 0; } }; int dirx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; // 8个方向 int diry[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int n, m; string ans; class aStart{ public: list openSet; list closeSet; char maze[maxn][maxn]; node map[maxn][maxn], road[maxn][maxn], start, fin; void initMap(); void drawMap(); void debug(); int getH(node a, node b); int getG(int i); void getDir(int i, node nei); bool isInclude(list arr, node qur); void dfs(int x, int y); void aStartSearch(); }; void color(int x) // 给文字上色 { if(x >= 0 && x > n; m = n; for(int i = 0; i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3