Rename all "labyrinth" to "maze" and configure the Sonatype maven repo.

This commit is contained in:
Manuel Friedli 2023-05-16 02:15:02 +02:00
parent cb1c016cc7
commit fcb87e13a5
Signed by: manuel
GPG key ID: 41D08ABA75634DA1
42 changed files with 510 additions and 483 deletions

View file

@ -1,2 +1 @@
# labyrinth-generator # maze-generator

8
maze-generator.iml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/jsonschema2pojo" isTestSource="false" generated="true" />
</content>
</component>
</module>

177
pom.xml
View file

@ -1,31 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>ch.fritteli</groupId> <groupId>ch.fritteli</groupId>
<artifactId>fritteli-build-parent</artifactId> <artifactId>fritteli-build-parent</artifactId>
<version>2.0.4</version> <version>5.0.0</version>
</parent> </parent>
<groupId>ch.fritteli.labyrinth</groupId> <groupId>ch.fritteli.a-maze-r</groupId>
<artifactId>labyrinth-generator</artifactId> <artifactId>maze-generator</artifactId>
<version>0.0.9-SNAPSHOT</version> <version>0.0.9-SNAPSHOT</version>
<description>The Labyrinth generator, a library for generating Labyrinths in various output formats.</description>
<url>https://manuel.friedli.info/labyrinth.html</url>
<properties> <description>A-Maze-R, The Maze Generator. It is a library for generating mazes in various output formats.
<jackson.version>2.14.2</jackson.version> </description>
<java.source.version>17</java.source.version> <url>https://manuel.friedli.info/maze.html</url>
<java.target.version>17</java.target.version> <inceptionYear>2022</inceptionYear>
<jetbrains-annotations.version>24.0.1</jetbrains-annotations.version>
<junit-jupiter.version>5.9.2</junit-jupiter.version> <licenses>
<logback.version>1.4.6</logback.version> <license>
<lombok.version>1.18.26</lombok.version> <name>GNU Affero General Public License</name>
<pdfbox.version>2.0.27</pdfbox.version> <url>https://www.gnu.org/licenses/agpl-3.0.html</url>
<slf4j.version>2.0.7</slf4j.version> </license>
<vavr.version>0.10.4</vavr.version> </licenses>
</properties>
<developers> <developers>
<developer> <developer>
@ -42,6 +40,29 @@
</developer> </developer>
</developers> </developers>
<scm>
<connection>scm:git:https://gittr.ch/java/maze-generator.git</connection>
<developerConnection>scm:git:ssh://git@gittr.ch/java/maze-generator.git</developerConnection>
<url>https://gittr.ch/java/maze-generator</url>
<tag>HEAD</tag>
</scm>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<name>Sonatype Maven Repository - Snapshots</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<properties>
<jackson.version>2.15.0</jackson.version>
<jsonschema2pojo-maven-plugin.version>1.2.1</jsonschema2pojo-maven-plugin.version>
<maven-site-plugin.version>4.0.0-M8</maven-site-plugin.version>
<pdfbox.version>2.0.28</pdfbox.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
@ -91,12 +112,13 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.jsonschema2pojo</groupId> <groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId> <artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.2.1</version> <version>${jsonschema2pojo-maven-plugin.version}</version>
<executions> <executions>
<execution> <execution>
<phase>generate-sources</phase> <phase>generate-sources</phase>
@ -105,34 +127,12 @@
</goals> </goals>
<configuration> <configuration>
<sourcePaths> <sourcePaths>
<sourcePath>src/main/resources/labyrinth.schema.json</sourcePath> <sourcePath>src/main/resources/maze.schema.json</sourcePath>
</sourcePaths> </sourcePaths>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>ch.fritteli.labyrinth.generator.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
@ -149,52 +149,55 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId> <artifactId>maven-site-plugin</artifactId>
<version>4.0.0-M6</version> <version>${maven-site-plugin.version}</version>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<scm>
<connection>scm:git:https://gittr.ch/java/labyrinth-generator.git</connection> <profiles>
<developerConnection>scm:git:ssh://git@gittr.ch/java/labyrinth-generator.git</developerConnection> <profile>
<url>https://gittr.ch/java/labyrinth-generator</url> <id>release</id>
<tag>HEAD</tag> <build>
</scm> <plugins>
<distributionManagement> <plugin>
<repository> <groupId>org.apache.maven.plugins</groupId>
<id>repo.gittr.ch</id> <artifactId>maven-source-plugin</artifactId>
<name>gittr.ch</name> <executions>
<url>https://repo.gittr.ch/releases/</url> <execution>
</repository> <id>attach-sources</id>
<snapshotRepository> <goals>
<id>repo.gittr.ch</id> <goal>jar-no-fork</goal>
<name>gittr.ch</name> </goals>
<url>https://repo.gittr.ch/snapshots/</url> </execution>
</snapshotRepository> </executions>
</distributionManagement> </plugin>
<repositories> <plugin>
<repository> <groupId>org.apache.maven.plugins</groupId>
<id>repo.gittr.ch.releases</id> <artifactId>maven-javadoc-plugin</artifactId>
<url>https://repo.gittr.ch/releases/</url> <executions>
<releases> <execution>
<enabled>true</enabled> <id>attach-javadocs</id>
<updatePolicy>never</updatePolicy> <goals>
</releases> <goal>jar</goal>
<snapshots> </goals>
<enabled>false</enabled> </execution>
<updatePolicy>never</updatePolicy> </executions>
</snapshots> </plugin>
</repository> <plugin>
<repository> <groupId>org.apache.maven.plugins</groupId>
<id>repo.gittr.ch.snapshots</id> <artifactId>maven-gpg-plugin</artifactId>
<url>https://repo.gittr.ch/snapshots/</url> <executions>
<releases> <execution>
<enabled>false</enabled> <id>sign-artifacts</id>
<updatePolicy>never</updatePolicy> <phase>verify</phase>
</releases> <goals>
<snapshots> <goal>sign</goal>
<enabled>true</enabled> </goals>
<updatePolicy>always</updatePolicy> </execution>
</snapshots> </executions>
</repository> </plugin>
</repositories> </plugins>
</build>
</profile>
</profiles>
</project> </project>

View file

@ -1,9 +0,0 @@
package ch.fritteli.labyrinth.generator.renderer;
import ch.fritteli.labyrinth.generator.model.Labyrinth;
import lombok.NonNull;
public interface Renderer<T> {
@NonNull
T render(@NonNull final Labyrinth labyrinth);
}

View file

@ -1,13 +1,14 @@
package ch.fritteli.labyrinth.generator; package ch.fritteli.maze.generator;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.algorithm.RandomDepthFirst;
import ch.fritteli.labyrinth.generator.renderer.html.HTMLRenderer; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.renderer.htmlfile.HTMLFileRenderer; import ch.fritteli.maze.generator.renderer.html.HTMLRenderer;
import ch.fritteli.labyrinth.generator.renderer.json.JsonRenderer; import ch.fritteli.maze.generator.renderer.htmlfile.HTMLFileRenderer;
import ch.fritteli.labyrinth.generator.renderer.jsonfile.JsonFileRenderer; import ch.fritteli.maze.generator.renderer.json.JsonRenderer;
import ch.fritteli.labyrinth.generator.renderer.pdffile.PDFFileRenderer; import ch.fritteli.maze.generator.renderer.jsonfile.JsonFileRenderer;
import ch.fritteli.labyrinth.generator.renderer.text.TextRenderer; import ch.fritteli.maze.generator.renderer.pdffile.PDFFileRenderer;
import ch.fritteli.labyrinth.generator.renderer.textfile.TextFileRenderer; import ch.fritteli.maze.generator.renderer.text.TextRenderer;
import ch.fritteli.maze.generator.renderer.textfile.TextFileRenderer;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import lombok.NonNull; import lombok.NonNull;
@ -21,15 +22,15 @@ public class Main {
public static void main(@NonNull final String[] args) { public static void main(@NonNull final String[] args) {
final int width = 20; final int width = 20;
final int height = 30; final int height = 30;
final Labyrinth labyrinth = new Labyrinth(width, height/*, 0*/); final Maze maze = new Maze(width, height/*, 0*/);
new Generator(labyrinth).run(); new RandomDepthFirst(maze).run();
final TextRenderer textRenderer = TextRenderer.newInstance(); final TextRenderer textRenderer = TextRenderer.newInstance();
final HTMLRenderer htmlRenderer = HTMLRenderer.newInstance(); final HTMLRenderer htmlRenderer = HTMLRenderer.newInstance();
final JsonRenderer jsonRenderer = JsonRenderer.newInstance(); final JsonRenderer jsonRenderer = JsonRenderer.newInstance();
final Path userHome = Paths.get(System.getProperty("user.home")); final Path userHome = Paths.get(System.getProperty("user.home"));
final String baseFilename = getBaseFilename(labyrinth); final String baseFilename = getBaseFilename(maze);
final TextFileRenderer textFileRenderer = TextFileRenderer.newInstance() final TextFileRenderer textFileRenderer = TextFileRenderer.newInstance()
.setTargetLabyrinthFile(userHome.resolve(baseFilename + ".txt")) .setTargetMazeFile(userHome.resolve(baseFilename + ".txt"))
.setTargetSolutionFile(userHome.resolve(baseFilename + "-solution.txt")); .setTargetSolutionFile(userHome.resolve(baseFilename + "-solution.txt"));
final HTMLFileRenderer htmlFileRenderer = HTMLFileRenderer.newInstance() final HTMLFileRenderer htmlFileRenderer = HTMLFileRenderer.newInstance()
.setTargetFile(userHome.resolve(baseFilename + ".html")); .setTargetFile(userHome.resolve(baseFilename + ".html"));
@ -38,26 +39,26 @@ public class Main {
final PDFFileRenderer pdfFileRenderer = PDFFileRenderer.newInstance() final PDFFileRenderer pdfFileRenderer = PDFFileRenderer.newInstance()
.setTargetFile(userHome.resolve(baseFilename + ".pdf")); .setTargetFile(userHome.resolve(baseFilename + ".pdf"));
log.info("Labyrinth-ID: {}", labyrinth.getRandomSeed()); log.info("Maze-ID: {}", maze.getRandomSeed());
// Render Labyrinth to stdout // Render Maze to stdout
log.info("Text rendering:\n{}", textRenderer.render(labyrinth)); log.info("Text rendering:\n{}", textRenderer.render(maze));
// Render Labyrinth solution to stdout // Render Maze solution to stdout
log.info("Text rendering with solution:\n{}", textRenderer.setRenderSolution(true).render(labyrinth)); log.info("Text rendering with solution:\n{}", textRenderer.setRenderSolution(true).render(maze));
// Render HTML to stdout // Render HTML to stdout
log.info("HTML rendering:\n{}", htmlRenderer.render(labyrinth)); log.info("HTML rendering:\n{}", htmlRenderer.render(maze));
// Render JSON to stdout // Render JSON to stdout
log.info("JSON rendering:\n{}", jsonRenderer.render(labyrinth)); log.info("JSON rendering:\n{}", jsonRenderer.render(maze));
// Render Labyrinth and solution to (separate) files // Render Maze and solution to (separate) files
log.info("Text rendering to file:\n{}", textFileRenderer.render(labyrinth)); log.info("Text rendering to file:\n{}", textFileRenderer.render(maze));
// Render HTML to file // Render HTML to file
log.info("HTML rendering to file:\n{}", htmlFileRenderer.render(labyrinth)); log.info("HTML rendering to file:\n{}", htmlFileRenderer.render(maze));
// Render JSON to file // Render JSON to file
log.info("JSON rendering to file:\n{}", jsonFileRenderer.render(labyrinth)); log.info("JSON rendering to file:\n{}", jsonFileRenderer.render(maze));
// Render PDF to file // Render PDF to file
log.info("PDF rendering to file:\n{}", pdfFileRenderer.render(labyrinth)); log.info("PDF rendering to file:\n{}", pdfFileRenderer.render(maze));
} }
private static String getBaseFilename(@NonNull final Labyrinth labyrinth) { private static String getBaseFilename(@NonNull final Maze maze) {
return "labyrinth-" + labyrinth.getWidth() + "x" + labyrinth.getHeight() + "-" + labyrinth.getRandomSeed(); return "maze-" + maze.getWidth() + "x" + maze.getHeight() + "-" + maze.getRandomSeed();
} }
} }

View file

@ -1,27 +1,27 @@
package ch.fritteli.labyrinth.generator; package ch.fritteli.maze.generator.algorithm;
import ch.fritteli.labyrinth.generator.model.Direction; import ch.fritteli.maze.generator.model.Direction;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.model.Position; import ch.fritteli.maze.generator.model.Position;
import ch.fritteli.labyrinth.generator.model.Tile; import ch.fritteli.maze.generator.model.Tile;
import io.vavr.control.Option; import io.vavr.control.Option;
import java.util.Deque; import java.util.Deque;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Random; import java.util.Random;
import lombok.NonNull; import lombok.NonNull;
public class Generator { public class RandomDepthFirst {
@NonNull @NonNull
private final Labyrinth labyrinth; private final Maze maze;
@NonNull @NonNull
private final Random random; private final Random random;
@NonNull @NonNull
private final Deque<Position> positions = new LinkedList<>(); private final Deque<Position> positions = new LinkedList<>();
public Generator(@NonNull final Labyrinth labyrinth) { public RandomDepthFirst(@NonNull final Maze maze) {
this.labyrinth = labyrinth; this.maze = maze;
this.random = new Random(labyrinth.getRandomSeed()); this.random = new Random(maze.getRandomSeed());
} }
public void run() { public void run() {
@ -31,8 +31,8 @@ public class Generator {
} }
private void preDig() { private void preDig() {
final Position end = this.labyrinth.getEnd(); final Position end = this.maze.getEnd();
final Tile endTile = this.labyrinth.getEndTile(); final Tile endTile = this.maze.getEndTile();
if (end.getY() == 0) { if (end.getY() == 0) {
endTile.enableDiggingToOrFrom(Direction.TOP); endTile.enableDiggingToOrFrom(Direction.TOP);
@ -40,10 +40,10 @@ public class Generator {
} else if (end.getX() == 0) { } else if (end.getX() == 0) {
endTile.enableDiggingToOrFrom(Direction.LEFT); endTile.enableDiggingToOrFrom(Direction.LEFT);
endTile.digFrom(Direction.LEFT); endTile.digFrom(Direction.LEFT);
} else if (end.getY() == this.labyrinth.getHeight() - 1) { } else if (end.getY() == this.maze.getHeight() - 1) {
endTile.enableDiggingToOrFrom(Direction.BOTTOM); endTile.enableDiggingToOrFrom(Direction.BOTTOM);
endTile.digFrom(Direction.BOTTOM); endTile.digFrom(Direction.BOTTOM);
} else if (end.getX() == this.labyrinth.getWidth() - 1) { } else if (end.getX() == this.maze.getWidth() - 1) {
endTile.enableDiggingToOrFrom(Direction.RIGHT); endTile.enableDiggingToOrFrom(Direction.RIGHT);
endTile.digFrom(Direction.RIGHT); endTile.digFrom(Direction.RIGHT);
} }
@ -54,17 +54,17 @@ public class Generator {
private void dig() { private void dig() {
while (!this.positions.isEmpty()) { while (!this.positions.isEmpty()) {
final Position currentPosition = this.positions.peek(); final Position currentPosition = this.positions.peek();
final Tile currentTile = this.labyrinth.getTileAt(currentPosition).get(); final Tile currentTile = this.maze.getTileAt(currentPosition).get();
final Option<Direction> directionToDigTo = currentTile.getRandomAvailableDirection(this.random); final Option<Direction> directionToDigTo = currentTile.getRandomAvailableDirection(this.random);
if (directionToDigTo.isDefined()) { if (directionToDigTo.isDefined()) {
final Direction digTo = directionToDigTo.get(); final Direction digTo = directionToDigTo.get();
final Direction digFrom = digTo.invert(); final Direction digFrom = digTo.invert();
final Position neighborPosition = currentPosition.move(digTo); final Position neighborPosition = currentPosition.move(digTo);
final Tile neighborTile = this.labyrinth.getTileAt(neighborPosition).get(); final Tile neighborTile = this.maze.getTileAt(neighborPosition).get();
if (currentTile.digTo(digTo) && neighborTile.digFrom(digFrom)) { if (currentTile.digTo(digTo) && neighborTile.digFrom(digFrom)) {
// all ok! // all ok!
this.positions.push(neighborPosition); this.positions.push(neighborPosition);
if (neighborPosition.equals(this.labyrinth.getStart())) { if (neighborPosition.equals(this.maze.getStart())) {
this.markSolution(); this.markSolution();
} }
} else { } else {
@ -79,12 +79,12 @@ public class Generator {
} }
private void markSolution() { private void markSolution() {
this.positions.forEach(position -> this.labyrinth.getTileAt(position).get().setSolution()); this.positions.forEach(position -> this.maze.getTileAt(position).get().setSolution());
} }
private void postDig() { private void postDig() {
final Position start = this.labyrinth.getStart(); final Position start = this.maze.getStart();
final Tile startTile = this.labyrinth.getStartTile(); final Tile startTile = this.maze.getStartTile();
if (start.getY() == 0) { if (start.getY() == 0) {
startTile.enableDiggingToOrFrom(Direction.TOP); startTile.enableDiggingToOrFrom(Direction.TOP);
@ -92,10 +92,10 @@ public class Generator {
} else if (start.getX() == 0) { } else if (start.getX() == 0) {
startTile.enableDiggingToOrFrom(Direction.LEFT); startTile.enableDiggingToOrFrom(Direction.LEFT);
startTile.digTo(Direction.LEFT); startTile.digTo(Direction.LEFT);
} else if (start.getY() == this.labyrinth.getHeight() - 1) { } else if (start.getY() == this.maze.getHeight() - 1) {
startTile.enableDiggingToOrFrom(Direction.BOTTOM); startTile.enableDiggingToOrFrom(Direction.BOTTOM);
startTile.digTo(Direction.BOTTOM); startTile.digTo(Direction.BOTTOM);
} else if (start.getX() == this.labyrinth.getWidth() - 1) { } else if (start.getX() == this.maze.getWidth() - 1) {
startTile.enableDiggingToOrFrom(Direction.RIGHT); startTile.enableDiggingToOrFrom(Direction.RIGHT);
startTile.digTo(Direction.RIGHT); startTile.digTo(Direction.RIGHT);
} }

View file

@ -1,4 +1,4 @@
package ch.fritteli.labyrinth.generator.model; package ch.fritteli.maze.generator.model;
public enum Direction { public enum Direction {
TOP, TOP,

View file

@ -1,4 +1,4 @@
package ch.fritteli.labyrinth.generator.model; package ch.fritteli.maze.generator.model;
import io.vavr.control.Option; import io.vavr.control.Option;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -8,7 +8,7 @@ import lombok.ToString;
@EqualsAndHashCode @EqualsAndHashCode
@ToString @ToString
public class Labyrinth { public class Maze {
private final Tile[][] field; private final Tile[][] field;
@Getter @Getter
@ -22,19 +22,19 @@ public class Labyrinth {
@Getter @Getter
private final Position end; private final Position end;
public Labyrinth(final int width, final int height) { public Maze(final int width, final int height) {
this(width, height, System.nanoTime()); this(width, height, System.nanoTime());
} }
public Labyrinth(final int width, final int height, @NonNull final Position start, @NonNull final Position end) { public Maze(final int width, final int height, @NonNull final Position start, @NonNull final Position end) {
this(width, height, System.nanoTime(), start, end); this(width, height, System.nanoTime(), start, end);
} }
public Labyrinth(final int width, final int height, final long randomSeed) { public Maze(final int width, final int height, final long randomSeed) {
this(width, height, randomSeed, new Position(0, 0), new Position(width - 1, height - 1)); this(width, height, randomSeed, new Position(0, 0), new Position(width - 1, height - 1));
} }
public Labyrinth(final int width, final int height, final long randomSeed, @NonNull final Position start, @NonNull final Position end) { public Maze(final int width, final int height, final long randomSeed, @NonNull final Position start, @NonNull final Position end) {
if (width <= 1 || height <= 1) { if (width <= 1 || height <= 1) {
throw new IllegalArgumentException("width and height must be >1"); throw new IllegalArgumentException("width and height must be >1");
} }
@ -42,10 +42,10 @@ public class Labyrinth {
throw new IllegalArgumentException("'start' must not be equal to 'end'"); throw new IllegalArgumentException("'start' must not be equal to 'end'");
} }
if (start.getX() != 0 && start.getX() != width - 1 && start.getY() != 0 && start.getY() != height - 1) { if (start.getX() != 0 && start.getX() != width - 1 && start.getY() != 0 && start.getY() != height - 1) {
throw new IllegalArgumentException("'start' must be at the edge of the labyrinth"); throw new IllegalArgumentException("'start' must be at the edge of the maze");
} }
if (end.getX() != 0 && end.getX() != width - 1 && end.getY() != 0 && end.getY() != height - 1) { if (end.getX() != 0 && end.getX() != width - 1 && end.getY() != 0 && end.getY() != height - 1) {
throw new IllegalArgumentException("'end' must be at the edge of the labyrinth"); throw new IllegalArgumentException("'end' must be at the edge of the maze");
} }
this.width = width; this.width = width;
this.height = height; this.height = height;
@ -59,7 +59,7 @@ public class Labyrinth {
/** /**
* INTERNAL API. Exists only for deserialization. Not to be called from user code. * INTERNAL API. Exists only for deserialization. Not to be called from user code.
*/ */
private Labyrinth(@NonNull final Tile[][] field, final int width, final int height, final long randomSeed) { private Maze(@NonNull final Tile[][] field, final int width, final int height, final long randomSeed) {
this.field = field; this.field = field;
this.width = width; this.width = width;
this.height = height; this.height = height;
@ -71,7 +71,7 @@ public class Labyrinth {
/** /**
* INTERNAL API. Exists only for deserialization. Not to be called from user code. * INTERNAL API. Exists only for deserialization. Not to be called from user code.
*/ */
private Labyrinth(@NonNull final Tile[][] field, final int width, final int height, @NonNull final Position start, @NonNull final Position end, final long randomSeed) { private Maze(@NonNull final Tile[][] field, final int width, final int height, @NonNull final Position start, @NonNull final Position end, final long randomSeed) {
this.field = field; this.field = field;
this.width = width; this.width = width;
this.height = height; this.height = height;

View file

@ -1,4 +1,4 @@
package ch.fritteli.labyrinth.generator.model; package ch.fritteli.maze.generator.model;
import lombok.NonNull; import lombok.NonNull;
import lombok.Value; import lombok.Value;

View file

@ -1,4 +1,4 @@
package ch.fritteli.labyrinth.generator.model; package ch.fritteli.maze.generator.model;
import io.vavr.collection.Stream; import io.vavr.collection.Stream;
import io.vavr.control.Option; import io.vavr.control.Option;

View file

@ -1,4 +1,4 @@
package ch.fritteli.labyrinth.generator.model; package ch.fritteli.maze.generator.model;
import io.vavr.collection.Stream; import io.vavr.collection.Stream;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;

View file

@ -0,0 +1,9 @@
package ch.fritteli.maze.generator.renderer;
import ch.fritteli.maze.generator.model.Maze;
import lombok.NonNull;
public interface Renderer<T> {
@NonNull
T render(@NonNull final Maze maze);
}

View file

@ -1,8 +1,8 @@
package ch.fritteli.labyrinth.generator.renderer.html; package ch.fritteli.maze.generator.renderer.html;
import ch.fritteli.labyrinth.generator.model.Direction; import ch.fritteli.maze.generator.model.Direction;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.model.Tile; import ch.fritteli.maze.generator.model.Tile;
import io.vavr.collection.HashSet; import io.vavr.collection.HashSet;
import io.vavr.collection.Set; import io.vavr.collection.Set;
import lombok.AccessLevel; import lombok.AccessLevel;
@ -11,17 +11,17 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) @RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class Generator { class Generator {
private final Labyrinth labyrinth; private final Maze maze;
private int y = 0; private int y = 0;
boolean hasNext() { boolean hasNext() {
return this.y < this.labyrinth.getHeight(); return this.y < this.maze.getHeight();
} }
String next() { String next() {
StringBuilder sb = new StringBuilder("<tr>"); StringBuilder sb = new StringBuilder("<tr>");
for (int x = 0; x < this.labyrinth.getWidth(); x++) { for (int x = 0; x < this.maze.getWidth(); x++) {
final Tile currentTile = this.labyrinth.getTileAt(x, this.y).get(); final Tile currentTile = this.maze.getTileAt(x, this.y).get();
sb.append("<td class=\""); sb.append("<td class=\"");
sb.append(this.getClasses(currentTile).mkString(" ")); sb.append(this.getClasses(currentTile).mkString(" "));
sb.append("\">&nbsp;</td>"); sb.append("\">&nbsp;</td>");

View file

@ -1,7 +1,7 @@
package ch.fritteli.labyrinth.generator.renderer.html; package ch.fritteli.maze.generator.renderer.html;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.renderer.Renderer; import ch.fritteli.maze.generator.renderer.Renderer;
import lombok.NonNull; import lombok.NonNull;
public class HTMLRenderer implements Renderer<String> { public class HTMLRenderer implements Renderer<String> {
@ -119,12 +119,12 @@ public class HTMLRenderer implements Renderer<String> {
@NonNull @NonNull
@Override @Override
public String render(@NonNull final Labyrinth labyrinth) { public String render(@NonNull final Maze maze) {
if (labyrinth.getWidth() == 0 || labyrinth.getHeight() == 0) { if (maze.getWidth() == 0 || maze.getHeight() == 0) {
return this.getPreamble(labyrinth) + POSTAMBLE; return this.getPreamble(maze) + POSTAMBLE;
} }
final Generator generator = new Generator(labyrinth); final Generator generator = new Generator(maze);
final StringBuilder sb = new StringBuilder(this.getPreamble(labyrinth)); final StringBuilder sb = new StringBuilder(this.getPreamble(maze));
sb.append("<table id=\"labyrinth\">"); sb.append("<table id=\"labyrinth\">");
while (generator.hasNext()) { while (generator.hasNext()) {
sb.append(generator.next()); sb.append(generator.next());
@ -134,10 +134,10 @@ public class HTMLRenderer implements Renderer<String> {
return sb.toString(); return sb.toString();
} }
private String getPreamble(@NonNull final Labyrinth labyrinth) { private String getPreamble(@NonNull final Maze maze) {
return "<!DOCTYPE html><html lang=\"en\">" + return "<!DOCTYPE html><html lang=\"en\">" +
"<head>" + "<head>" +
"<title>Labyrinth " + labyrinth.getWidth() + "x" + labyrinth.getHeight() + ", ID " + labyrinth.getRandomSeed() + "</title>" + "<title>Maze " + maze.getWidth() + "x" + maze.getHeight() + ", ID " + maze.getRandomSeed() + "</title>" +
"<meta charset=\"utf-8\">" + "<meta charset=\"utf-8\">" +
"<style>" + "<style>" +
"table{border-collapse:collapse;}" + "table{border-collapse:collapse;}" +

View file

@ -1,8 +1,8 @@
package ch.fritteli.labyrinth.generator.renderer.htmlfile; package ch.fritteli.maze.generator.renderer.htmlfile;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.renderer.Renderer; import ch.fritteli.maze.generator.renderer.Renderer;
import ch.fritteli.labyrinth.generator.renderer.html.HTMLRenderer; import ch.fritteli.maze.generator.renderer.html.HTMLRenderer;
import io.vavr.control.Option; import io.vavr.control.Option;
import io.vavr.control.Try; import io.vavr.control.Try;
import lombok.NonNull; import lombok.NonNull;
@ -24,7 +24,7 @@ public class HTMLFileRenderer implements Renderer<Path> {
private HTMLFileRenderer() { private HTMLFileRenderer() {
this.targetFile = Try this.targetFile = Try
.of(() -> Files.createTempFile("labyrinth_", ".html")) .of(() -> Files.createTempFile("maze_", ".html"))
.onFailure(ex -> log.error("Unable to set default target file.", ex)) .onFailure(ex -> log.error("Unable to set default target file.", ex))
.toOption(); .toOption();
} }
@ -48,7 +48,7 @@ public class HTMLFileRenderer implements Renderer<Path> {
@NonNull @NonNull
@Override @Override
public Path render(@NonNull final Labyrinth labyrinth) { public Path render(@NonNull final Maze maze) {
if (!this.isTargetFileDefinedAndWritable()) { if (!this.isTargetFileDefinedAndWritable()) {
try { try {
Files.createFile(this.targetFile.get()); Files.createFile(this.targetFile.get());
@ -56,7 +56,7 @@ public class HTMLFileRenderer implements Renderer<Path> {
throw new IllegalArgumentException("Cannot write to target file.", e); throw new IllegalArgumentException("Cannot write to target file.", e);
} }
} }
final String html = HTML_RENDERER.render(labyrinth); final String html = HTML_RENDERER.render(maze);
final Path targetFile = this.targetFile.get(); final Path targetFile = this.targetFile.get();
try { try {
Files.writeString(targetFile, html, StandardCharsets.UTF_8); Files.writeString(targetFile, html, StandardCharsets.UTF_8);

View file

@ -1,37 +1,38 @@
package ch.fritteli.labyrinth.generator.renderer.json; package ch.fritteli.maze.generator.renderer.json;
import ch.fritteli.labyrinth.generator.json.JsonCell; import ch.fritteli.maze.generator.json.JsonCell;
import ch.fritteli.labyrinth.generator.json.JsonCoordinates; import ch.fritteli.maze.generator.json.JsonCoordinates;
import ch.fritteli.labyrinth.generator.json.JsonLabyrinth; import ch.fritteli.maze.generator.json.JsonMaze;
import ch.fritteli.labyrinth.generator.model.Direction; import ch.fritteli.maze.generator.model.Direction;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.model.Tile; import ch.fritteli.maze.generator.model.Tile;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) @RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class Generator { class Generator {
@NonNull @NonNull
private final Labyrinth labyrinth; private final Maze maze;
@NonNull @NonNull
JsonLabyrinth generate() { JsonMaze generate() {
final JsonLabyrinth result = new JsonLabyrinth(); final JsonMaze result = new JsonMaze();
result.setId(String.valueOf(this.labyrinth.getRandomSeed())); result.setId(String.valueOf(this.maze.getRandomSeed()));
result.setWidth(this.labyrinth.getWidth()); result.setWidth(this.maze.getWidth());
result.setHeight(this.labyrinth.getHeight()); result.setHeight(this.maze.getHeight());
final List<List<JsonCell>> rows = new ArrayList<>(); final List<List<JsonCell>> rows = new ArrayList<>();
for (int y = 0; y < this.labyrinth.getHeight(); y++) { for (int y = 0; y < this.maze.getHeight(); y++) {
final ArrayList<JsonCell> row = new ArrayList<>(); final ArrayList<JsonCell> row = new ArrayList<>();
for (int x = 0; x < this.labyrinth.getWidth(); x++) { for (int x = 0; x < this.maze.getWidth(); x++) {
// x and y are not effectively final and can therefore not be accessed from within the lambda. Hence, create the string beforehand. // x and y are not effectively final and can therefore not be accessed from within the lambda. Hence, create the string beforehand.
final String exceptionString = "Failed to obtain tile at %dx%d, although labyrinth has dimensoins %dx%d" final String exceptionString = "Failed to obtain tile at %dx%d, although maze has dimensoins %dx%d"
.formatted(x, y, this.labyrinth.getWidth(), this.labyrinth.getHeight()); .formatted(x, y, this.maze.getWidth(), this.maze.getHeight());
final Tile tile = this.labyrinth.getTileAt(x, y) final Tile tile = this.maze.getTileAt(x, y)
.getOrElseThrow(() -> new IllegalStateException(exceptionString)); .getOrElseThrow(() -> new IllegalStateException(exceptionString));
final JsonCell cell = new JsonCell(); final JsonCell cell = new JsonCell();
cell.setTop(tile.hasWallAt(Direction.TOP)); cell.setTop(tile.hasWallAt(Direction.TOP));
@ -45,12 +46,12 @@ class Generator {
} }
result.setGrid(rows); result.setGrid(rows);
final JsonCoordinates start = new JsonCoordinates(); final JsonCoordinates start = new JsonCoordinates();
start.setX(this.labyrinth.getStart().getX()); start.setX(this.maze.getStart().getX());
start.setY(this.labyrinth.getStart().getY()); start.setY(this.maze.getStart().getY());
result.setStart(start); result.setStart(start);
final JsonCoordinates end = new JsonCoordinates(); final JsonCoordinates end = new JsonCoordinates();
end.setX(this.labyrinth.getEnd().getX()); end.setX(this.maze.getEnd().getX());
end.setY(this.labyrinth.getEnd().getY()); end.setY(this.maze.getEnd().getY());
result.setEnd(end); result.setEnd(end);
return result; return result;
} }

View file

@ -1,15 +1,16 @@
package ch.fritteli.labyrinth.generator.renderer.json; package ch.fritteli.maze.generator.renderer.json;
import ch.fritteli.labyrinth.generator.json.JsonCell; import ch.fritteli.maze.generator.json.JsonCell;
import ch.fritteli.labyrinth.generator.json.JsonLabyrinth; import ch.fritteli.maze.generator.json.JsonMaze;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.renderer.Renderer; import ch.fritteli.maze.generator.renderer.Renderer;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.NonNull;
public class JsonRenderer implements Renderer<String> { public class JsonRenderer implements Renderer<String> {
@ -27,7 +28,7 @@ public class JsonRenderer implements Renderer<String> {
} }
@NonNull @NonNull
private static JsonLabyrinth createSingleCellLabyrinth() { private static JsonMaze createSingleCellMaze() {
// This is the only cell. // This is the only cell.
final JsonCell cell = new JsonCell(); final JsonCell cell = new JsonCell();
cell.setRight(true); cell.setRight(true);
@ -37,17 +38,17 @@ public class JsonRenderer implements Renderer<String> {
final List<List<JsonCell>> rows = new ArrayList<>(); final List<List<JsonCell>> rows = new ArrayList<>();
rows.add(new ArrayList<>()); rows.add(new ArrayList<>());
rows.get(0).add(cell); rows.get(0).add(cell);
// Wrap it all in an instance of JsonLabyrinth. // Wrap it all in an instance of JsonMaze.
final JsonLabyrinth jsonLabyrinth = new JsonLabyrinth(); final JsonMaze jsonMaze = new JsonMaze();
jsonLabyrinth.setId("0"); jsonMaze.setId("0");
jsonLabyrinth.setGrid(rows); jsonMaze.setGrid(rows);
return jsonLabyrinth; return jsonMaze;
} }
@NonNull @NonNull
private String toString(@NonNull final JsonLabyrinth jsonLabyrinth) { private String toString(@NonNull final JsonMaze jsonMaze) {
try { try {
return this.objectMapper.writeValueAsString(jsonLabyrinth); return this.objectMapper.writeValueAsString(jsonMaze);
} catch (final JsonProcessingException e) { } catch (final JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -55,14 +56,14 @@ public class JsonRenderer implements Renderer<String> {
@NonNull @NonNull
@Override @Override
public String render(@NonNull final Labyrinth labyrinth) { public String render(@NonNull final Maze maze) {
final JsonLabyrinth jsonLabyrinth; final JsonMaze jsonMaze;
if (labyrinth.getWidth() == 0 || labyrinth.getHeight() == 0) { if (maze.getWidth() == 0 || maze.getHeight() == 0) {
jsonLabyrinth = createSingleCellLabyrinth(); jsonMaze = createSingleCellMaze();
} else { } else {
final Generator generator = new Generator(labyrinth); final Generator generator = new Generator(maze);
jsonLabyrinth = generator.generate(); jsonMaze = generator.generate();
} }
return toString(jsonLabyrinth); return toString(jsonMaze);
} }
} }

View file

@ -1,8 +1,8 @@
package ch.fritteli.labyrinth.generator.renderer.jsonfile; package ch.fritteli.maze.generator.renderer.jsonfile;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.renderer.Renderer; import ch.fritteli.maze.generator.renderer.Renderer;
import ch.fritteli.labyrinth.generator.renderer.json.JsonRenderer; import ch.fritteli.maze.generator.renderer.json.JsonRenderer;
import io.vavr.control.Option; import io.vavr.control.Option;
import io.vavr.control.Try; import io.vavr.control.Try;
import java.io.File; import java.io.File;
@ -24,7 +24,7 @@ public class JsonFileRenderer implements Renderer<Path> {
private JsonFileRenderer() { private JsonFileRenderer() {
this.targetFile = Try this.targetFile = Try
.of(() -> Files.createTempFile("labyrinth_", ".json")) .of(() -> Files.createTempFile("maze_", ".json"))
.onFailure(ex -> log.error("Unable to set default target file.", ex)) .onFailure(ex -> log.error("Unable to set default target file.", ex))
.toOption(); .toOption();
} }
@ -48,7 +48,7 @@ public class JsonFileRenderer implements Renderer<Path> {
@NonNull @NonNull
@Override @Override
public Path render(@NonNull final Labyrinth labyrinth) { public Path render(@NonNull final Maze maze) {
if (!this.isTargetFileDefinedAndWritable()) { if (!this.isTargetFileDefinedAndWritable()) {
try { try {
Files.createFile(this.targetFile.get()); Files.createFile(this.targetFile.get());
@ -56,7 +56,7 @@ public class JsonFileRenderer implements Renderer<Path> {
throw new IllegalArgumentException("Cannot write to target file.", e); throw new IllegalArgumentException("Cannot write to target file.", e);
} }
} }
final String json = JSON_RENDERER.render(labyrinth); final String json = JSON_RENDERER.render(maze);
final Path outputFile = this.targetFile.get(); final Path outputFile = this.targetFile.get();
try { try {
Files.writeString(outputFile, json, StandardCharsets.UTF_8); Files.writeString(outputFile, json, StandardCharsets.UTF_8);

View file

@ -1,9 +1,9 @@
package ch.fritteli.labyrinth.generator.renderer.pdf; package ch.fritteli.maze.generator.renderer.pdf;
import ch.fritteli.labyrinth.generator.model.Direction; import ch.fritteli.maze.generator.model.Direction;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.model.Position; import ch.fritteli.maze.generator.model.Position;
import ch.fritteli.labyrinth.generator.model.Tile; import ch.fritteli.maze.generator.model.Tile;
import io.vavr.control.Option; import io.vavr.control.Option;
import java.awt.BasicStroke; import java.awt.BasicStroke;
import java.awt.Color; import java.awt.Color;
@ -25,16 +25,16 @@ import org.jetbrains.annotations.Nullable;
class Generator { class Generator {
@NonNull @NonNull
private final Labyrinth labyrinth; private final Maze maze;
@NonNull @NonNull
public ByteArrayOutputStream generate() { public ByteArrayOutputStream generate() {
final float pageWidth = this.labyrinth.getWidth() * PDFRenderer.SCALE + 2 * PDFRenderer.MARGIN; final float pageWidth = this.maze.getWidth() * PDFRenderer.SCALE + 2 * PDFRenderer.MARGIN;
final float pageHeight = this.labyrinth.getHeight() * PDFRenderer.SCALE + 2 * PDFRenderer.MARGIN; final float pageHeight = this.maze.getHeight() * PDFRenderer.SCALE + 2 * PDFRenderer.MARGIN;
final PDDocument pdDocument = new PDDocument(); final PDDocument pdDocument = new PDDocument();
final PDDocumentInformation info = new PDDocumentInformation(); final PDDocumentInformation info = new PDDocumentInformation();
info.setTitle("Labyrinth %sx%s, ID %s".formatted(this.labyrinth.getWidth(), this.labyrinth.getHeight(), this.labyrinth.getRandomSeed())); info.setTitle("Maze %sx%s, ID %s".formatted(this.maze.getWidth(), this.maze.getHeight(), this.maze.getRandomSeed()));
pdDocument.setDocumentInformation(info); pdDocument.setDocumentInformation(info);
final PDPage puzzlePage = new PDPage(new PDRectangle(pageWidth, pageHeight)); final PDPage puzzlePage = new PDPage(new PDRectangle(pageWidth, pageHeight));
final PDPage solutionPage = new PDPage(new PDRectangle(pageWidth, pageHeight)); final PDPage solutionPage = new PDPage(new PDRectangle(pageWidth, pageHeight));
@ -72,11 +72,11 @@ class Generator {
// PDF has the origin in the lower left corner. We want it in the upper left corner, hence some magic is required. // PDF has the origin in the lower left corner. We want it in the upper left corner, hence some magic is required.
Coordinate coordinate = new Coordinate(0f, 0f); Coordinate coordinate = new Coordinate(0f, 0f);
// Draw the TOP borders of all tiles. // Draw the TOP borders of all tiles.
for (int y = 0; y < this.labyrinth.getHeight(); y++) { for (int y = 0; y < this.maze.getHeight(); y++) {
boolean isPainting = false; boolean isPainting = false;
coordinate = coordinate.withY(y); coordinate = coordinate.withY(y);
for (int x = 0; x < this.labyrinth.getWidth(); x++) { for (int x = 0; x < this.maze.getWidth(); x++) {
final Tile currentTile = this.labyrinth.getTileAt(x, y).get(); final Tile currentTile = this.maze.getTileAt(x, y).get();
coordinate = coordinate.withX(x); coordinate = coordinate.withX(x);
if (currentTile.hasWallAt(Direction.TOP)) { if (currentTile.hasWallAt(Direction.TOP)) {
if (!isPainting) { if (!isPainting) {
@ -96,7 +96,7 @@ class Generator {
} }
} }
if (isPainting) { if (isPainting) {
coordinate = coordinate.withX(this.labyrinth.getWidth()); coordinate = coordinate.withX(this.maze.getWidth());
for (final PDPageContentStream contentStream : contentStreams) { for (final PDPageContentStream contentStream : contentStreams) {
contentStream.lineTo(coordinate.getX(), coordinate.getY()); contentStream.lineTo(coordinate.getX(), coordinate.getY());
contentStream.stroke(); contentStream.stroke();
@ -105,10 +105,10 @@ class Generator {
} }
// Draw the BOTTOM border of the last row of tiles. // Draw the BOTTOM border of the last row of tiles.
boolean isPainting = false; boolean isPainting = false;
int y = this.labyrinth.getHeight(); int y = this.maze.getHeight();
coordinate = coordinate.withY(this.labyrinth.getHeight()); coordinate = coordinate.withY(this.maze.getHeight());
for (int x = 0; x < this.labyrinth.getWidth(); x++) { for (int x = 0; x < this.maze.getWidth(); x++) {
final Tile currentTile = this.labyrinth.getTileAt(x, y - 1).get(); final Tile currentTile = this.maze.getTileAt(x, y - 1).get();
coordinate = coordinate.withX(x); coordinate = coordinate.withX(x);
if (currentTile.hasWallAt(Direction.BOTTOM)) { if (currentTile.hasWallAt(Direction.BOTTOM)) {
if (!isPainting) { if (!isPainting) {
@ -128,7 +128,7 @@ class Generator {
} }
} }
if (isPainting) { if (isPainting) {
coordinate = coordinate.withX(this.labyrinth.getWidth()); coordinate = coordinate.withX(this.maze.getWidth());
for (final PDPageContentStream contentStream : contentStreams) { for (final PDPageContentStream contentStream : contentStreams) {
contentStream.lineTo(coordinate.getX(), coordinate.getY()); contentStream.lineTo(coordinate.getX(), coordinate.getY());
contentStream.stroke(); contentStream.stroke();
@ -140,11 +140,11 @@ class Generator {
// PDF has the origin in the lower left corner. We want it in the upper left corner, hence some magic is required. // PDF has the origin in the lower left corner. We want it in the upper left corner, hence some magic is required.
Coordinate coordinate = new Coordinate(0f, 0f); Coordinate coordinate = new Coordinate(0f, 0f);
// Draw the LEFT borders of all tiles. // Draw the LEFT borders of all tiles.
for (int x = 0; x < this.labyrinth.getWidth(); x++) { for (int x = 0; x < this.maze.getWidth(); x++) {
boolean isPainting = false; boolean isPainting = false;
coordinate = coordinate.withX(x); coordinate = coordinate.withX(x);
for (int y = 0; y < this.labyrinth.getHeight(); y++) { for (int y = 0; y < this.maze.getHeight(); y++) {
final Tile currentTile = this.labyrinth.getTileAt(x, y).get(); final Tile currentTile = this.maze.getTileAt(x, y).get();
coordinate = coordinate.withY(y); coordinate = coordinate.withY(y);
if (currentTile.hasWallAt(Direction.LEFT)) { if (currentTile.hasWallAt(Direction.LEFT)) {
if (!isPainting) { if (!isPainting) {
@ -164,7 +164,7 @@ class Generator {
} }
} }
if (isPainting) { if (isPainting) {
coordinate = coordinate.withY(this.labyrinth.getHeight()); coordinate = coordinate.withY(this.maze.getHeight());
for (final PDPageContentStream contentStream : contentStreams) { for (final PDPageContentStream contentStream : contentStreams) {
contentStream.lineTo(coordinate.getX(), coordinate.getY()); contentStream.lineTo(coordinate.getX(), coordinate.getY());
contentStream.stroke(); contentStream.stroke();
@ -173,10 +173,10 @@ class Generator {
} }
// Draw the RIGHT border of the last column of tiles. // Draw the RIGHT border of the last column of tiles.
boolean isPainting = false; boolean isPainting = false;
int x = this.labyrinth.getWidth(); int x = this.maze.getWidth();
coordinate = coordinate.withX(this.labyrinth.getWidth()); coordinate = coordinate.withX(this.maze.getWidth());
for (int y = 0; y < this.labyrinth.getHeight(); y++) { for (int y = 0; y < this.maze.getHeight(); y++) {
final Tile currentTile = this.labyrinth.getTileAt(x - 1, y).get(); final Tile currentTile = this.maze.getTileAt(x - 1, y).get();
coordinate = coordinate.withY(y); coordinate = coordinate.withY(y);
if (currentTile.hasWallAt(Direction.RIGHT)) { if (currentTile.hasWallAt(Direction.RIGHT)) {
if (!isPainting) { if (!isPainting) {
@ -196,7 +196,7 @@ class Generator {
} }
} }
if (isPainting) { if (isPainting) {
coordinate = coordinate.withY(this.labyrinth.getHeight()); coordinate = coordinate.withY(this.maze.getHeight());
for (final PDPageContentStream contentStream : contentStreams) { for (final PDPageContentStream contentStream : contentStreams) {
contentStream.lineTo(coordinate.getX(), coordinate.getY()); contentStream.lineTo(coordinate.getX(), coordinate.getY());
contentStream.stroke(); contentStream.stroke();
@ -208,8 +208,8 @@ class Generator {
// Draw the solution in red // Draw the solution in red
pageContentStream.setStrokingColor(Color.RED); pageContentStream.setStrokingColor(Color.RED);
// PDF has the origin in the lower left corner. We want it in the upper left corner, hence some magic is required. // PDF has the origin in the lower left corner. We want it in the upper left corner, hence some magic is required.
final Position end = this.labyrinth.getEnd(); final Position end = this.maze.getEnd();
Position currentPosition = this.labyrinth.getStart(); Position currentPosition = this.maze.getStart();
Position previousPosition = null; Position previousPosition = null;
SolutionCoordinate coordinate = new SolutionCoordinate(currentPosition.getX(), currentPosition.getY()); SolutionCoordinate coordinate = new SolutionCoordinate(currentPosition.getX(), currentPosition.getY());
pageContentStream.moveTo(coordinate.getX(), coordinate.getY()); pageContentStream.moveTo(coordinate.getX(), coordinate.getY());
@ -225,11 +225,11 @@ class Generator {
@NonNull @NonNull
private Position findNextSolutionPosition(@Nullable final Position previousPosition, @NonNull final Position currentPosition) { private Position findNextSolutionPosition(@Nullable final Position previousPosition, @NonNull final Position currentPosition) {
final Tile currentTile = this.labyrinth.getTileAt(currentPosition).get(); final Tile currentTile = this.maze.getTileAt(currentPosition).get();
for (final Direction direction : Direction.values()) { for (final Direction direction : Direction.values()) {
if (!currentTile.hasWallAt(direction)) { if (!currentTile.hasWallAt(direction)) {
final Position position = currentPosition.move(direction); final Position position = currentPosition.move(direction);
final Option<Tile> tileAtPosition = this.labyrinth.getTileAt(position); final Option<Tile> tileAtPosition = this.maze.getTileAt(position);
if (position.equals(previousPosition)) { if (position.equals(previousPosition)) {
continue; continue;
} }
@ -265,7 +265,7 @@ class Generator {
} }
private float calcY(final int y) { private float calcY(final int y) {
return (Generator.this.labyrinth.getHeight() - y) * PDFRenderer.SCALE + PDFRenderer.MARGIN; return (Generator.this.maze.getHeight() - y) * PDFRenderer.SCALE + PDFRenderer.MARGIN;
} }
} }
@ -285,7 +285,7 @@ class Generator {
} }
private float calcY(final int y) { private float calcY(final int y) {
return (Generator.this.labyrinth.getHeight() - y) * PDFRenderer.SCALE - PDFRenderer.SCALE / 2 + PDFRenderer.MARGIN; return (Generator.this.maze.getHeight() - y) * PDFRenderer.SCALE - PDFRenderer.SCALE / 2 + PDFRenderer.MARGIN;
} }
} }
} }

View file

@ -1,8 +1,9 @@
package ch.fritteli.labyrinth.generator.renderer.pdf; package ch.fritteli.maze.generator.renderer.pdf;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.renderer.Renderer; import ch.fritteli.maze.generator.renderer.Renderer;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import lombok.NonNull; import lombok.NonNull;
public class PDFRenderer implements Renderer<ByteArrayOutputStream> { public class PDFRenderer implements Renderer<ByteArrayOutputStream> {
@ -19,8 +20,8 @@ public class PDFRenderer implements Renderer<ByteArrayOutputStream> {
@NonNull @NonNull
@Override @Override
public ByteArrayOutputStream render(@NonNull final Labyrinth labyrinth) { public ByteArrayOutputStream render(@NonNull final Maze maze) {
final Generator generator = new Generator(labyrinth); final Generator generator = new Generator(maze);
return generator.generate(); return generator.generate();
} }
} }

View file

@ -1,8 +1,8 @@
package ch.fritteli.labyrinth.generator.renderer.pdffile; package ch.fritteli.maze.generator.renderer.pdffile;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.renderer.Renderer; import ch.fritteli.maze.generator.renderer.Renderer;
import ch.fritteli.labyrinth.generator.renderer.pdf.PDFRenderer; import ch.fritteli.maze.generator.renderer.pdf.PDFRenderer;
import io.vavr.control.Option; import io.vavr.control.Option;
import io.vavr.control.Try; import io.vavr.control.Try;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -24,7 +24,7 @@ public class PDFFileRenderer implements Renderer<Path> {
private PDFFileRenderer() { private PDFFileRenderer() {
this.targetFile = Try this.targetFile = Try
.of(() -> Files.createTempFile("labyrinth_", ".pdf")) .of(() -> Files.createTempFile("maze_", ".pdf"))
.onFailure(ex -> log.error("Unable to set default target file.", ex)) .onFailure(ex -> log.error("Unable to set default target file.", ex))
.toOption(); .toOption();
} }
@ -48,7 +48,7 @@ public class PDFFileRenderer implements Renderer<Path> {
@NonNull @NonNull
@Override @Override
public Path render(@NonNull final Labyrinth labyrinth) { public Path render(@NonNull final Maze maze) {
if (!this.isTargetFileDefinedAndWritable()) { if (!this.isTargetFileDefinedAndWritable()) {
try { try {
Files.createFile(this.targetFile.get()); Files.createFile(this.targetFile.get());
@ -56,7 +56,7 @@ public class PDFFileRenderer implements Renderer<Path> {
throw new IllegalArgumentException("Cannot write to target file.", e); throw new IllegalArgumentException("Cannot write to target file.", e);
} }
} }
final ByteArrayOutputStream bytes = PDF_RENDERER.render(labyrinth); final ByteArrayOutputStream bytes = PDF_RENDERER.render(maze);
final Path outputFile = this.targetFile.get(); final Path outputFile = this.targetFile.get();
try { try {
bytes.writeTo(Files.newOutputStream(outputFile)); bytes.writeTo(Files.newOutputStream(outputFile));

View file

@ -1,4 +1,4 @@
package ch.fritteli.labyrinth.generator.renderer.text; package ch.fritteli.maze.generator.renderer.text;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View file

@ -1,8 +1,8 @@
package ch.fritteli.labyrinth.generator.renderer.text; package ch.fritteli.maze.generator.renderer.text;
import ch.fritteli.labyrinth.generator.model.Direction; import ch.fritteli.maze.generator.model.Direction;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.model.Tile; import ch.fritteli.maze.generator.model.Tile;
import io.vavr.control.Option; import io.vavr.control.Option;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NonNull; import lombok.NonNull;
@ -11,7 +11,7 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) @RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class Generator { class Generator {
@NonNull @NonNull
private final Labyrinth labyrinth; private final Maze maze;
private final boolean renderSolution; private final boolean renderSolution;
private int x = 0; private int x = 0;
private int y = 0; private int y = 0;
@ -25,15 +25,15 @@ class Generator {
private int line = 0; private int line = 0;
boolean hasNext() { boolean hasNext() {
return this.y < this.labyrinth.getHeight(); return this.y < this.maze.getHeight();
} }
String next() { String next() {
final Tile currentTile = this.labyrinth.getTileAt(this.x, this.y).get(); final Tile currentTile = this.maze.getTileAt(this.x, this.y).get();
final Option<Tile> topTile = this.labyrinth.getTileAt(this.x, this.y - 1); final Option<Tile> topTile = this.maze.getTileAt(this.x, this.y - 1);
final Option<Tile> rightTile = this.labyrinth.getTileAt(this.x + 1, this.y); final Option<Tile> rightTile = this.maze.getTileAt(this.x + 1, this.y);
final Option<Tile> bottomTile = this.labyrinth.getTileAt(this.x, this.y + 1); final Option<Tile> bottomTile = this.maze.getTileAt(this.x, this.y + 1);
final Option<Tile> leftTile = this.labyrinth.getTileAt(this.x - 1, this.y); final Option<Tile> leftTile = this.maze.getTileAt(this.x - 1, this.y);
final String s; final String s;
switch (this.line) { switch (this.line) {
case 0: case 0:
@ -56,13 +56,13 @@ class Generator {
private void prepareNextStep() { private void prepareNextStep() {
// do some magic ... // do some magic ...
this.x++; this.x++;
if (this.x == this.labyrinth.getWidth()) { if (this.x == this.maze.getWidth()) {
// Reached the end of the row? // Reached the end of the row?
// On to the next line then! // On to the next line then!
this.x = 0; this.x = 0;
this.line++; this.line++;
} }
if (this.line == 2 && this.y < this.labyrinth.getHeight() - 1) { if (this.line == 2 && this.y < this.maze.getHeight() - 1) {
// Finished rendering the center line, and more rows available? // Finished rendering the center line, and more rows available?
// On to the next row then! // On to the next row then!
this.line = 0; this.line = 0;
@ -106,7 +106,7 @@ class Generator {
charDef3.up(); charDef3.up();
} }
result = charDef1.toString() + charDef2; result = charDef1.toString() + charDef2;
if (this.x == this.labyrinth.getWidth() - 1) { if (this.x == this.maze.getWidth() - 1) {
result += charDef3 + "\n"; result += charDef3 + "\n";
} }
return result; return result;
@ -153,7 +153,7 @@ class Generator {
result = charDef1.toString() + charDef2; result = charDef1.toString() + charDef2;
if (this.x == this.labyrinth.getWidth() - 1) { if (this.x == this.maze.getWidth() - 1) {
result += charDef3 + "\n"; result += charDef3 + "\n";
} }
@ -187,7 +187,7 @@ class Generator {
result = charDef1.toString() + charDef2; result = charDef1.toString() + charDef2;
if (this.x == this.labyrinth.getWidth() - 1) { if (this.x == this.maze.getWidth() - 1) {
result += charDef3; result += charDef3;
} }
return result; return result;

View file

@ -1,7 +1,7 @@
package ch.fritteli.labyrinth.generator.renderer.text; package ch.fritteli.maze.generator.renderer.text;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.renderer.Renderer; import ch.fritteli.maze.generator.renderer.Renderer;
import lombok.NonNull; import lombok.NonNull;
public class TextRenderer implements Renderer<String> { public class TextRenderer implements Renderer<String> {
@ -24,11 +24,11 @@ public class TextRenderer implements Renderer<String> {
@NonNull @NonNull
@Override @Override
public String render(@NonNull final Labyrinth labyrinth) { public String render(@NonNull final Maze maze) {
if (labyrinth.getWidth() == 0 || labyrinth.getHeight() == 0) { if (maze.getWidth() == 0 || maze.getHeight() == 0) {
return ""; return "";
} }
final Generator generator = new Generator(labyrinth, this.renderSolution); final Generator generator = new Generator(maze, this.renderSolution);
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
while (generator.hasNext()) { while (generator.hasNext()) {
sb.append(generator.next()); sb.append(generator.next());

View file

@ -1,8 +1,8 @@
package ch.fritteli.labyrinth.generator.renderer.textfile; package ch.fritteli.maze.generator.renderer.textfile;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.renderer.Renderer; import ch.fritteli.maze.generator.renderer.Renderer;
import ch.fritteli.labyrinth.generator.renderer.text.TextRenderer; import ch.fritteli.maze.generator.renderer.text.TextRenderer;
import io.vavr.collection.List; import io.vavr.collection.List;
import io.vavr.control.Option; import io.vavr.control.Option;
import io.vavr.control.Try; import io.vavr.control.Try;
@ -21,19 +21,19 @@ public class TextFileRenderer implements Renderer<List<Path>> {
@NonNull @NonNull
private static final TextRenderer TEXT_RENDERER = TextRenderer.newInstance(); private static final TextRenderer TEXT_RENDERER = TextRenderer.newInstance();
@NonNull @NonNull
private Option<Path> targetLabyrinthFile; private Option<Path> targetMazeFile;
@NonNull @NonNull
private Option<Path> targetSolutionFile; private Option<Path> targetSolutionFile;
private TextFileRenderer() { private TextFileRenderer() {
this.targetLabyrinthFile = Try this.targetMazeFile = Try
.of(() -> Files.createTempFile("labyrinth_", ".txt")) .of(() -> Files.createTempFile("maze_", ".txt"))
.onFailure(ex -> log.error("Unable to set default target file", ex)) .onFailure(ex -> log.error("Unable to set default target file", ex))
.toOption(); .toOption();
this.targetSolutionFile = this.targetLabyrinthFile.toTry() this.targetSolutionFile = this.targetMazeFile.toTry()
.map(Path::getParent) .map(Path::getParent)
.flatMap(parent -> this.targetLabyrinthFile.toTry() .flatMap(parent -> this.targetMazeFile.toTry()
.map(Path::getFileName) .map(Path::getFileName)
.map(Path::toString) .map(Path::toString)
.map(a -> a.replace(".txt", "-solution.txt")) .map(a -> a.replace(".txt", "-solution.txt"))
@ -47,8 +47,8 @@ public class TextFileRenderer implements Renderer<List<Path>> {
return new TextFileRenderer(); return new TextFileRenderer();
} }
public boolean isTargetLabyrinthFileDefinedAndWritable() { public boolean isTargetMazeFileDefinedAndWritable() {
return this.targetLabyrinthFile return this.targetMazeFile
.map(Path::toFile) .map(Path::toFile)
.exists(File::canWrite); .exists(File::canWrite);
} }
@ -60,8 +60,8 @@ public class TextFileRenderer implements Renderer<List<Path>> {
} }
@NonNull @NonNull
public TextFileRenderer setTargetLabyrinthFile(@NonNull final Path targetLabyrinthFile) { public TextFileRenderer setTargetMazeFile(@NonNull final Path targetMazeFile) {
this.targetLabyrinthFile = Option.of(targetLabyrinthFile); this.targetMazeFile = Option.of(targetMazeFile);
return this; return this;
} }
@ -73,13 +73,13 @@ public class TextFileRenderer implements Renderer<List<Path>> {
@NonNull @NonNull
@Override @Override
public List<Path> render(@NonNull final Labyrinth labyrinth) { public List<Path> render(@NonNull final Maze maze) {
if (!this.isTargetLabyrinthFileDefinedAndWritable()) { if (!this.isTargetMazeFileDefinedAndWritable()) {
try { try {
Files.createFile(this.targetLabyrinthFile.get()); Files.createFile(this.targetMazeFile.get());
} catch (IOException | NoSuchElementException e) { } catch (IOException | NoSuchElementException e) {
log.error("Cannot write to target labyrinth file.", e); log.error("Cannot write to target maze file.", e);
throw new IllegalArgumentException("Cannot write to target labyrinth file.", e); throw new IllegalArgumentException("Cannot write to target maze file.", e);
} }
} }
if (!this.isTargetSolutionFileDefinedAndWritable()) { if (!this.isTargetSolutionFileDefinedAndWritable()) {
@ -92,21 +92,21 @@ public class TextFileRenderer implements Renderer<List<Path>> {
final String text; final String text;
final String solution; final String solution;
synchronized (TEXT_RENDERER) { synchronized (TEXT_RENDERER) {
text = TEXT_RENDERER.setRenderSolution(false).render(labyrinth).strip(); text = TEXT_RENDERER.setRenderSolution(false).render(maze).strip();
solution = TEXT_RENDERER.setRenderSolution(true).render(labyrinth).strip(); solution = TEXT_RENDERER.setRenderSolution(true).render(maze).strip();
} }
final Path targetLabyrinthFile = this.targetLabyrinthFile.get(); final Path targetMazeFile = this.targetMazeFile.get();
final Path targetSolutionFile = this.targetSolutionFile.get(); final Path targetSolutionFile = this.targetSolutionFile.get();
try { try {
Files.write(targetLabyrinthFile, text.getBytes(StandardCharsets.UTF_8)); Files.write(targetMazeFile, text.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) { } catch (IOException e) {
log.error("Failed writing to file " + targetLabyrinthFile.normalize(), e); log.error("Failed writing to file " + targetMazeFile.normalize(), e);
} }
try { try {
Files.write(targetSolutionFile, solution.getBytes(StandardCharsets.UTF_8)); Files.write(targetSolutionFile, solution.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) { } catch (IOException e) {
log.error("Failed writing to file " + targetSolutionFile.normalize()); log.error("Failed writing to file " + targetSolutionFile.normalize());
} }
return List.of(targetLabyrinthFile, targetSolutionFile); return List.of(targetMazeFile, targetSolutionFile);
} }
} }

View file

@ -1,19 +1,19 @@
package ch.fritteli.labyrinth.generator.serialization; package ch.fritteli.maze.generator.serialization;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import lombok.NonNull; import lombok.NonNull;
public abstract class AbstractLabyrinthInputStream extends ByteArrayInputStream { public abstract class AbstractMazeInputStream extends ByteArrayInputStream {
public AbstractLabyrinthInputStream(@NonNull final byte[] buf) { public AbstractMazeInputStream(@NonNull final byte[] buf) {
super(buf); super(buf);
} }
public abstract void checkHeader(); public abstract void checkHeader();
@NonNull @NonNull
public abstract Labyrinth readLabyrinthData(); public abstract Maze readMazeData();
public byte readByte() { public byte readByte() {
final int read = this.read(); final int read = this.read();

View file

@ -1,14 +1,14 @@
package ch.fritteli.labyrinth.generator.serialization; package ch.fritteli.maze.generator.serialization;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import lombok.NonNull; import lombok.NonNull;
public abstract class AbstractLabyrinthOutputStream extends ByteArrayOutputStream { public abstract class AbstractMazeOutputStream extends ByteArrayOutputStream {
public abstract void writeHeader(); public abstract void writeHeader();
public abstract void writeLabyrinthData(@NonNull final Labyrinth labyrinth); public abstract void writeMazeData(@NonNull final Maze maze);
public void writeByte(final byte value) { public void writeByte(final byte value) {
this.write(value); this.write(value);

View file

@ -1,13 +1,13 @@
package ch.fritteli.labyrinth.generator.serialization.v1; package ch.fritteli.maze.generator.serialization.v1;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.model.Tile; import ch.fritteli.maze.generator.model.Tile;
import ch.fritteli.labyrinth.generator.serialization.AbstractLabyrinthInputStream; import ch.fritteli.maze.generator.serialization.AbstractMazeInputStream;
import lombok.NonNull; import lombok.NonNull;
public class LabyrinthInputStreamV1 extends AbstractLabyrinthInputStream { public class MazeInputStreamV1 extends AbstractMazeInputStream {
public LabyrinthInputStreamV1(@NonNull final byte[] buf) { public MazeInputStreamV1(@NonNull final byte[] buf) {
super(buf); super(buf);
} }
@ -15,21 +15,21 @@ public class LabyrinthInputStreamV1 extends AbstractLabyrinthInputStream {
public void checkHeader() { public void checkHeader() {
final byte magic1 = this.readByte(); final byte magic1 = this.readByte();
if (magic1 != SerializerDeserializerV1.MAGIC_BYTE_1) { if (magic1 != SerializerDeserializerV1.MAGIC_BYTE_1) {
throw new IllegalArgumentException("Invalid labyrinth data."); throw new IllegalArgumentException("Invalid maze data.");
} }
final byte magic2 = this.readByte(); final byte magic2 = this.readByte();
if (magic2 != SerializerDeserializerV1.MAGIC_BYTE_2) { if (magic2 != SerializerDeserializerV1.MAGIC_BYTE_2) {
throw new IllegalArgumentException("Invalid labyrinth data."); throw new IllegalArgumentException("Invalid maze data.");
} }
final int version = this.readByte(); final int version = this.readByte();
if (version != SerializerDeserializerV1.VERSION_BYTE) { if (version != SerializerDeserializerV1.VERSION_BYTE) {
throw new IllegalArgumentException("Unknown Labyrinth data version: " + version); throw new IllegalArgumentException("Unknown maze data version: " + version);
} }
} }
@NonNull @NonNull
@Override @Override
public Labyrinth readLabyrinthData() { public Maze readMazeData() {
final long randomSeed = this.readLong(); final long randomSeed = this.readLong();
final int width = this.readInt(); final int width = this.readInt();
final int height = this.readInt(); final int height = this.readInt();
@ -46,6 +46,6 @@ public class LabyrinthInputStreamV1 extends AbstractLabyrinthInputStream {
} }
} }
return SerializerDeserializerV1.createLabyrinth(tiles, width, height, randomSeed); return SerializerDeserializerV1.createMaze(tiles, width, height, randomSeed);
} }
} }

View file

@ -1,11 +1,11 @@
package ch.fritteli.labyrinth.generator.serialization.v1; package ch.fritteli.maze.generator.serialization.v1;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.model.Tile; import ch.fritteli.maze.generator.model.Tile;
import ch.fritteli.labyrinth.generator.serialization.AbstractLabyrinthOutputStream; import ch.fritteli.maze.generator.serialization.AbstractMazeOutputStream;
import lombok.NonNull; import lombok.NonNull;
public class LabyrinthOutputStreamV1 extends AbstractLabyrinthOutputStream { public class MazeOutputStreamV1 extends AbstractMazeOutputStream {
@Override @Override
public void writeHeader() { public void writeHeader() {
@ -15,10 +15,10 @@ public class LabyrinthOutputStreamV1 extends AbstractLabyrinthOutputStream {
} }
@Override @Override
public void writeLabyrinthData(@NonNull final Labyrinth labyrinth) { public void writeMazeData(@NonNull final Maze maze) {
final long randomSeed = labyrinth.getRandomSeed(); final long randomSeed = maze.getRandomSeed();
final int width = labyrinth.getWidth(); final int width = maze.getWidth();
final int height = labyrinth.getHeight(); final int height = maze.getHeight();
this.writeLong(randomSeed); this.writeLong(randomSeed);
this.writeInt(width); this.writeInt(width);
this.writeInt(height); this.writeInt(height);
@ -26,7 +26,7 @@ public class LabyrinthOutputStreamV1 extends AbstractLabyrinthOutputStream {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
// We .get() it, because we want to crash hard if it is not available. // We .get() it, because we want to crash hard if it is not available.
final Tile tile = labyrinth.getTileAt(x, y).get(); final Tile tile = maze.getTileAt(x, y).get();
final byte bitmask = SerializerDeserializerV1.getBitmaskForTile(tile); final byte bitmask = SerializerDeserializerV1.getBitmaskForTile(tile);
this.writeByte(bitmask); this.writeByte(bitmask);
} }

View file

@ -1,8 +1,8 @@
package ch.fritteli.labyrinth.generator.serialization.v1; package ch.fritteli.maze.generator.serialization.v1;
import ch.fritteli.labyrinth.generator.model.Direction; import ch.fritteli.maze.generator.model.Direction;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.model.Tile; import ch.fritteli.maze.generator.model.Tile;
import lombok.NonNull; import lombok.NonNull;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
@ -57,40 +57,41 @@ public class SerializerDeserializerV1 {
private final byte SOLUTION_BIT = 0b0001_0000; private final byte SOLUTION_BIT = 0b0001_0000;
/** /**
* Serializes the {@code labyrinth} into a byte array. * Serializes the {@code maze} into a byte array.
* *
* @param labyrinth The labyrinth to be serialized. * @param maze The {@link Maze} to be serialized.
* @return The resulting byte array. * @return The resulting byte array.
*/ */
@NonNull @NonNull
public byte[] serialize(@NonNull final Labyrinth labyrinth) { public byte[] serialize(@NonNull final Maze maze) {
final LabyrinthOutputStreamV1 stream = new LabyrinthOutputStreamV1(); final MazeOutputStreamV1 stream = new MazeOutputStreamV1();
stream.writeHeader(); stream.writeHeader();
stream.writeLabyrinthData(labyrinth); stream.writeMazeData(maze);
return stream.toByteArray(); return stream.toByteArray();
} }
/** /**
* Deserializes the byte array into an instance of {@link Labyrinth}. * Deserializes the byte array into an instance of {@link Maze}.
* *
* @param bytes The byte array to be deserialized. * @param bytes The byte array to be deserialized.
* @return An instance of {@link Labyrinth}. * @return An instance of {@link Maze}.
*/ */
@NonNull @NonNull
public Labyrinth deserialize(@NonNull final byte[] bytes) { public Maze deserialize(@NonNull final byte[] bytes) {
final LabyrinthInputStreamV1 stream = new LabyrinthInputStreamV1(bytes); final MazeInputStreamV1 stream = new MazeInputStreamV1(bytes);
stream.checkHeader(); stream.checkHeader();
return stream.readLabyrinthData(); return stream.readMazeData();
} }
@NonNull @NonNull
Labyrinth createLabyrinth(@NonNull final Tile[][] field, final int width, final int height, final long randomSeed) { Maze createMaze(@NonNull final Tile[][] field, final int width, final int height, final long randomSeed) {
try { try {
final Constructor<Labyrinth> constructor = Labyrinth.class.getDeclaredConstructor(Tile[][].class, Integer.TYPE, Integer.TYPE, Long.TYPE); final Constructor<Maze> constructor = Maze.class.getDeclaredConstructor(Tile[][].class, Integer.TYPE, Integer.TYPE, Long.TYPE);
constructor.setAccessible(true); constructor.setAccessible(true);
return constructor.newInstance(field, width, height, randomSeed); return constructor.newInstance(field, width, height, randomSeed);
} catch (@NonNull final NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { } catch (@NonNull final NoSuchMethodException | IllegalAccessException | InstantiationException |
throw new RuntimeException("Can not deserialize Labyrinth from labyrinth data.", e); InvocationTargetException e) {
throw new RuntimeException("Can not deserialize Maze from maze data.", e);
} }
} }
@ -100,8 +101,9 @@ public class SerializerDeserializerV1 {
final Constructor<Tile> constructor = Tile.class.getDeclaredConstructor(EnumSet.class, Boolean.TYPE); final Constructor<Tile> constructor = Tile.class.getDeclaredConstructor(EnumSet.class, Boolean.TYPE);
constructor.setAccessible(true); constructor.setAccessible(true);
return constructor.newInstance(walls, solution); return constructor.newInstance(walls, solution);
} catch (@NonNull final NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { } catch (@NonNull final NoSuchMethodException | InstantiationException | IllegalAccessException |
throw new RuntimeException("Can not deserialize Tile from labyrinth data.", e); InvocationTargetException e) {
throw new RuntimeException("Can not deserialize Tile from maze data.", e);
} }
} }

View file

@ -1,14 +1,14 @@
package ch.fritteli.labyrinth.generator.serialization.v2; package ch.fritteli.maze.generator.serialization.v2;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.model.Position; import ch.fritteli.maze.generator.model.Position;
import ch.fritteli.labyrinth.generator.model.Tile; import ch.fritteli.maze.generator.model.Tile;
import ch.fritteli.labyrinth.generator.serialization.AbstractLabyrinthInputStream; import ch.fritteli.maze.generator.serialization.AbstractMazeInputStream;
import lombok.NonNull; import lombok.NonNull;
public class LabyrinthInputStreamV2 extends AbstractLabyrinthInputStream { public class MazeInputStreamV2 extends AbstractMazeInputStream {
public LabyrinthInputStreamV2(@NonNull final byte[] buf) { public MazeInputStreamV2(@NonNull final byte[] buf) {
super(buf); super(buf);
} }
@ -19,21 +19,21 @@ public class LabyrinthInputStreamV2 extends AbstractLabyrinthInputStream {
// 02 0x02 version // 02 0x02 version
final byte magic1 = this.readByte(); final byte magic1 = this.readByte();
if (magic1 != SerializerDeserializerV2.MAGIC_BYTE_1) { if (magic1 != SerializerDeserializerV2.MAGIC_BYTE_1) {
throw new IllegalArgumentException("Invalid labyrinth data."); throw new IllegalArgumentException("Invalid maze data.");
} }
final byte magic2 = this.readByte(); final byte magic2 = this.readByte();
if (magic2 != SerializerDeserializerV2.MAGIC_BYTE_2) { if (magic2 != SerializerDeserializerV2.MAGIC_BYTE_2) {
throw new IllegalArgumentException("Invalid labyrinth data."); throw new IllegalArgumentException("Invalid maze data.");
} }
final int version = this.readByte(); final int version = this.readByte();
if (version != SerializerDeserializerV2.VERSION_BYTE) { if (version != SerializerDeserializerV2.VERSION_BYTE) {
throw new IllegalArgumentException("Unknown Labyrinth data version: " + version); throw new IllegalArgumentException("Unknown maze data version: " + version);
} }
} }
@NonNull @NonNull
@Override @Override
public Labyrinth readLabyrinthData() { public Maze readMazeData() {
// 03..06 width (int) // 03..06 width (int)
// 07..10 height (int) // 07..10 height (int)
// 11..14 start-x (int) // 11..14 start-x (int)
@ -64,6 +64,6 @@ public class LabyrinthInputStreamV2 extends AbstractLabyrinthInputStream {
final Position start = new Position(startX, startY); final Position start = new Position(startX, startY);
final Position end = new Position(endX, endY); final Position end = new Position(endX, endY);
return SerializerDeserializerV2.createLabyrinth(tiles, width, height, start, end, randomSeed); return SerializerDeserializerV2.createMaze(tiles, width, height, start, end, randomSeed);
} }
} }

View file

@ -1,12 +1,12 @@
package ch.fritteli.labyrinth.generator.serialization.v2; package ch.fritteli.maze.generator.serialization.v2;
import ch.fritteli.labyrinth.generator.model.Labyrinth; import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.labyrinth.generator.model.Position; import ch.fritteli.maze.generator.model.Position;
import ch.fritteli.labyrinth.generator.model.Tile; import ch.fritteli.maze.generator.model.Tile;
import ch.fritteli.labyrinth.generator.serialization.AbstractLabyrinthOutputStream; import ch.fritteli.maze.generator.serialization.AbstractMazeOutputStream;
import lombok.NonNull; import lombok.NonNull;
public class LabyrinthOutputStreamV2 extends AbstractLabyrinthOutputStream { public class MazeOutputStreamV2 extends AbstractMazeOutputStream {
@Override @Override
public void writeHeader() { public void writeHeader() {
@ -19,7 +19,7 @@ public class LabyrinthOutputStreamV2 extends AbstractLabyrinthOutputStream {
} }
@Override @Override
public void writeLabyrinthData(@NonNull final Labyrinth labyrinth) { public void writeMazeData(@NonNull final Maze maze) {
// 03..06 width (int) // 03..06 width (int)
// 07..10 height (int) // 07..10 height (int)
// 11..14 start-x (int) // 11..14 start-x (int)
@ -28,11 +28,11 @@ public class LabyrinthOutputStreamV2 extends AbstractLabyrinthOutputStream {
// 23..26 end-y (int) // 23..26 end-y (int)
// 27..34 random seed number (long) // 27..34 random seed number (long)
// 35.. tiles // 35.. tiles
final long randomSeed = labyrinth.getRandomSeed(); final long randomSeed = maze.getRandomSeed();
final int width = labyrinth.getWidth(); final int width = maze.getWidth();
final int height = labyrinth.getHeight(); final int height = maze.getHeight();
final Position start = labyrinth.getStart(); final Position start = maze.getStart();
final Position end = labyrinth.getEnd(); final Position end = maze.getEnd();
this.writeInt(width); this.writeInt(width);
this.writeInt(height); this.writeInt(height);
this.writeInt(start.getX()); this.writeInt(start.getX());
@ -44,7 +44,7 @@ public class LabyrinthOutputStreamV2 extends AbstractLabyrinthOutputStream {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
// We .get() it, because we want to crash hard if it is not available. // We .get() it, because we want to crash hard if it is not available.
final Tile tile = labyrinth.getTileAt(x, y).get(); final Tile tile = maze.getTileAt(x, y).get();
final byte bitmask = SerializerDeserializerV2.getBitmaskForTile(tile); final byte bitmask = SerializerDeserializerV2.getBitmaskForTile(tile);
this.writeByte(bitmask); this.writeByte(bitmask);
} }

View file

@ -1,14 +1,15 @@
package ch.fritteli.labyrinth.generator.serialization.v2; package ch.fritteli.maze.generator.serialization.v2;
import ch.fritteli.maze.generator.model.Direction;
import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.maze.generator.model.Position;
import ch.fritteli.maze.generator.model.Tile;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
import ch.fritteli.labyrinth.generator.model.Direction;
import ch.fritteli.labyrinth.generator.model.Labyrinth;
import ch.fritteli.labyrinth.generator.model.Position;
import ch.fritteli.labyrinth.generator.model.Tile;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.EnumSet; import java.util.EnumSet;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
/** /**
* <pre> * <pre>
@ -61,40 +62,41 @@ public class SerializerDeserializerV2 {
private final byte SOLUTION_BIT = 0b0001_0000; private final byte SOLUTION_BIT = 0b0001_0000;
/** /**
* Serializes the {@code labyrinth} into a byte array. * Serializes the {@code maze} into a byte array.
* *
* @param labyrinth The labyrinth to be serialized. * @param maze The {@link Maze} to be serialized.
* @return The resulting byte array. * @return The resulting byte array.
*/ */
@NonNull @NonNull
public byte[] serialize(@NonNull final Labyrinth labyrinth) { public byte[] serialize(@NonNull final Maze maze) {
final LabyrinthOutputStreamV2 stream = new LabyrinthOutputStreamV2(); final MazeOutputStreamV2 stream = new MazeOutputStreamV2();
stream.writeHeader(); stream.writeHeader();
stream.writeLabyrinthData(labyrinth); stream.writeMazeData(maze);
return stream.toByteArray(); return stream.toByteArray();
} }
/** /**
* Deserializes the byte array into an instance of {@link Labyrinth}. * Deserializes the byte array into an instance of {@link Maze}.
* *
* @param bytes The byte array to be deserialized. * @param bytes The byte array to be deserialized.
* @return An instance of {@link Labyrinth}. * @return An instance of {@link Maze}.
*/ */
@NonNull @NonNull
public Labyrinth deserialize(@NonNull final byte[] bytes) { public Maze deserialize(@NonNull final byte[] bytes) {
final LabyrinthInputStreamV2 stream = new LabyrinthInputStreamV2(bytes); final MazeInputStreamV2 stream = new MazeInputStreamV2(bytes);
stream.checkHeader(); stream.checkHeader();
return stream.readLabyrinthData(); return stream.readMazeData();
} }
@NonNull @NonNull
Labyrinth createLabyrinth(@NonNull final Tile[][] field, final int width, final int height, @NonNull final Position start, @NonNull final Position end, final long randomSeed) { Maze createMaze(@NonNull final Tile[][] field, final int width, final int height, @NonNull final Position start, @NonNull final Position end, final long randomSeed) {
try { try {
final Constructor<Labyrinth> constructor = Labyrinth.class.getDeclaredConstructor(Tile[][].class, Integer.TYPE, Integer.TYPE, Position.class, Position.class, Long.TYPE); final Constructor<Maze> constructor = Maze.class.getDeclaredConstructor(Tile[][].class, Integer.TYPE, Integer.TYPE, Position.class, Position.class, Long.TYPE);
constructor.setAccessible(true); constructor.setAccessible(true);
return constructor.newInstance(field, width, height, start, end, randomSeed); return constructor.newInstance(field, width, height, start, end, randomSeed);
} catch (@NonNull final NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { } catch (@NonNull final NoSuchMethodException | IllegalAccessException | InstantiationException |
throw new RuntimeException("Can not deserialize Labyrinth from labyrinth data.", e); InvocationTargetException e) {
throw new RuntimeException("Can not deserialize Maze from maze data.", e);
} }
} }
@ -104,8 +106,9 @@ public class SerializerDeserializerV2 {
final Constructor<Tile> constructor = Tile.class.getDeclaredConstructor(EnumSet.class, Boolean.TYPE); final Constructor<Tile> constructor = Tile.class.getDeclaredConstructor(EnumSet.class, Boolean.TYPE);
constructor.setAccessible(true); constructor.setAccessible(true);
return constructor.newInstance(walls, solution); return constructor.newInstance(walls, solution);
} catch (@NonNull final NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { } catch (@NonNull final NoSuchMethodException | InstantiationException | IllegalAccessException |
throw new RuntimeException("Can not deserialize Tile from labyrinth data.", e); InvocationTargetException e) {
throw new RuntimeException("Can not deserialize Tile from maze data.", e);
} }
} }

View file

@ -1,7 +1,7 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://manuel.friedli.info/labyrinth-2/labyrinth.schema.json", "$id": "https://manuel.friedli.info/maze/maze.schema.json",
"javaType": "ch.fritteli.labyrinth.generator.json.JsonLabyrinth", "javaType": "ch.fritteli.maze.generator.json.JsonMaze",
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"required": [ "required": [
@ -52,7 +52,7 @@
}, },
"cell": { "cell": {
"type": "object", "type": "object",
"javaType": "ch.fritteli.labyrinth.generator.json.JsonCell", "javaType": "ch.fritteli.maze.generator.json.JsonCell",
"additionalProperties": false, "additionalProperties": false,
"required": [], "required": [],
"properties": { "properties": {
@ -75,7 +75,7 @@
}, },
"coordinates": { "coordinates": {
"type": "object", "type": "object",
"javaType": "ch.fritteli.labyrinth.generator.json.JsonCoordinates", "javaType": "ch.fritteli.maze.generator.json.JsonCoordinates",
"additionalProperties": false, "additionalProperties": false,
"required": [ "required": [
"x", "x",

View file

@ -1,36 +0,0 @@
package ch.fritteli.labyrinth.generator.serialization.v1;
import ch.fritteli.labyrinth.generator.Generator;
import ch.fritteli.labyrinth.generator.model.Labyrinth;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class SerializerDeserializerV1Test {
@Test
void testSerializeDeserializeTiny() {
final Labyrinth expected = new Labyrinth(2, 2, 255);
new Generator(expected).run();
final byte[] bytes = SerializerDeserializerV1.serialize(expected);
final Labyrinth result = SerializerDeserializerV1.deserialize(bytes);
assertThat(result).isEqualTo(expected);
}
@Test
void testSerializeDeserializeMedium() {
final Labyrinth expected = new Labyrinth(20, 20, -271828182846L);
new Generator(expected).run();
final byte[] bytes = SerializerDeserializerV1.serialize(expected);
final Labyrinth result = SerializerDeserializerV1.deserialize(bytes);
assertThat(result).isEqualTo(expected);
}
@Test
void testSerializeDeserializeLarge() {
final Labyrinth expected = new Labyrinth(200, 320, 3141592653589793238L);
new Generator(expected).run();
final byte[] bytes = SerializerDeserializerV1.serialize(expected);
final Labyrinth result = SerializerDeserializerV1.deserialize(bytes);
assertThat(result).isEqualTo(expected);
}
}

View file

@ -1,5 +1,6 @@
package ch.fritteli.labyrinth.generator.model; package ch.fritteli.maze.generator.model;
import ch.fritteli.maze.generator.model.Direction;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

View file

@ -1,29 +1,29 @@
package ch.fritteli.labyrinth.generator.model; package ch.fritteli.maze.generator.model;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
class LabyrinthTest { class MazeTest {
@Test @Test
void testConstruct() { void testConstruct() {
// act / assert on simple cases // act / assert on simple cases
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new Labyrinth(0, 0)) assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new Maze(0, 0))
.withMessage("width and height must be >1"); .withMessage("width and height must be >1");
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new Labyrinth(0, 0, 0)) assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new Maze(0, 0, 0))
.withMessage("width and height must be >1"); .withMessage("width and height must be >1");
// now for the real work: // now for the real work:
// arrange // arrange
final Labyrinth sut = new Labyrinth(2, 3, 5); final Maze sut = new Maze(2, 3, 5);
// assert // assert
assertThat(sut) assertThat(sut)
.returns(2, Labyrinth::getWidth) .returns(2, Maze::getWidth)
.returns(3, Labyrinth::getHeight) .returns(3, Maze::getHeight)
.returns(5L, Labyrinth::getRandomSeed) .returns(5L, Maze::getRandomSeed)
.returns(new Position(0, 0), Labyrinth::getStart) .returns(new Position(0, 0), Maze::getStart)
.returns(new Position(1, 2), Labyrinth::getEnd); .returns(new Position(1, 2), Maze::getEnd);
} }
} }

View file

@ -1,5 +1,7 @@
package ch.fritteli.labyrinth.generator.model; package ch.fritteli.maze.generator.model;
import ch.fritteli.maze.generator.model.Direction;
import ch.fritteli.maze.generator.model.Position;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

View file

@ -1,5 +1,7 @@
package ch.fritteli.labyrinth.generator.model; package ch.fritteli.maze.generator.model;
import ch.fritteli.maze.generator.model.Direction;
import ch.fritteli.maze.generator.model.Tile;
import io.vavr.control.Option; import io.vavr.control.Option;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;

View file

@ -1,5 +1,7 @@
package ch.fritteli.labyrinth.generator.model; package ch.fritteli.maze.generator.model;
import ch.fritteli.maze.generator.model.Direction;
import ch.fritteli.maze.generator.model.Walls;
import io.vavr.collection.Stream; import io.vavr.collection.Stream;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;

View file

@ -1,5 +1,6 @@
package ch.fritteli.labyrinth.generator.renderer.text; package ch.fritteli.maze.generator.renderer.text;
import ch.fritteli.maze.generator.renderer.text.CharDefinition;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

View file

@ -0,0 +1,36 @@
package ch.fritteli.maze.generator.serialization.v1;
import ch.fritteli.maze.generator.algorithm.RandomDepthFirst;
import ch.fritteli.maze.generator.model.Maze;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class SerializerDeserializerV1Test {
@Test
void testSerializeDeserializeTiny() {
final Maze expected = new Maze(2, 2, 255);
new RandomDepthFirst(expected).run();
final byte[] bytes = SerializerDeserializerV1.serialize(expected);
final Maze result = SerializerDeserializerV1.deserialize(bytes);
assertThat(result).isEqualTo(expected);
}
@Test
void testSerializeDeserializeMedium() {
final Maze expected = new Maze(20, 20, -271828182846L);
new RandomDepthFirst(expected).run();
final byte[] bytes = SerializerDeserializerV1.serialize(expected);
final Maze result = SerializerDeserializerV1.deserialize(bytes);
assertThat(result).isEqualTo(expected);
}
@Test
void testSerializeDeserializeLarge() {
final Maze expected = new Maze(200, 320, 3141592653589793238L);
new RandomDepthFirst(expected).run();
final byte[] bytes = SerializerDeserializerV1.serialize(expected);
final Maze result = SerializerDeserializerV1.deserialize(bytes);
assertThat(result).isEqualTo(expected);
}
}