1
我发现了一个对我来说在实现A *时非常有用的代码。但我面临一个问题。 我需要计算曼哈顿距离,我试图实现一个,但它不工作。此代码提供欧几里德距离的计算。从欧几里得距离转换为曼哈顿距离c#
public Node(Node parentNode, Node goalNode, int gCost,int x, int y)
{
this.parentNode = parentNode;
this._goalNode = goalNode;
this.gCost = gCost;
this.x=x;
this.y=y;
InitNode();
}
private void InitNode()
{
this.g = (parentNode!=null)? this.parentNode.g + gCost:gCost;
this.h = (_goalNode!=null)? (int) Euclidean_H():0;
}
private double Euclidean_H()
{
double xd = this.x - this._goalNode .x ;
double yd = this.y - this._goalNode .y ;
return Math.Sqrt((xd*xd) + (yd*yd));
}
使用c#代码。 非常感谢。
首先搜索我没有 - 没有一个确切的同样的问题 - http://stackoverflow.com/questions/4532528/manhattan-heuristic-function-for-a-star-a与一个很好的解决方案.. –
我真的搜索,但我找不到。谢谢 –