计算曼哈顿距离 [英] Calculating Manhattan Distance

查看:239
本文介绍了计算曼哈顿距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施的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);

更多信息:<一href="http://en.wikipedia.org/wiki/Taxicab_geometry">http://en.wikipedia.org/wiki/Taxicab_geometry

这篇关于计算曼哈顿距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆