Git Product home page Git Product logo

jps's Issues

Broken algorithm.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.