Some dcumentation improvements and minor refactorings.
This commit is contained in:
parent
185114bcf4
commit
c8619f80e8
4 changed files with 77 additions and 41 deletions
|
@ -16,8 +16,8 @@
|
||||||
<orderEntry type="library" name="Maven: org.jetbrains:annotations:19.0.0" level="project" />
|
<orderEntry type="library" name="Maven: org.jetbrains:annotations:19.0.0" level="project" />
|
||||||
<orderEntry type="library" name="Maven: io.vavr:vavr:0.10.2" level="project" />
|
<orderEntry type="library" name="Maven: io.vavr:vavr:0.10.2" level="project" />
|
||||||
<orderEntry type="library" name="Maven: io.vavr:vavr-match:0.10.2" level="project" />
|
<orderEntry type="library" name="Maven: io.vavr:vavr-match:0.10.2" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.apache.pdfbox:pdfbox:2.0.20" level="project" />
|
<orderEntry type="library" name="Maven: org.apache.pdfbox:pdfbox:2.0.25" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.apache.pdfbox:fontbox:2.0.20" level="project" />
|
<orderEntry type="library" name="Maven: org.apache.pdfbox:fontbox:2.0.25" level="project" />
|
||||||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
|
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.6.1" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.6.1" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
|
||||||
|
|
24
pom.xml
24
pom.xml
|
@ -8,9 +8,15 @@
|
||||||
<artifactId>fritteli-build-parent</artifactId>
|
<artifactId>fritteli-build-parent</artifactId>
|
||||||
<version>2.0.4</version>
|
<version>2.0.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>ch.fritteli.labyrinth</groupId>
|
<groupId>ch.fritteli.labyrinth</groupId>
|
||||||
<artifactId>labyrinth-generator</artifactId>
|
<artifactId>labyrinth-generator</artifactId>
|
||||||
<version>0.0.2-SNAPSHOT</version>
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<pdfbox.version>2.0.25</pdfbox.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
@ -27,7 +33,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.pdfbox</groupId>
|
<groupId>org.apache.pdfbox</groupId>
|
||||||
<artifactId>pdfbox</artifactId>
|
<artifactId>pdfbox</artifactId>
|
||||||
<version>2.0.20</version>
|
<version>${pdfbox.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
@ -81,12 +87,24 @@
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>repo.gittr.ch</id>
|
<id>repo.gittr.ch.releases</id>
|
||||||
<url>https://repo.gittr.ch/</url>
|
<url>https://repo.gittr.ch/releases/</url>
|
||||||
<releases>
|
<releases>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
<updatePolicy>never</updatePolicy>
|
<updatePolicy>never</updatePolicy>
|
||||||
</releases>
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
<updatePolicy>never</updatePolicy>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>repo.gittr.ch.snapshots</id>
|
||||||
|
<url>https://repo.gittr.ch/snapshots/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
<updatePolicy>never</updatePolicy>
|
||||||
|
</releases>
|
||||||
<snapshots>
|
<snapshots>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
<updatePolicy>always</updatePolicy>
|
<updatePolicy>always</updatePolicy>
|
||||||
|
|
|
@ -15,6 +15,13 @@ class Generator {
|
||||||
private final boolean renderSolution;
|
private final boolean renderSolution;
|
||||||
private int x = 0;
|
private int x = 0;
|
||||||
private int y = 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;
|
private int line = 0;
|
||||||
|
|
||||||
boolean hasNext() {
|
boolean hasNext() {
|
||||||
|
|
|
@ -12,23 +12,23 @@ import java.util.EnumSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* decimal hex border
|
* decimal hex bin border
|
||||||
* 0 0 no border
|
* 0 0 0000 no border
|
||||||
* 1 1 top
|
* 1 1 0001 top
|
||||||
* 2 2 right
|
* 2 2 0010 right
|
||||||
* 3 3 top+right
|
* 3 3 0011 top+right
|
||||||
* 4 4 bottom
|
* 4 4 0100 bottom
|
||||||
* 5 5 top+bottom
|
* 5 5 0101 top+bottom
|
||||||
* 6 6 right+bottom
|
* 6 6 0110 right+bottom
|
||||||
* 7 7 top+right+bottom
|
* 7 7 0111 top+right+bottom
|
||||||
* 8 8 left
|
* 8 8 1000 left
|
||||||
* 9 9 top+left
|
* 9 9 1001 top+left
|
||||||
* 10 a right+left
|
* 10 a 1010 right+left
|
||||||
* 11 b top+right+left
|
* 11 b 1011 top+right+left
|
||||||
* 12 c bottom+left
|
* 12 c 1100 bottom+left
|
||||||
* 13 d top+bottom+left
|
* 13 d 1101 top+bottom+left
|
||||||
* 14 e right+bottom+left
|
* 14 e 1110 right+bottom+left
|
||||||
* 15 f top+right+bottom+left
|
* 15 f 1111 top+right+bottom+left
|
||||||
* </pre>
|
* </pre>
|
||||||
* ==> bits 0..2: always 0; bit 3: 1=solution, 0=not solution; bits 4..7: encode walls
|
* ==> bits 0..2: always 0; bit 3: 1=solution, 0=not solution; bits 4..7: encode walls
|
||||||
* ==> first bytes are:
|
* ==> first bytes are:
|
||||||
|
@ -64,24 +64,9 @@ public class SerializerDeserializer {
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public byte[] serialize(@NonNull final Labyrinth labyrinth) {
|
public byte[] serialize(@NonNull final Labyrinth labyrinth) {
|
||||||
@NonNull final LabyrinthOutputStream stream = new LabyrinthOutputStream();
|
final LabyrinthOutputStream stream = new LabyrinthOutputStream();
|
||||||
final int width = labyrinth.getWidth();
|
writeHeader(stream);
|
||||||
final int height = labyrinth.getHeight();
|
writeLabyrinthData(stream, labyrinth);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return stream.toByteArray();
|
return stream.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +83,13 @@ public class SerializerDeserializer {
|
||||||
return readLabyrinthData(stream);
|
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) {
|
private static void checkHeader(@NonNull final LabyrinthInputStream stream) {
|
||||||
final byte magic1 = stream.readByte();
|
final byte magic1 = stream.readByte();
|
||||||
if (magic1 != MAGIC_BYTE_1) {
|
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
|
@NonNull
|
||||||
private static Labyrinth readLabyrinthData(@NonNull final LabyrinthInputStream stream) {
|
private static Labyrinth readLabyrinthData(@NonNull final LabyrinthInputStream stream) {
|
||||||
final long randomSeed = stream.readLong();
|
final long randomSeed = stream.readLong();
|
||||||
final int width = stream.readInt();
|
final int width = stream.readInt();
|
||||||
final int height = 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++) {
|
for (int x = 0; x < width; x++) {
|
||||||
tiles[x] = new Tile[height];
|
tiles[x] = new Tile[height];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue