计算曼哈顿距离曼哈顿、距离

2023-09-11 04:06:32 作者:烟雨红尘

我实施的N×N puzzels在Java二维数组INT [] []状态。感到需要使用曼哈顿heureustic按以下方式:

I'm implementing NxN puzzels in java 2D array int[][] state. am required to use the manhattan heureustic in the following way:

             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

目前,我不知道该怎么走的更远。我在益智游戏编程二维数组所以我出汗难初学者理解某些概念。

At the moment i don't know how to go further. Am a beginner in puzzle game programming with 2D arrays so am sweating hard to understand certain concepts.

在问,如果有人可以解释给我一步一步帮助我的程序必须遵循写这篇code Java编写的。

Am asking if someone can help by explaining to me the step by step the procedure i must follow to write this code in Java.

谢谢

推荐答案

这更是一个数学问题,但反正曼哈顿距离是水平和垂直距离

This is more a math question, but anyways the Manhattan distance is the sum of the absolute values of the horizontal and the vertical distance

int distance = Math.abs(x1-x0) + Math.abs(y1-y0);

更多信息:http://en.wikipedia.org/wiki/Taxicab_geometry