我一直停留在这个棘手的错误,在过去几个小时,我在想,如果这里有人可以帮助我。整数递归A的每个循环中被重置*算法
基本上我实现通过递归A *,我想每个节点(称为代码中的一个瓦片)来存储它已经通过先前的节点的数目的一个整数值。这是这样的,一旦算法找到了出口,它可以返回并返回最短路线。
然而转弯计数器正在每次遍历函数时间复位。但是,如果我删除行:
map[y][x].setID(path);
它细支起来,当然生成一个堆栈溢出错误,但我真的不能明白为什么这会导致问题。
代码的主比特是在这里:
private static Tile[][] findSquares(IntVector v, Tile[][] map, int wall, int empty, int end, int start, int path, int turns)
{
// System.out.println(turns);
if (!isHit)
{
for (int y = v.y - 1; y <= v.y + 1; y++)
{
for (int x = v.x - 1; x <= v.x + 1; x++)
{
if (map[y][x].id == end)
{
isHit = true;
}
else if (map[y][x].id != wall && map[y][x].id != path && map[y][x].id != end && !isHit && map[y][x].id != start)
{
map[y][x].turns++;
System.out.println(map[y][x].turns); //Always Results in 1
map[y][x].setID(path);
findSquares(new IntVector(x, y), map, wall, empty, end, start, path, turns);
break;
}
}
}
}
return map;
}
与表示节点瓦片。这里是瓷砖类:
static private class Tile
{
int id;
int turns = 0;
Tile(int id)
{
this.id = id;
}
public void addTurn()
{
turns++;
}
public void setID(int id)
{
this.id = id;
}
public int getTurns()
{
return turns;
}
public Tile setTurns(int turns)
{
this.turns = turns;
return this;
}
}
也许这是关于瓦类是静态的?
其中isHit定义?另外,A *通常使用优先级队列和启发式函数实现,但我没有看到它们。 – Antimony 2013-04-07 19:15:40
你说你实现'A *',那么你的启发函数在哪里?你使用哪个?请注意,'A *'算法仅仅是'Dijkstra'算法的一个普通实现,不同之处在于增加**启发函数**以提高速度。一种可能的启发是* as-the-crows-fly *,但也有其他可能性。 – Zabuza 2018-03-08 16:34:53
如果有帮助,[这里](https://github.com/ZabuzaW/PathWeaver/blob/master/src/de/zabuza/pathweaver/network/algorithm/shortestpath/DijkstraShortestPathComputation.java)Dijkstra算法是用Java实现说明。和[这里](https://github.com/ZabuzaW/PathWeaver/blob/master/src/de/zabuza/pathweaver/network/algorithm/shortestpath/AStarShortestPathComputation.java)是把它变成唯一需要改变的' A *',使用*作为最乌鸦飞*从[这里](https://github.com/ZabuzaW/PathWeaver/blob/master/src/de/zabuza/pathweaver/network/algorithm/metric/ StraightLineRoadTimeMetric.java)。 – Zabuza 2018-03-08 16:38:47