From c5d8503dbbcb3fd0dd2ca1489baf2d01733e7480 Mon Sep 17 00:00:00 2001 From: philippe lhardy Date: Tue, 5 Dec 2017 19:37:58 +0100 Subject: [PATCH] resolved now support multiple path --- java/org/artisanlogiciel/games/LabyModel.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/java/org/artisanlogiciel/games/LabyModel.java b/java/org/artisanlogiciel/games/LabyModel.java index 86b968c..3bd6e36 100644 --- a/java/org/artisanlogiciel/games/LabyModel.java +++ b/java/org/artisanlogiciel/games/LabyModel.java @@ -656,7 +656,6 @@ TODO public LinkedList resolve(int x, int y, MazeResolutionListener rlistener) { long safeguard = width * height; - short selectedDirection = 0; int newx = 0; int newy = 0; @@ -668,7 +667,7 @@ TODO // list of positions from start to end LinkedList backpath = new LinkedList(); // position that point to (x,y). - DirectionPosition found = new DirectionPosition(selectedDirection,new Position(x, y)); + DirectionPosition found = new DirectionPosition((short) 0,new Position(x, y)); // entry Position entry = new Position(0, 0); @@ -725,9 +724,10 @@ TODO { if (isFlagSet(getCell(p),reversedirection)) { - System.out.println("check " + p); if (found != null) { + // there is already a potential solution in adjacent cell of last. + System.out.println("alternate " + p + " from " + last + "/" + safeguard); // could be a unique parent of two paths... // but search from other entry/exits than generated // from @@ -754,26 +754,35 @@ TODO } } } - selectedDirection=reversedirection; - if (! isFlagSet(getCell(p), SOLVED )) + else { - // was already solved. - found = new DirectionPosition(selectedDirection,p); - if (rlistener != null) + if (! isFlagSet(getCell(p), SOLVED )) { - rlistener.notifySearch(found); + // this is first potential solution in adjacent cell of last. + System.out.println("check " + p + " from " + last + "/" + safeguard); + + found = new DirectionPosition(reversedirection,p); + if (rlistener != null) + { + rlistener.notifySearch(found); + } + } + else + { + // was already solved. + System.out.println("already solved " + p + " from " + last + "/" + safeguard); } } // support multiple pathes } else { - System.out.println("not reachable " + p + " from " + found); + System.out.println("not reachable " + p + " from " + last + "/" + safeguard); } } else { - System.out.println("p outofbounds " + p); + System.out.println("p outofbounds " + p + "/" + safeguard); } } if (found == null) @@ -793,6 +802,10 @@ TODO } if (found == null) { + if ( ! altpath.isEmpty() ) + { + rlistener.notifySearchError("No path found BUT ALTPATH !" ); + } rlistener.notifySearchError("No path found !"); break; }