相关疑难解决方法(0)

A星算法

我的A-star实施方面遇到了问题.它确实找到了从我的A点到B点的路径,但是如果地形更"复杂",那么我的Find()函数似乎没有结束.例如,它在这里可以在20 x 20阵列上工作,但是如果你在最右边的障碍物/墙壁的底部添加一个方形('#'),那么它就会失败.

我希望有人可以指出我正在做的任何错误.这是我的代码:

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue> 

using namespace std;

class CNode
{
public:

    CNode() : xPos(0), yPos(0), travelCost(0) {}
    CNode(int x, int y) : xPos(x), yPos(y), travelCost(0) {}
    CNode(int x, int y, int cost) : xPos(x), yPos(y), travelCost(cost) {}

    inline CNode& operator=(const CNode& target)
    {
        if (*this != target)
        {
            xPos = target.xPos;
            yPos = target.yPos;
            travelCost = target.travelCost;
        }

        return *this;
    }

    inline bool operator==(const CNode& target) …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm a-star

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

a-star ×1

algorithm ×1

c++ ×1