resolved now support multiple path

This commit is contained in:
philippe lhardy
2017-12-05 19:37:58 +01:00
parent b2c5bc0d97
commit c5d8503dbb

View File

@@ -656,7 +656,6 @@ TODO
public LinkedList<DirectionPosition> resolve(int x, int y, MazeResolutionListener rlistener) public LinkedList<DirectionPosition> resolve(int x, int y, MazeResolutionListener rlistener)
{ {
long safeguard = width * height; long safeguard = width * height;
short selectedDirection = 0;
int newx = 0; int newx = 0;
int newy = 0; int newy = 0;
@@ -668,7 +667,7 @@ TODO
// list of positions from start to end // list of positions from start to end
LinkedList<DirectionPosition> backpath = new LinkedList<DirectionPosition>(); LinkedList<DirectionPosition> backpath = new LinkedList<DirectionPosition>();
// position that point to (x,y). // 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 // entry
Position entry = new Position(0, 0); Position entry = new Position(0, 0);
@@ -725,9 +724,10 @@ TODO
{ {
if (isFlagSet(getCell(p),reversedirection)) if (isFlagSet(getCell(p),reversedirection))
{ {
System.out.println("check " + p);
if (found != null) 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... // could be a unique parent of two paths...
// but search from other entry/exits than generated // but search from other entry/exits than generated
// from // from
@@ -754,26 +754,35 @@ TODO
} }
} }
} }
selectedDirection=reversedirection; else
{
if (! isFlagSet(getCell(p), SOLVED )) if (! isFlagSet(getCell(p), SOLVED ))
{ {
// was already solved. // this is first potential solution in adjacent cell of last.
found = new DirectionPosition(selectedDirection,p); System.out.println("check " + p + " from " + last + "/" + safeguard);
found = new DirectionPosition(reversedirection,p);
if (rlistener != null) if (rlistener != null)
{ {
rlistener.notifySearch(found); rlistener.notifySearch(found);
} }
} }
else
{
// was already solved.
System.out.println("already solved " + p + " from " + last + "/" + safeguard);
}
}
// support multiple pathes // support multiple pathes
} }
else else
{ {
System.out.println("not reachable " + p + " from " + found); System.out.println("not reachable " + p + " from " + last + "/" + safeguard);
} }
} }
else else
{ {
System.out.println("p outofbounds " + p); System.out.println("p outofbounds " + p + "/" + safeguard);
} }
} }
if (found == null) if (found == null)
@@ -793,6 +802,10 @@ TODO
} }
if (found == null) if (found == null)
{ {
if ( ! altpath.isEmpty() )
{
rlistener.notifySearchError("No path found BUT ALTPATH !" );
}
rlistener.notifySearchError("No path found !"); rlistener.notifySearchError("No path found !");
break; break;
} }