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與一個很好的解決方案.. –
我真的搜索,但我找不到。謝謝 –