java中用于解决8个难题的合适树类是什么
我正在做一个用 java 开发的 AI for 8 拼图。我有 1 个类保存 8 个拼图板的二维字符串数组。这个类还保存其他必要的信息。问题是什么是我将用来保存每个对象的合适的树。
I'm doing an AI for 8 puzzle that develop on java. I have 1 class that keep the 2 dimension array of string that is a 8 puzzle board. This class also keep other necessary information. The question what is an appropriate tree that i will use to keep each object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白你为什么要使用一棵树。
如果您想以尽可能少的移动次数解决 8 个难题,那么您实际上需要找到从当前配置到图中“已解决”配置的最短路径,其中顶点是配置,边是移动。
最短路径可以通过广度优先搜索等来解决。
我认为这段代码很好地解释了它: http://www.dreamincode.net/code/snippet1914 .htm
(隐式)图可以在心里被描绘成一棵树,但所描绘的更像是算法的控制流。
I can't see why you would want to use a tree.
If you're after solving an 8-puzzle in as few moves as possible, what you're after is actually finding the shortest path from the current configuration to the "solved" configuration in a graph where vertices are configurations and edges are moves.
The shortest path can be solved with for instance a breadth-first search.
I think this code explains it fairly well: http://www.dreamincode.net/code/snippet1914.htm
The (implicit) graph could mentally be pictured as a tree, but what is being depicted is more like the control flow of the algorithm.
您可能需要考虑使用 A* 搜索来实现此目的。可以在此处找到对该算法的详细解释。
You may want to consider using A* search for this. A good explanation of the algorithm can be found here.