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)
{
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<DirectionPosition> backpath = new LinkedList<DirectionPosition>();
// 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;
}