true
always
diff --git a/src/main/java/ch/fritteli/labyrinth/generator/renderer/text/Generator.java b/src/main/java/ch/fritteli/labyrinth/generator/renderer/text/Generator.java
index 8378018..b8be526 100644
--- a/src/main/java/ch/fritteli/labyrinth/generator/renderer/text/Generator.java
+++ b/src/main/java/ch/fritteli/labyrinth/generator/renderer/text/Generator.java
@@ -15,6 +15,13 @@ class Generator {
private final boolean renderSolution;
private int x = 0;
private int y = 0;
+ // Each row has three lines:
+ // - The top border
+ // - The central pathway
+ // - The bottom border
+ // The bottom border of one row is identical to the top border of the following row. We use this variable here in
+ // order to be able to render the bottom border of the last row, which obviously does not have a following row with
+ // a top border.
private int line = 0;
boolean hasNext() {
diff --git a/src/main/java/ch/fritteli/labyrinth/generator/serialization/SerializerDeserializer.java b/src/main/java/ch/fritteli/labyrinth/generator/serialization/SerializerDeserializer.java
index 3315202..ae4df70 100644
--- a/src/main/java/ch/fritteli/labyrinth/generator/serialization/SerializerDeserializer.java
+++ b/src/main/java/ch/fritteli/labyrinth/generator/serialization/SerializerDeserializer.java
@@ -12,23 +12,23 @@ import java.util.EnumSet;
/**
*
- * decimal hex border
- * 0 0 no border
- * 1 1 top
- * 2 2 right
- * 3 3 top+right
- * 4 4 bottom
- * 5 5 top+bottom
- * 6 6 right+bottom
- * 7 7 top+right+bottom
- * 8 8 left
- * 9 9 top+left
- * 10 a right+left
- * 11 b top+right+left
- * 12 c bottom+left
- * 13 d top+bottom+left
- * 14 e right+bottom+left
- * 15 f top+right+bottom+left
+ * decimal hex bin border
+ * 0 0 0000 no border
+ * 1 1 0001 top
+ * 2 2 0010 right
+ * 3 3 0011 top+right
+ * 4 4 0100 bottom
+ * 5 5 0101 top+bottom
+ * 6 6 0110 right+bottom
+ * 7 7 0111 top+right+bottom
+ * 8 8 1000 left
+ * 9 9 1001 top+left
+ * 10 a 1010 right+left
+ * 11 b 1011 top+right+left
+ * 12 c 1100 bottom+left
+ * 13 d 1101 top+bottom+left
+ * 14 e 1110 right+bottom+left
+ * 15 f 1111 top+right+bottom+left
*
* ==> bits 0..2: always 0; bit 3: 1=solution, 0=not solution; bits 4..7: encode walls
* ==> first bytes are:
@@ -64,24 +64,9 @@ public class SerializerDeserializer {
*/
@NonNull
public byte[] serialize(@NonNull final Labyrinth labyrinth) {
- @NonNull final LabyrinthOutputStream stream = new LabyrinthOutputStream();
- final int width = labyrinth.getWidth();
- final int height = labyrinth.getHeight();
- final long randomSeed = labyrinth.getRandomSeed();
- stream.writeByte(MAGIC_BYTE_1);
- stream.writeByte(MAGIC_BYTE_2);
- stream.writeByte(VERSION_BYTE);
- stream.writeLong(randomSeed);
- stream.writeInt(width);
- stream.writeInt(height);
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- // We .get() it, because we want to crash hard if it is not available.
- @NonNull final Tile tile = labyrinth.getTileAt(x, y).get();
- final byte bitmask = getBitmaskForTile(tile);
- stream.writeByte(bitmask);
- }
- }
+ final LabyrinthOutputStream stream = new LabyrinthOutputStream();
+ writeHeader(stream);
+ writeLabyrinthData(stream, labyrinth);
return stream.toByteArray();
}
@@ -98,6 +83,13 @@ public class SerializerDeserializer {
return readLabyrinthData(stream);
}
+ private static void writeHeader(@NonNull final LabyrinthOutputStream stream) {
+ stream.writeByte(MAGIC_BYTE_1);
+ stream.writeByte(MAGIC_BYTE_2);
+ stream.writeByte(VERSION_BYTE);
+
+ }
+
private static void checkHeader(@NonNull final LabyrinthInputStream stream) {
final byte magic1 = stream.readByte();
if (magic1 != MAGIC_BYTE_1) {
@@ -113,13 +105,32 @@ public class SerializerDeserializer {
}
}
+ private static void writeLabyrinthData(@NonNull final LabyrinthOutputStream stream, @NonNull final Labyrinth labyrinth) {
+ final long randomSeed = labyrinth.getRandomSeed();
+ final int width = labyrinth.getWidth();
+ final int height = labyrinth.getHeight();
+ stream.writeLong(randomSeed);
+ stream.writeInt(width);
+ stream.writeInt(height);
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ // We .get() it, because we want to crash hard if it is not available.
+ final Tile tile = labyrinth.getTileAt(x, y).get();
+ final byte bitmask = getBitmaskForTile(tile);
+ stream.writeByte(bitmask);
+ }
+ }
+
+ }
+
@NonNull
private static Labyrinth readLabyrinthData(@NonNull final LabyrinthInputStream stream) {
final long randomSeed = stream.readLong();
final int width = stream.readInt();
final int height = stream.readInt();
- @NonNull final Tile[][] tiles = new Tile[width][height];
+ final Tile[][] tiles = new Tile[width][height];
for (int x = 0; x < width; x++) {
tiles[x] = new Tile[height];
}