English 中文(简体)
Behaviour of Javascript and Java on PlayN is different
原标题:

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.

最佳回答

It looks like you are iterating over the contents of a HashMap. Board defines emptyCells which is a HashMap, and then GameSearch calls Board.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.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签