Calculating Manhattan Distance

前端 未结 1 631
没有蜡笔的小新
没有蜡笔的小新 2020-12-17 16:58

I\'m implementing NxN puzzels in Java 2D array int[][] state. am required to use the Manhattan heuristic in the following way:

             the sum of the v         


        
1条回答
  •  失恋的感觉
    2020-12-17 17:15

    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);
    

    More info: http://en.wikipedia.org/wiki/Taxicab_geometry

    0 讨论(0)
提交回复
热议问题