Can somebody explain in Manhattan dstance for the 8 puzzle in java for me?

天大地大妈咪最大 提交于 2019-12-04 21:33:50

There is a fine point of difference in what the goal state looks like for you, and what the goal state looks like for the reference implementation you are viewing.

For the reference implementation, it works if the goal state looks like:

1 2 3
4 5 6
7 8 0

In your case, you want Manhattan distance for:

0 1 2
3 4 5 
6 7 8

A quick fix is to simply redefine your goal state as the former.

However, if the latter is what you really want, then change the targetX/Y to not have a subtraction of 1 from value.

The manhattan distance is the distance defined as the increase in the distance when moving pieces diagonally. If the movable tile is in the upper right hand corner, to move the piece to the bottom left hand corner, you can't move it directly along the diagonal. You have to make sequential left then down move. The increase is the manhattan distance. The fun part of this is the shuffling algorithm. The manhattan distance is also know in mathematics as the taxi-cab distance, http://en.wikipedia.org/wiki/Taxicab_geometry .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!