kevinsheehan / jps Goto Github PK
View Code? Open in Web Editor NEWJava Jump Point Search Implementation
Java Jump Point Search Implementation
Hello, I believe the algorithm is broken. Here's my test code:
package jps;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
public class JPSTest {
public static void main(String[] args) throws ExecutionException, InterruptedException {
Tile[][] tiles = new Tile[100][100];
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
tiles[i][j] = new Tile(i, j);
}
}
List<List<Tile>> tileList = JPSTestUtil.arraysToLists(tiles);
Tile start = tileList.get(0).get(0);
Tile end = tileList.get(99).get(99);
for (Tile tile : tileList.get(50)) {
tile.walkable = false;
}
tileList.get(50).get(20).walkable = true;
tileList.get(50).get(21).walkable = true;
tileList.get(50).get(22).walkable = true;
for (List<Tile> list : tileList) {
for (Tile tile : list) {
System.out.print((tile.walkable ? 0 : "*") + " ");
}
System.out.println();
}
JPS<Tile> jps = JPS.JPSFactory.getJPS(new Graph<>(tileList), Graph.Diagonal.ALWAYS);
Future<Queue<Tile>> futurePath = jps.findPath(start, end);
Queue<Tile> path = futurePath.get();
System.out.println();
for (List<Tile> list : tileList) {
for (Tile tile : list) {
if (path != null) {
Tile element = path.peek();
if (tile.x == element.x && tile.y == element.y) {
System.out.print("-" + " ");
path.remove();
} else
System.out.print((tile.walkable ? 0 : 1) + " ");
} else {
System.out.println("No path");
return;
}
}
System.out.println();
}
}
}
If you comment out the lines, you can see the path that looks like this: https://pastebin.com/raw/2DaUSqt5
However, if you un-comment the lines, you notice an error message "no path" because the queue Queue<Tile> path = futurePath.get();
is empty. However, there is clearly an opening in the path. Seen here: https://pastebin.com/raw/zsUPVJdt In this example, there are 3 walkable tiles on line 50, so the algorithm SHOULD be able to find a path through, yet it does not.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.