计算曼哈顿距离
我正在java 2D数组int [] []状态中实现NxN puzzels。 我需要以下列方式使用曼哈顿的heureustic:
the sum of the vertical and horizontal distances from the current node to the goal node/tile +(plus) the number of moves to reach the goal node from the initial position
目前我不知道该怎么走。 我是2Darrays益智游戏编程的初学者,所以很难理解某些概念。
我问是否有人可以通过逐步向我解释我必须遵循以Java编写此代码的程序来帮助我。
谢谢
这更像是一个数学问题,但无论如何,曼哈顿距离是水平距离和垂直距离的绝对值之和
int distance = Math.abs(x1-x0) + Math.abs(y1-y0);
更多信息: http : //en.wikipedia.org/wiki/Taxicab_geometry