java中用于解决8个难题的合适树类是什么

发布于 2024-09-06 12:10:22 字数 97 浏览 1 评论 0原文

我正在做一个用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半枫 2024-09-13 12:10:22

我不明白你为什么要使用一棵树。

如果您想以尽可能少的移动次数解决 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.

暮色兮凉城 2024-09-13 12:10:22

您可能需要考虑使用 A* 搜索来实现此目的。可以在此处找到对该算法的详细解释。

You may want to consider using A* search for this. A good explanation of the algorithm can be found here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文