The performance of Javascript versus Java on PlayN varies significantly

After building the PlayN project and running the Java version, I noticed that its behavior is not consistent with the HTML version.

I created a board game that utilizes a customized Minimax algorithm for its AI, which includes a search tree and evaluation weighting.

Given that there are no random calculations involved and same inputs should yield same outputs, it is surprising to see the different behaviors of the Java and JavaScript versions of the AI.

You can access the Html/javascript version here.

The Java (JAR) file can be downloaded from here.

Despite using the same code and Ant scripts for compilation, the results vary. Could it be possible that the difference in performance is due to resource limitations on the JavaScript environment?

Any assistance or insights would be greatly appreciated. Thank you.

Answer №1

When traversing through the elements of a HashMap, you have to be aware that there is no guaranteed order in which the values will be returned. In this case, the Board class contains a HashMap called emptyCells, and the GameSearch class uses the method Board.getEmptyCellCollection to retrieve a collection of values from this HashMap for iteration. Since HashMap does not maintain insertion order, the sequence of values may vary between Java and JavaScript versions.

To ensure a consistent order when iterating over a HashMap, consider using a LinkedHashMap instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Populating a form field using another input

I am facing an issue with retrieving the price of a product in one field when the product name is selected in another field on a simple POS system. It works fine for the first product, but when I add another row for the next product, the price does not dis ...

A square containing two triangular interactive zones

My goal is to divide a square-shaped div diagonally, creating two triangles. Each triangle should respond to the hover event. However, I have encountered a problem where if you move from one corner of the div directly to the opposite corner, the hover eve ...

Utilize jQuery to convert text to lowercase before adding Capitalize CSS styling

I have encountered a situation where I need to change the HTML link values from UPPERCASE to LOWERCASE and then apply a capitalization style. The problem lies in the fact that the links arrive in uppercase, so I had to come up with a workaround: The given ...

I am facing an issue with updating the state dynamically within a useState object

Within my useState, there is an object containing a variety of values. I have an input field and am dynamically setting its value to useState[key], which works fine. However, the issue arises when I try to update these values. When I call onChange and use ...

Encountering difficulties during the login process for an application

Having trouble signing in? I encountered an issue while using the following code snippet. It seems that when I try to sign in with a phone number for the second time, instead of prompting "this number already exists", it isn't working as expected. Add ...

Utilizing Angular and Express for routing with the seamless integration of html5mode

I'm facing an issue with making angular and express routing work together with html5mode enabled. When I change state from '/' to my admins state, everything works fine until I refresh the page. Then I only get a json result of admins but my ...

What is the best way to determine the identifier of an object in Java programming language?

Currently grappling with a coding issue where I am attempting to utilize System.out.println() in order to display the name of an object. For instance, given the code snippet String foo = new String("Hi");, my goal is to output "foo". Any suggestions on h ...

What is the reason that when we assign `'initial'` as the value for `display` property, it does not function as intended for list elements?

To toggle the visibility of elements, I have created a unique function that accepts an object and a boolean. Depending on the boolean value, either 'none' or 'initial' is assigned to the 'display' property of the specified obj ...

Learn how to dynamically set the "selected" option in Vue based on object data

I've done some digging on SO but haven't found exactly what I need. So, here's the situation - I've got a sorting function in progress. I have an array of date ranges (PayPeriods) that I want to render into a select with option compone ...

Turning a JSON dot string into an object reference in JavaScript: A simple guide

Having a JSON object labeled test with values like this: {"items":[{"name":"test"}]}, I need a way to apply the string items[0].name to it in order to search for a specific value (test.items[0].name). Currently, my only idea is to create a function that pa ...

Let's leverage the power of Node.js and Express with the Jade templating

My goal is to iterate over an array within a jade layout file named lessons.jade: each lesson in myLessons ul.nav.pull-center: li.dropdown.nav.text-center .btn.btn-default.dropdown-toggle.btn-lg.btn-block(data-toggle="dropdown ...

What is the best JavaScript framework for implementing client-side hyphenation?

Looking to improve my website's readability, I want to implement client-side hyphenation using JavaScript for longer texts. Although CSS3 hyphenation is preferred, it's not always available. So far, I've been using Hyphenator.js, which, whi ...

Whenever the download bar emerges at the bottom, the slideshow content on the page suddenly shifts upwards

Each time the download bar shows up at the bottom, the slideshow content on the Homepage suddenly moves up. It returns to its original position after I close the download bar.https://photos.app.goo.gl/F482eMfkXyfEZkdA9. My assumption is that this issue is ...

Guide to sending client-to-client notifications in Angular/Ionic with Firebase Cloud Messaging

I am looking to implement client-client push notifications (not server-to-client). My goal is to send a notification when one user messages another. Is this feasible? How can I achieve this using the structure in the Firebase real-time database? Here is a ...

What steps can I take to establish a simple yet secure password authentication using next.js, mongoDB, and bcrypt?

As a hobby programmer working on my project, I aim to implement a secure password authentication system in my next.js project using only my next.js backend API and MongoDB (Atlas via Data API). I understand that there are various third-party authentication ...

Having trouble running the server in Node.js

When working with Node.Js, I encountered a specific issue My progress stopped at 6:16 when the instructions mentioned running "node server.js" to open 127.0.0.1:3000, but instead, an error occurred. https://i.sstatic.net/6esE5.png Upon checking my brows ...

Is there a method to have JavaScript display all the information during a SQL while loop?

I'm currently working on implementing a timer for my script. However, I am facing an issue where the timer only counts down from the last result instead of each individual result returned from the query. Any assistance with resolving this problem woul ...

Creating a Star Rating system with jQuery using a dropdown menu for multiple selections

Recently, I came across a simple jQuery Star rating system that I want to implement on my website. I have been following the code from http://jsfiddle.net/, and it works perfectly for one star rating system. However, I have multiple star rating systems on ...

Filtering API Gateway requests for your Java lambda function based on the request path can be achieved by implementing a few

My Lambda function is integrated with API Gateway using proxy integration, allowing it to accept proxy+ resources as input. I have a Java Lambda class that takes APIGatewayProxyRequestEvent type as input and provides APIGatewayProxyRequestOutput as the re ...

What is the method for enlarging the width of the nvd3 chart timespan?

Click here In the Plnkr linked above, I have included the latest versions of d3 and nvd3 libraries. Upon initial viewing of the chart, you may notice that all the timespan ticks such as 09:00, 08:30, 08:00, etc., are overlapping on the left xAxis. The ti ...