我正在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
Run Code Online (Sandbox Code Playgroud)
目前我不知道该怎么走.我是2D阵列益智游戏编程的初学者,所以很难理解某些概念.
我在询问是否有人可以帮助我逐步向我解释在Java中编写此代码时必须遵循的程序.
谢谢
Ott*_*ger 44
这更像是一个数学问题,但无论如何,曼哈顿距离是水平距离和垂直距离的绝对值之和
int distance = Math.abs(x1-x0) + Math.abs(y1-y0);
Run Code Online (Sandbox Code Playgroud)
更多信息:http://en.wikipedia.org/wiki/Taxicab_geometry
| 归档时间: |
|
| 查看次数: |
45628 次 |
| 最近记录: |