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

本文介绍了一种基于A*算法的寻路实现方法,并通过具体示例展示了如何使用C++进行编码。该算法适用于游戏开发及机器人路径规划等领域。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本垃圾的博客链接

思路可以参考这个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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值