思路可以参考这个https://blog.youkuaiyun.com/h348592532/article/details/44421753
如果有不对的请联系我(之前那个版本有点问题我改了一下)
寻路时:
紫色'.'表示在closeSet里的节点,红色'#'表示在openSet里的节点
寻路成功时:
下面那行对应键盘上的'QWEADZXC'
测试例子
20
....................
....................
...##############...
................#...
................#...
................#...
................#...
................#...
................#...
s...............#...
................#...
................#...
...##############...
.................e..
....................
....................
....................
....................
....................
....................
#include <iostream>
#include <algorithm>
#include <list>
#include <cstdlib>
#include <ctime>
#include <windows.h>
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<node> openSet;
list<node> closeSet;
char maze[maxn]