[英]Manhattan distance to drive the search in NxN 2D array
I would like to know how to use the Manhattan Distance heuristic to drive my search in NxN 2d array.我想知道如何使用曼哈顿距离启发式算法来驱动我在 NxN 二维数组中的搜索。 I have the following Manhattan distance:
我有以下曼哈顿距离:
private int manhattan(int[] pos, int tile) {
int[] dest = new int[] {
(tile - 1) % BOARDSIZE, (tile - 1) / BOARDSIZE
};
return Math.abs(dest[0] - pos[0]) + Math.abs(dest[1] - pos[1]);
}
I will be moving tiles to the empty tile to LEFT, RIGHT, UP or DOWN.我将把瓷砖移到空瓷砖上向左、向右、向上或向下。 How do I use the above function to select neighbours of a node in order to add to a queue?
如何使用上述函数选择节点的邻居以添加到队列中? Do I have to put it in a double for loop or?
我必须把它放在一个双循环中还是? I am using
f = g+h
.我正在使用
f = g+h
。
I am a beginner in puzzles so am struggling a little bit to understand.我是拼图的初学者,所以我有点难以理解。
I can see you've rewritten your earlier question.我可以看到你已经重写了你之前的问题。 The question you pose is explored in detail in Russell and Norvig's Artificial Intelligence: A Modern Approach .
您提出的问题在Russell 和 Norvig 的人工智能:现代方法中进行了详细探讨。 Read the 3rd chapter.
阅读第 3 章。 Check out their website at http://aima.cs.berkeley.edu/ .
查看他们的网站http://aima.cs.berkeley.edu/ 。 They even have code for A* there, with a link to a demo of the 8 puzzle .
他们甚至在那里有 A* 的代码,以及一个8 拼图演示的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.