PlayN 上 Javascript 和 Java 的行为不同
当我构建 PlayN 项目并运行 java 版本时,其行为与运行 HTML 版本时不同。
基本上,我制作了一款棋盘游戏,其人工智能使用了 Minimax 算法的修改版本(搜索树和权重评估)。
由于没有任何内容是随机计算的,并且如果输入相同,我希望输出也相同。
然而,java 和 javascript (HTML) 版本的 AI 对相同输入的行为有所不同。
可以在此处找到 Html/javascript 版本的链接: http://mugle-app.appspot.com/+games/staff/fiar/
java (JAR) 文件可以在以下位置找到: http://ez-playn.googlecode.com/files/FiarJava.zip
它们都使用相同的代码,只是编译不同,但都使用提供的 Ant 脚本。树深度是固定的,评估器权重是固定的
我无法理解为什么会有差异,因为除了搜索树之外,所有东西都有效......可能是因为评估很重并且 javascript 运行资源不足?
感谢您的任何帮助。
When I build the PlayN project and run the java version, it's behaviour is different to when I run the HTML version.
Basically I made a board game that uses a modified version of the Minimax algorithm (search tree and weighting evaluation) for its AI.
Since nothing is calculated randomly, and if the inputs are the same, I'd expect the outputs to be the same too.
However, the AI's of the java and javascript (HTML) versions behave differently to the same input.
The link to the Html/javascript version can be found here:
http://mugle-app.appspot.com/+games/staff/fiar/
The java (JAR) file can be found at:
http://ez-playn.googlecode.com/files/FiarJava.zip
They both use the same code, only compilations have been different, but both using the provided Ant scripts. Tree depth is fixed, evaluator weightings are fixed
I can't understand why there would be a difference since every thing works except the search tree...could it be because that evaluation is heavy and javascript run's out of resources?
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在迭代 HashMap 的内容。
Board
定义了emptyCells
,它是一个 HashMap,然后GameSearch
调用Board.getEmptyCellCollection
(它返回HashMap 作为一个集合),然后迭代它们。这些值没有具有可预测的顺序,并且在从 Java 到 JavaScript 的转换过程中顺序几乎肯定会发生变化。如果需要以可预测的顺序迭代 HashMap 的内容,请使用 LinkedHashMap。
It looks like you are iterating over the contents of a HashMap.
Board
definesemptyCells
which is a HashMap, and thenGameSearch
callsBoard.getEmptyCellCollection
(which returns the values of the HashMap as a collection) and then iterates over them. Those values do not have a predictable ordering, and the ordering will almost certainly change in the conversion from Java to JavaScript.If you need to iterate over the contents of a HashMap in predictable order, use LinkedHashMap.