LabyModel limit public constructors to
LabyModel(MazeParams params, Random random) and LabyModel(String pFormat, InputStream pIn) fix unchecked and (java9) deprecated Short(short)
This commit is contained in:
@@ -33,9 +33,11 @@ public class LabyModel implements WallsProvider
|
||||
public final static short DIRECTION = 4; // could we get rid of that to
|
||||
// free one bit for other purpose
|
||||
// ?
|
||||
// can be both POSITIVE and NEGATIVE, it means that you can move in positive direction and in negative direction.
|
||||
public final static short POSITIVE = 8;
|
||||
public final static short NEGATIVE = 16;
|
||||
|
||||
|
||||
// can it be both OPEN and CLOSED ?
|
||||
private final static short OPEN = 32; // can be reused once generation is
|
||||
// completed
|
||||
private final static short CLOSED = 64; // can be reused once generation is
|
||||
@@ -44,25 +46,23 @@ public class LabyModel implements WallsProvider
|
||||
public final static short DOWN = Brick.DOWN << FLAGLENGTH | DIRECTION | VERTICAL | POSITIVE;
|
||||
public final static short RIGHT = Brick.RIGHT << FLAGLENGTH | DIRECTION | HORIZONTAL | POSITIVE;
|
||||
public final static short UP = Brick.UP << FLAGLENGTH | DIRECTION | VERTICAL | NEGATIVE;
|
||||
public final static short ENTRY = Brick.ENTRY << FLAGLENGTH; // flag when a
|
||||
// wall should
|
||||
// be open to
|
||||
// access
|
||||
// this.
|
||||
private final static short GOAL = Brick.GOAL << FLAGLENGTH; // flag when a
|
||||
// wall should
|
||||
// be open to
|
||||
// access this.
|
||||
public final static short SOLVED = 64 << FLAGLENGTH; // flag when solution
|
||||
// is on this path.
|
||||
private final static short FREE = 128 << FLAGLENGTH; // free flag
|
||||
|
||||
// flag when a wall should be open to access this for entry
|
||||
public final static short ENTRY = Brick.ENTRY << FLAGLENGTH;
|
||||
// flag when a wall should be open to access this for exit
|
||||
private final static short GOAL = Brick.GOAL << FLAGLENGTH;
|
||||
// flag when solution is on this path.
|
||||
public final static short SOLVED = 64 << FLAGLENGTH;
|
||||
// free flag
|
||||
private final static short FREE = 128 << FLAGLENGTH;
|
||||
// remains 2 free bits ( keep one out for sign )
|
||||
|
||||
// orders matters see getReverseDirection
|
||||
private static final short[] AllDirections = { LEFT, DOWN, RIGHT, UP };
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
// wall flags + status flags for each position (x,y)
|
||||
// wall flags Brick.(LEFT,DOWN,RIGHT,UP,ENTRY,GOAL) + status flags for each position (x,y)
|
||||
private short[][] t;
|
||||
private int depth = 0;
|
||||
/**
|
||||
@@ -71,11 +71,15 @@ public class LabyModel implements WallsProvider
|
||||
* that to shorter maxdepth is the harder the labyrinth is ...
|
||||
**/
|
||||
private int maxdepth = 0;
|
||||
private int deepest = 0; // longest path found
|
||||
// longest path found
|
||||
private int deepest = 0;
|
||||
// each move is a linearwork step
|
||||
private int linearwork = 0;
|
||||
|
||||
private Position deepestEnd = null;
|
||||
boolean maxreached = false;
|
||||
java.util.Random random;
|
||||
// list of positions not fully walked
|
||||
private final LinkedList<Position> openList = new LinkedList<Position>();
|
||||
// list of entries and exits.
|
||||
private final LinkedList<Position> entryExits = new LinkedList<Position>();
|
||||
@@ -87,7 +91,7 @@ public class LabyModel implements WallsProvider
|
||||
MazeCreationListener listener = null;
|
||||
|
||||
|
||||
public LabyModel(int width, int height, int maxdepth, Random random)
|
||||
private LabyModel(int width, int height, int maxdepth, Random random)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
@@ -99,14 +103,12 @@ public class LabyModel implements WallsProvider
|
||||
|
||||
public LabyModel(MazeParams params, Random random)
|
||||
{
|
||||
this.width = params.getWidth();
|
||||
this.height = params.getHeight();
|
||||
this.maxdepth = params.getMaxDepth();
|
||||
this.random = random;
|
||||
// CLEAR == 0 and array is initialized with 0s
|
||||
t = new short[width][height];
|
||||
this(params.getWidth(),params.getHeight(),params.getMaxDepth(),random);
|
||||
}
|
||||
|
||||
/**
|
||||
construct LabyModel from an InputStream, yet only "raw" is supported
|
||||
**/
|
||||
public LabyModel(String pFormat, InputStream pIn) throws IOException
|
||||
{
|
||||
parseInputStream(pFormat, pIn);
|
||||
@@ -123,7 +125,6 @@ public class LabyModel implements WallsProvider
|
||||
if ((x >= 0) && (x < width) && (y >= 0) && (y < height))
|
||||
{
|
||||
// t[x][y] |= DIRECTION | VERTICAL | POSITIVE | HORIZONTAL | NEGATIVE | LEFT | RIGHT | UP | DOWN;
|
||||
t[x][y] |= DIRECTION | VERTICAL | POSITIVE | HORIZONTAL | NEGATIVE;
|
||||
t[x][y] |= LEFT | RIGHT | UP | DOWN;
|
||||
}
|
||||
}
|
||||
@@ -392,7 +393,7 @@ public class LabyModel implements WallsProvider
|
||||
brickMap[x][y] = new Brick(out2XY(x, y), outHorizWall2XY(x, y), getWalls(x, y));
|
||||
}
|
||||
}
|
||||
return new LabyMap(brickMap, (LinkedList<Position>) entryExits.clone());
|
||||
return new LabyMap(brickMap, new LinkedList<Position>(entryExits));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,8 +445,7 @@ public class LabyModel implements WallsProvider
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
// resetCell(x,y);
|
||||
t[x][y] &= ~( OPEN | SOLVED);
|
||||
|
||||
t[x][y] &= ~( OPEN | SOLVED);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -485,6 +485,7 @@ public class LabyModel implements WallsProvider
|
||||
return check;
|
||||
}
|
||||
|
||||
// coherency : if CLOSED then not OPEN
|
||||
public void computeOpenList()
|
||||
{
|
||||
openList.clear();
|
||||
@@ -505,7 +506,7 @@ public class LabyModel implements WallsProvider
|
||||
}
|
||||
|
||||
/**
|
||||
generate a maze with an entry set at (x,y)
|
||||
generate a maze with an entry set at (x,y) with a maxdepth
|
||||
**/
|
||||
public void generateWithEntry(int x, int y)
|
||||
{
|
||||
@@ -696,7 +697,7 @@ public class LabyModel implements WallsProvider
|
||||
// internal GUARD.
|
||||
if (! isFlagSet(reversedirection,pointingdirection))
|
||||
{
|
||||
System.out.println("Internal ERROR. Please check AllDirections order "
|
||||
System.out.println("[FATAL] Internal ERROR. Please check AllDirections order "
|
||||
+ (reversedirection & pointingdirection) + " " + pointingdirection);
|
||||
return backpath;
|
||||
}
|
||||
@@ -718,7 +719,7 @@ public class LabyModel implements WallsProvider
|
||||
{
|
||||
if (! isFlagSet(getCell(p), SOLVED ))
|
||||
{
|
||||
LinkedList<DirectionPosition> cp = (LinkedList<DirectionPosition>) backpath.clone();
|
||||
LinkedList<DirectionPosition> cp = new LinkedList<DirectionPosition>(backpath);
|
||||
DirectionPosition altfound = new DirectionPosition(reversedirection,p);
|
||||
cp.addFirst(altfound);
|
||||
altpath.addLast(cp);
|
||||
@@ -884,7 +885,7 @@ public class LabyModel implements WallsProvider
|
||||
{
|
||||
if ((t[newx][newy]) == CLEAR)
|
||||
{
|
||||
freeDirection.add(new Short(direction));
|
||||
freeDirection.add(Short.valueOf(direction));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1087,30 +1088,37 @@ public class LabyModel implements WallsProvider
|
||||
{
|
||||
throw new IOException("Use correct constructor.");
|
||||
}
|
||||
|
||||
|
||||
private void parseInputStream(String pFormat, InputStream pIn) throws IOException
|
||||
{
|
||||
if ((pFormat == null) || (pFormat.equals("raw")))
|
||||
{
|
||||
// maxdepth is unset then unmodified
|
||||
byte[] header = new byte[4];
|
||||
DataInputStream in = new DataInputStream(pIn);
|
||||
in.read(header);
|
||||
int rwidth = in.readInt();
|
||||
int rheight = in.readInt();
|
||||
width = rwidth;
|
||||
height = rheight;
|
||||
maxdepth = maxdepth;
|
||||
random = null;
|
||||
// SHOULD CHECK max width and max height...
|
||||
// CLEAR == 0 and array is initialized with 0s
|
||||
t = new short[width][height];
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
t[x][y] = in.readShort();
|
||||
}
|
||||
}
|
||||
if ( (rwidth > 0) && (rheight > 0 ) )
|
||||
{
|
||||
width = rwidth;
|
||||
height = rheight;
|
||||
random = null;
|
||||
// SHOULD CHECK max width and max height...
|
||||
// CLEAR == 0 and array is initialized with 0s
|
||||
t = new short[width][height];
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
t[x][y] = in.readShort();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException("Invalid header for width and height");
|
||||
}
|
||||
// should be at end of stream ? Not necessary can stream multiple
|
||||
// labs ( or tiling ).
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user