Rename all "labyrinth" to "maze" and configure the Sonatype maven repo.
This commit is contained in:
parent
cb1c016cc7
commit
fcb87e13a5
8
maze-generator.iml
Normal file
8
maze-generator.iml
Normal 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
177
pom.xml
|
@ -1,31 +1,29 @@
|
|||
<?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>
|
||||
|
||||
<parent>
|
||||
<groupId>ch.fritteli</groupId>
|
||||
<artifactId>fritteli-build-parent</artifactId>
|
||||
<version>2.0.4</version>
|
||||
<version>5.0.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>ch.fritteli.labyrinth</groupId>
|
||||
<artifactId>labyrinth-generator</artifactId>
|
||||
<groupId>ch.fritteli.a-maze-r</groupId>
|
||||
<artifactId>maze-generator</artifactId>
|
||||
<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>
|
||||
<jackson.version>2.14.2</jackson.version>
|
||||
<java.source.version>17</java.source.version>
|
||||
<java.target.version>17</java.target.version>
|
||||
<jetbrains-annotations.version>24.0.1</jetbrains-annotations.version>
|
||||
<junit-jupiter.version>5.9.2</junit-jupiter.version>
|
||||
<logback.version>1.4.6</logback.version>
|
||||
<lombok.version>1.18.26</lombok.version>
|
||||
<pdfbox.version>2.0.27</pdfbox.version>
|
||||
<slf4j.version>2.0.7</slf4j.version>
|
||||
<vavr.version>0.10.4</vavr.version>
|
||||
</properties>
|
||||
<description>A-Maze-R, The Maze Generator. It is a library for generating mazes in various output formats.
|
||||
</description>
|
||||
<url>https://manuel.friedli.info/maze.html</url>
|
||||
<inceptionYear>2022</inceptionYear>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU Affero General Public License</name>
|
||||
<url>https://www.gnu.org/licenses/agpl-3.0.html</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
|
@ -42,6 +40,29 @@
|
|||
</developer>
|
||||
</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>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -91,12 +112,13 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jsonschema2pojo</groupId>
|
||||
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<version>${jsonschema2pojo-maven-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-sources</phase>
|
||||
|
@ -105,34 +127,12 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<sourcePaths>
|
||||
<sourcePath>src/main/resources/labyrinth.schema.json</sourcePath>
|
||||
<sourcePath>src/main/resources/maze.schema.json</sourcePath>
|
||||
</sourcePaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</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>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
|
@ -149,52 +149,55 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>4.0.0-M6</version>
|
||||
<version>${maven-site-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<scm>
|
||||
<connection>scm:git:https://gittr.ch/java/labyrinth-generator.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@gittr.ch/java/labyrinth-generator.git</developerConnection>
|
||||
<url>https://gittr.ch/java/labyrinth-generator</url>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>repo.gittr.ch</id>
|
||||
<name>gittr.ch</name>
|
||||
<url>https://repo.gittr.ch/releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>repo.gittr.ch</id>
|
||||
<name>gittr.ch</name>
|
||||
<url>https://repo.gittr.ch/snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo.gittr.ch.releases</id>
|
||||
<url>https://repo.gittr.ch/releases/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
</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>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -1,13 +1,14 @@
|
|||
package ch.fritteli.labyrinth.generator;
|
||||
package ch.fritteli.maze.generator;
|
||||
|
||||
import ch.fritteli.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.generator.renderer.html.HTMLRenderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.htmlfile.HTMLFileRenderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.json.JsonRenderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.jsonfile.JsonFileRenderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.pdffile.PDFFileRenderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.text.TextRenderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.textfile.TextFileRenderer;
|
||||
import ch.fritteli.maze.generator.algorithm.RandomDepthFirst;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.renderer.html.HTMLRenderer;
|
||||
import ch.fritteli.maze.generator.renderer.htmlfile.HTMLFileRenderer;
|
||||
import ch.fritteli.maze.generator.renderer.json.JsonRenderer;
|
||||
import ch.fritteli.maze.generator.renderer.jsonfile.JsonFileRenderer;
|
||||
import ch.fritteli.maze.generator.renderer.pdffile.PDFFileRenderer;
|
||||
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.Paths;
|
||||
import lombok.NonNull;
|
||||
|
@ -21,15 +22,15 @@ public class Main {
|
|||
public static void main(@NonNull final String[] args) {
|
||||
final int width = 20;
|
||||
final int height = 30;
|
||||
final Labyrinth labyrinth = new Labyrinth(width, height/*, 0*/);
|
||||
new Generator(labyrinth).run();
|
||||
final Maze maze = new Maze(width, height/*, 0*/);
|
||||
new RandomDepthFirst(maze).run();
|
||||
final TextRenderer textRenderer = TextRenderer.newInstance();
|
||||
final HTMLRenderer htmlRenderer = HTMLRenderer.newInstance();
|
||||
final JsonRenderer jsonRenderer = JsonRenderer.newInstance();
|
||||
final Path userHome = Paths.get(System.getProperty("user.home"));
|
||||
final String baseFilename = getBaseFilename(labyrinth);
|
||||
final String baseFilename = getBaseFilename(maze);
|
||||
final TextFileRenderer textFileRenderer = TextFileRenderer.newInstance()
|
||||
.setTargetLabyrinthFile(userHome.resolve(baseFilename + ".txt"))
|
||||
.setTargetMazeFile(userHome.resolve(baseFilename + ".txt"))
|
||||
.setTargetSolutionFile(userHome.resolve(baseFilename + "-solution.txt"));
|
||||
final HTMLFileRenderer htmlFileRenderer = HTMLFileRenderer.newInstance()
|
||||
.setTargetFile(userHome.resolve(baseFilename + ".html"));
|
||||
|
@ -38,26 +39,26 @@ public class Main {
|
|||
final PDFFileRenderer pdfFileRenderer = PDFFileRenderer.newInstance()
|
||||
.setTargetFile(userHome.resolve(baseFilename + ".pdf"));
|
||||
|
||||
log.info("Labyrinth-ID: {}", labyrinth.getRandomSeed());
|
||||
// Render Labyrinth to stdout
|
||||
log.info("Text rendering:\n{}", textRenderer.render(labyrinth));
|
||||
// Render Labyrinth solution to stdout
|
||||
log.info("Text rendering with solution:\n{}", textRenderer.setRenderSolution(true).render(labyrinth));
|
||||
log.info("Maze-ID: {}", maze.getRandomSeed());
|
||||
// Render Maze to stdout
|
||||
log.info("Text rendering:\n{}", textRenderer.render(maze));
|
||||
// Render Maze solution to stdout
|
||||
log.info("Text rendering with solution:\n{}", textRenderer.setRenderSolution(true).render(maze));
|
||||
// Render HTML to stdout
|
||||
log.info("HTML rendering:\n{}", htmlRenderer.render(labyrinth));
|
||||
log.info("HTML rendering:\n{}", htmlRenderer.render(maze));
|
||||
// Render JSON to stdout
|
||||
log.info("JSON rendering:\n{}", jsonRenderer.render(labyrinth));
|
||||
// Render Labyrinth and solution to (separate) files
|
||||
log.info("Text rendering to file:\n{}", textFileRenderer.render(labyrinth));
|
||||
log.info("JSON rendering:\n{}", jsonRenderer.render(maze));
|
||||
// Render Maze and solution to (separate) files
|
||||
log.info("Text rendering to file:\n{}", textFileRenderer.render(maze));
|
||||
// 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
|
||||
log.info("JSON rendering to file:\n{}", jsonFileRenderer.render(labyrinth));
|
||||
log.info("JSON rendering to file:\n{}", jsonFileRenderer.render(maze));
|
||||
// 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) {
|
||||
return "labyrinth-" + labyrinth.getWidth() + "x" + labyrinth.getHeight() + "-" + labyrinth.getRandomSeed();
|
||||
private static String getBaseFilename(@NonNull final Maze maze) {
|
||||
return "maze-" + maze.getWidth() + "x" + maze.getHeight() + "-" + maze.getRandomSeed();
|
||||
}
|
||||
}
|
|
@ -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.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.generator.model.Position;
|
||||
import ch.fritteli.labyrinth.generator.model.Tile;
|
||||
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 io.vavr.control.Option;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
import lombok.NonNull;
|
||||
|
||||
public class Generator {
|
||||
public class RandomDepthFirst {
|
||||
|
||||
@NonNull
|
||||
private final Labyrinth labyrinth;
|
||||
private final Maze maze;
|
||||
@NonNull
|
||||
private final Random random;
|
||||
@NonNull
|
||||
private final Deque<Position> positions = new LinkedList<>();
|
||||
|
||||
public Generator(@NonNull final Labyrinth labyrinth) {
|
||||
this.labyrinth = labyrinth;
|
||||
this.random = new Random(labyrinth.getRandomSeed());
|
||||
public RandomDepthFirst(@NonNull final Maze maze) {
|
||||
this.maze = maze;
|
||||
this.random = new Random(maze.getRandomSeed());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
@ -31,8 +31,8 @@ public class Generator {
|
|||
}
|
||||
|
||||
private void preDig() {
|
||||
final Position end = this.labyrinth.getEnd();
|
||||
final Tile endTile = this.labyrinth.getEndTile();
|
||||
final Position end = this.maze.getEnd();
|
||||
final Tile endTile = this.maze.getEndTile();
|
||||
|
||||
if (end.getY() == 0) {
|
||||
endTile.enableDiggingToOrFrom(Direction.TOP);
|
||||
|
@ -40,10 +40,10 @@ public class Generator {
|
|||
} else if (end.getX() == 0) {
|
||||
endTile.enableDiggingToOrFrom(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.digFrom(Direction.BOTTOM);
|
||||
} else if (end.getX() == this.labyrinth.getWidth() - 1) {
|
||||
} else if (end.getX() == this.maze.getWidth() - 1) {
|
||||
endTile.enableDiggingToOrFrom(Direction.RIGHT);
|
||||
endTile.digFrom(Direction.RIGHT);
|
||||
}
|
||||
|
@ -54,17 +54,17 @@ public class Generator {
|
|||
private void dig() {
|
||||
while (!this.positions.isEmpty()) {
|
||||
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);
|
||||
if (directionToDigTo.isDefined()) {
|
||||
final Direction digTo = directionToDigTo.get();
|
||||
final Direction digFrom = digTo.invert();
|
||||
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)) {
|
||||
// all ok!
|
||||
this.positions.push(neighborPosition);
|
||||
if (neighborPosition.equals(this.labyrinth.getStart())) {
|
||||
if (neighborPosition.equals(this.maze.getStart())) {
|
||||
this.markSolution();
|
||||
}
|
||||
} else {
|
||||
|
@ -79,12 +79,12 @@ public class Generator {
|
|||
}
|
||||
|
||||
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() {
|
||||
final Position start = this.labyrinth.getStart();
|
||||
final Tile startTile = this.labyrinth.getStartTile();
|
||||
final Position start = this.maze.getStart();
|
||||
final Tile startTile = this.maze.getStartTile();
|
||||
|
||||
if (start.getY() == 0) {
|
||||
startTile.enableDiggingToOrFrom(Direction.TOP);
|
||||
|
@ -92,10 +92,10 @@ public class Generator {
|
|||
} else if (start.getX() == 0) {
|
||||
startTile.enableDiggingToOrFrom(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.digTo(Direction.BOTTOM);
|
||||
} else if (start.getX() == this.labyrinth.getWidth() - 1) {
|
||||
} else if (start.getX() == this.maze.getWidth() - 1) {
|
||||
startTile.enableDiggingToOrFrom(Direction.RIGHT);
|
||||
startTile.digTo(Direction.RIGHT);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.generator.model;
|
||||
package ch.fritteli.maze.generator.model;
|
||||
|
||||
public enum Direction {
|
||||
TOP,
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.generator.model;
|
||||
package ch.fritteli.maze.generator.model;
|
||||
|
||||
import io.vavr.control.Option;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@ -8,7 +8,7 @@ import lombok.ToString;
|
|||
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
public class Labyrinth {
|
||||
public class Maze {
|
||||
|
||||
private final Tile[][] field;
|
||||
@Getter
|
||||
|
@ -22,19 +22,19 @@ public class Labyrinth {
|
|||
@Getter
|
||||
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());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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) {
|
||||
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'");
|
||||
}
|
||||
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) {
|
||||
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.height = height;
|
||||
|
@ -59,7 +59,7 @@ public class Labyrinth {
|
|||
/**
|
||||
* 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.width = width;
|
||||
this.height = height;
|
||||
|
@ -71,7 +71,7 @@ public class Labyrinth {
|
|||
/**
|
||||
* 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.width = width;
|
||||
this.height = height;
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.generator.model;
|
||||
package ch.fritteli.maze.generator.model;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.generator.model;
|
||||
package ch.fritteli.maze.generator.model;
|
||||
|
||||
import io.vavr.collection.Stream;
|
||||
import io.vavr.control.Option;
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.generator.model;
|
||||
package ch.fritteli.maze.generator.model;
|
||||
|
||||
import io.vavr.collection.Stream;
|
||||
import lombok.EqualsAndHashCode;
|
|
@ -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);
|
||||
}
|
|
@ -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.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.generator.model.Tile;
|
||||
import ch.fritteli.maze.generator.model.Direction;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.model.Tile;
|
||||
import io.vavr.collection.HashSet;
|
||||
import io.vavr.collection.Set;
|
||||
import lombok.AccessLevel;
|
||||
|
@ -11,17 +11,17 @@ import lombok.RequiredArgsConstructor;
|
|||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class Generator {
|
||||
private final Labyrinth labyrinth;
|
||||
private final Maze maze;
|
||||
private int y = 0;
|
||||
|
||||
boolean hasNext() {
|
||||
return this.y < this.labyrinth.getHeight();
|
||||
return this.y < this.maze.getHeight();
|
||||
}
|
||||
|
||||
String next() {
|
||||
StringBuilder sb = new StringBuilder("<tr>");
|
||||
for (int x = 0; x < this.labyrinth.getWidth(); x++) {
|
||||
final Tile currentTile = this.labyrinth.getTileAt(x, this.y).get();
|
||||
for (int x = 0; x < this.maze.getWidth(); x++) {
|
||||
final Tile currentTile = this.maze.getTileAt(x, this.y).get();
|
||||
sb.append("<td class=\"");
|
||||
sb.append(this.getClasses(currentTile).mkString(" "));
|
||||
sb.append("\"> </td>");
|
|
@ -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.labyrinth.generator.renderer.Renderer;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.renderer.Renderer;
|
||||
import lombok.NonNull;
|
||||
|
||||
public class HTMLRenderer implements Renderer<String> {
|
||||
|
@ -119,12 +119,12 @@ public class HTMLRenderer implements Renderer<String> {
|
|||
|
||||
@NonNull
|
||||
@Override
|
||||
public String render(@NonNull final Labyrinth labyrinth) {
|
||||
if (labyrinth.getWidth() == 0 || labyrinth.getHeight() == 0) {
|
||||
return this.getPreamble(labyrinth) + POSTAMBLE;
|
||||
public String render(@NonNull final Maze maze) {
|
||||
if (maze.getWidth() == 0 || maze.getHeight() == 0) {
|
||||
return this.getPreamble(maze) + POSTAMBLE;
|
||||
}
|
||||
final Generator generator = new Generator(labyrinth);
|
||||
final StringBuilder sb = new StringBuilder(this.getPreamble(labyrinth));
|
||||
final Generator generator = new Generator(maze);
|
||||
final StringBuilder sb = new StringBuilder(this.getPreamble(maze));
|
||||
sb.append("<table id=\"labyrinth\">");
|
||||
while (generator.hasNext()) {
|
||||
sb.append(generator.next());
|
||||
|
@ -134,10 +134,10 @@ public class HTMLRenderer implements Renderer<String> {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
private String getPreamble(@NonNull final Labyrinth labyrinth) {
|
||||
private String getPreamble(@NonNull final Maze maze) {
|
||||
return "<!DOCTYPE html><html lang=\"en\">" +
|
||||
"<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\">" +
|
||||
"<style>" +
|
||||
"table{border-collapse:collapse;}" +
|
|
@ -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.labyrinth.generator.renderer.Renderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.html.HTMLRenderer;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.renderer.Renderer;
|
||||
import ch.fritteli.maze.generator.renderer.html.HTMLRenderer;
|
||||
import io.vavr.control.Option;
|
||||
import io.vavr.control.Try;
|
||||
import lombok.NonNull;
|
||||
|
@ -24,7 +24,7 @@ public class HTMLFileRenderer implements Renderer<Path> {
|
|||
|
||||
private HTMLFileRenderer() {
|
||||
this.targetFile = Try
|
||||
.of(() -> Files.createTempFile("labyrinth_", ".html"))
|
||||
.of(() -> Files.createTempFile("maze_", ".html"))
|
||||
.onFailure(ex -> log.error("Unable to set default target file.", ex))
|
||||
.toOption();
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class HTMLFileRenderer implements Renderer<Path> {
|
|||
|
||||
@NonNull
|
||||
@Override
|
||||
public Path render(@NonNull final Labyrinth labyrinth) {
|
||||
public Path render(@NonNull final Maze maze) {
|
||||
if (!this.isTargetFileDefinedAndWritable()) {
|
||||
try {
|
||||
Files.createFile(this.targetFile.get());
|
||||
|
@ -56,7 +56,7 @@ public class HTMLFileRenderer implements Renderer<Path> {
|
|||
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();
|
||||
try {
|
||||
Files.writeString(targetFile, html, StandardCharsets.UTF_8);
|
|
@ -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.labyrinth.generator.json.JsonCoordinates;
|
||||
import ch.fritteli.labyrinth.generator.json.JsonLabyrinth;
|
||||
import ch.fritteli.labyrinth.generator.model.Direction;
|
||||
import ch.fritteli.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.generator.model.Tile;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import ch.fritteli.maze.generator.json.JsonCell;
|
||||
import ch.fritteli.maze.generator.json.JsonCoordinates;
|
||||
import ch.fritteli.maze.generator.json.JsonMaze;
|
||||
import ch.fritteli.maze.generator.model.Direction;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.model.Tile;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class Generator {
|
||||
|
||||
@NonNull
|
||||
private final Labyrinth labyrinth;
|
||||
private final Maze maze;
|
||||
|
||||
@NonNull
|
||||
JsonLabyrinth generate() {
|
||||
final JsonLabyrinth result = new JsonLabyrinth();
|
||||
result.setId(String.valueOf(this.labyrinth.getRandomSeed()));
|
||||
result.setWidth(this.labyrinth.getWidth());
|
||||
result.setHeight(this.labyrinth.getHeight());
|
||||
JsonMaze generate() {
|
||||
final JsonMaze result = new JsonMaze();
|
||||
result.setId(String.valueOf(this.maze.getRandomSeed()));
|
||||
result.setWidth(this.maze.getWidth());
|
||||
result.setHeight(this.maze.getHeight());
|
||||
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<>();
|
||||
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.
|
||||
final String exceptionString = "Failed to obtain tile at %dx%d, although labyrinth has dimensoins %dx%d"
|
||||
.formatted(x, y, this.labyrinth.getWidth(), this.labyrinth.getHeight());
|
||||
final Tile tile = this.labyrinth.getTileAt(x, y)
|
||||
final String exceptionString = "Failed to obtain tile at %dx%d, although maze has dimensoins %dx%d"
|
||||
.formatted(x, y, this.maze.getWidth(), this.maze.getHeight());
|
||||
final Tile tile = this.maze.getTileAt(x, y)
|
||||
.getOrElseThrow(() -> new IllegalStateException(exceptionString));
|
||||
final JsonCell cell = new JsonCell();
|
||||
cell.setTop(tile.hasWallAt(Direction.TOP));
|
||||
|
@ -45,12 +46,12 @@ class Generator {
|
|||
}
|
||||
result.setGrid(rows);
|
||||
final JsonCoordinates start = new JsonCoordinates();
|
||||
start.setX(this.labyrinth.getStart().getX());
|
||||
start.setY(this.labyrinth.getStart().getY());
|
||||
start.setX(this.maze.getStart().getX());
|
||||
start.setY(this.maze.getStart().getY());
|
||||
result.setStart(start);
|
||||
final JsonCoordinates end = new JsonCoordinates();
|
||||
end.setX(this.labyrinth.getEnd().getX());
|
||||
end.setY(this.labyrinth.getEnd().getY());
|
||||
end.setX(this.maze.getEnd().getX());
|
||||
end.setY(this.maze.getEnd().getY());
|
||||
result.setEnd(end);
|
||||
return result;
|
||||
}
|
|
@ -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.labyrinth.generator.json.JsonLabyrinth;
|
||||
import ch.fritteli.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.generator.renderer.Renderer;
|
||||
import ch.fritteli.maze.generator.json.JsonCell;
|
||||
import ch.fritteli.maze.generator.json.JsonMaze;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.renderer.Renderer;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.NonNull;
|
||||
|
||||
public class JsonRenderer implements Renderer<String> {
|
||||
|
||||
|
@ -27,7 +28,7 @@ public class JsonRenderer implements Renderer<String> {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
private static JsonLabyrinth createSingleCellLabyrinth() {
|
||||
private static JsonMaze createSingleCellMaze() {
|
||||
// This is the only cell.
|
||||
final JsonCell cell = new JsonCell();
|
||||
cell.setRight(true);
|
||||
|
@ -37,17 +38,17 @@ public class JsonRenderer implements Renderer<String> {
|
|||
final List<List<JsonCell>> rows = new ArrayList<>();
|
||||
rows.add(new ArrayList<>());
|
||||
rows.get(0).add(cell);
|
||||
// Wrap it all in an instance of JsonLabyrinth.
|
||||
final JsonLabyrinth jsonLabyrinth = new JsonLabyrinth();
|
||||
jsonLabyrinth.setId("0");
|
||||
jsonLabyrinth.setGrid(rows);
|
||||
return jsonLabyrinth;
|
||||
// Wrap it all in an instance of JsonMaze.
|
||||
final JsonMaze jsonMaze = new JsonMaze();
|
||||
jsonMaze.setId("0");
|
||||
jsonMaze.setGrid(rows);
|
||||
return jsonMaze;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String toString(@NonNull final JsonLabyrinth jsonLabyrinth) {
|
||||
private String toString(@NonNull final JsonMaze jsonMaze) {
|
||||
try {
|
||||
return this.objectMapper.writeValueAsString(jsonLabyrinth);
|
||||
return this.objectMapper.writeValueAsString(jsonMaze);
|
||||
} catch (final JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -55,14 +56,14 @@ public class JsonRenderer implements Renderer<String> {
|
|||
|
||||
@NonNull
|
||||
@Override
|
||||
public String render(@NonNull final Labyrinth labyrinth) {
|
||||
final JsonLabyrinth jsonLabyrinth;
|
||||
if (labyrinth.getWidth() == 0 || labyrinth.getHeight() == 0) {
|
||||
jsonLabyrinth = createSingleCellLabyrinth();
|
||||
public String render(@NonNull final Maze maze) {
|
||||
final JsonMaze jsonMaze;
|
||||
if (maze.getWidth() == 0 || maze.getHeight() == 0) {
|
||||
jsonMaze = createSingleCellMaze();
|
||||
} else {
|
||||
final Generator generator = new Generator(labyrinth);
|
||||
jsonLabyrinth = generator.generate();
|
||||
final Generator generator = new Generator(maze);
|
||||
jsonMaze = generator.generate();
|
||||
}
|
||||
return toString(jsonLabyrinth);
|
||||
return toString(jsonMaze);
|
||||
}
|
||||
}
|
|
@ -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.labyrinth.generator.renderer.Renderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.json.JsonRenderer;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.renderer.Renderer;
|
||||
import ch.fritteli.maze.generator.renderer.json.JsonRenderer;
|
||||
import io.vavr.control.Option;
|
||||
import io.vavr.control.Try;
|
||||
import java.io.File;
|
||||
|
@ -24,7 +24,7 @@ public class JsonFileRenderer implements Renderer<Path> {
|
|||
|
||||
private JsonFileRenderer() {
|
||||
this.targetFile = Try
|
||||
.of(() -> Files.createTempFile("labyrinth_", ".json"))
|
||||
.of(() -> Files.createTempFile("maze_", ".json"))
|
||||
.onFailure(ex -> log.error("Unable to set default target file.", ex))
|
||||
.toOption();
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class JsonFileRenderer implements Renderer<Path> {
|
|||
|
||||
@NonNull
|
||||
@Override
|
||||
public Path render(@NonNull final Labyrinth labyrinth) {
|
||||
public Path render(@NonNull final Maze maze) {
|
||||
if (!this.isTargetFileDefinedAndWritable()) {
|
||||
try {
|
||||
Files.createFile(this.targetFile.get());
|
||||
|
@ -56,7 +56,7 @@ public class JsonFileRenderer implements Renderer<Path> {
|
|||
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();
|
||||
try {
|
||||
Files.writeString(outputFile, json, StandardCharsets.UTF_8);
|
|
@ -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.labyrinth.generator.model.Labyrinth;
|
||||
import ch.fritteli.labyrinth.generator.model.Position;
|
||||
import ch.fritteli.labyrinth.generator.model.Tile;
|
||||
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 io.vavr.control.Option;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
|
@ -25,16 +25,16 @@ import org.jetbrains.annotations.Nullable;
|
|||
class Generator {
|
||||
|
||||
@NonNull
|
||||
private final Labyrinth labyrinth;
|
||||
private final Maze maze;
|
||||
|
||||
@NonNull
|
||||
public ByteArrayOutputStream generate() {
|
||||
final float pageWidth = this.labyrinth.getWidth() * PDFRenderer.SCALE + 2 * PDFRenderer.MARGIN;
|
||||
final float pageHeight = this.labyrinth.getHeight() * PDFRenderer.SCALE + 2 * PDFRenderer.MARGIN;
|
||||
final float pageWidth = this.maze.getWidth() * PDFRenderer.SCALE + 2 * PDFRenderer.MARGIN;
|
||||
final float pageHeight = this.maze.getHeight() * PDFRenderer.SCALE + 2 * PDFRenderer.MARGIN;
|
||||
|
||||
final PDDocument pdDocument = new PDDocument();
|
||||
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);
|
||||
final PDPage puzzlePage = 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.
|
||||
Coordinate coordinate = new Coordinate(0f, 0f);
|
||||
// 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;
|
||||
coordinate = coordinate.withY(y);
|
||||
for (int x = 0; x < this.labyrinth.getWidth(); x++) {
|
||||
final Tile currentTile = this.labyrinth.getTileAt(x, y).get();
|
||||
for (int x = 0; x < this.maze.getWidth(); x++) {
|
||||
final Tile currentTile = this.maze.getTileAt(x, y).get();
|
||||
coordinate = coordinate.withX(x);
|
||||
if (currentTile.hasWallAt(Direction.TOP)) {
|
||||
if (!isPainting) {
|
||||
|
@ -96,7 +96,7 @@ class Generator {
|
|||
}
|
||||
}
|
||||
if (isPainting) {
|
||||
coordinate = coordinate.withX(this.labyrinth.getWidth());
|
||||
coordinate = coordinate.withX(this.maze.getWidth());
|
||||
for (final PDPageContentStream contentStream : contentStreams) {
|
||||
contentStream.lineTo(coordinate.getX(), coordinate.getY());
|
||||
contentStream.stroke();
|
||||
|
@ -105,10 +105,10 @@ class Generator {
|
|||
}
|
||||
// Draw the BOTTOM border of the last row of tiles.
|
||||
boolean isPainting = false;
|
||||
int y = this.labyrinth.getHeight();
|
||||
coordinate = coordinate.withY(this.labyrinth.getHeight());
|
||||
for (int x = 0; x < this.labyrinth.getWidth(); x++) {
|
||||
final Tile currentTile = this.labyrinth.getTileAt(x, y - 1).get();
|
||||
int y = this.maze.getHeight();
|
||||
coordinate = coordinate.withY(this.maze.getHeight());
|
||||
for (int x = 0; x < this.maze.getWidth(); x++) {
|
||||
final Tile currentTile = this.maze.getTileAt(x, y - 1).get();
|
||||
coordinate = coordinate.withX(x);
|
||||
if (currentTile.hasWallAt(Direction.BOTTOM)) {
|
||||
if (!isPainting) {
|
||||
|
@ -128,7 +128,7 @@ class Generator {
|
|||
}
|
||||
}
|
||||
if (isPainting) {
|
||||
coordinate = coordinate.withX(this.labyrinth.getWidth());
|
||||
coordinate = coordinate.withX(this.maze.getWidth());
|
||||
for (final PDPageContentStream contentStream : contentStreams) {
|
||||
contentStream.lineTo(coordinate.getX(), coordinate.getY());
|
||||
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.
|
||||
Coordinate coordinate = new Coordinate(0f, 0f);
|
||||
// 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;
|
||||
coordinate = coordinate.withX(x);
|
||||
for (int y = 0; y < this.labyrinth.getHeight(); y++) {
|
||||
final Tile currentTile = this.labyrinth.getTileAt(x, y).get();
|
||||
for (int y = 0; y < this.maze.getHeight(); y++) {
|
||||
final Tile currentTile = this.maze.getTileAt(x, y).get();
|
||||
coordinate = coordinate.withY(y);
|
||||
if (currentTile.hasWallAt(Direction.LEFT)) {
|
||||
if (!isPainting) {
|
||||
|
@ -164,7 +164,7 @@ class Generator {
|
|||
}
|
||||
}
|
||||
if (isPainting) {
|
||||
coordinate = coordinate.withY(this.labyrinth.getHeight());
|
||||
coordinate = coordinate.withY(this.maze.getHeight());
|
||||
for (final PDPageContentStream contentStream : contentStreams) {
|
||||
contentStream.lineTo(coordinate.getX(), coordinate.getY());
|
||||
contentStream.stroke();
|
||||
|
@ -173,10 +173,10 @@ class Generator {
|
|||
}
|
||||
// Draw the RIGHT border of the last column of tiles.
|
||||
boolean isPainting = false;
|
||||
int x = this.labyrinth.getWidth();
|
||||
coordinate = coordinate.withX(this.labyrinth.getWidth());
|
||||
for (int y = 0; y < this.labyrinth.getHeight(); y++) {
|
||||
final Tile currentTile = this.labyrinth.getTileAt(x - 1, y).get();
|
||||
int x = this.maze.getWidth();
|
||||
coordinate = coordinate.withX(this.maze.getWidth());
|
||||
for (int y = 0; y < this.maze.getHeight(); y++) {
|
||||
final Tile currentTile = this.maze.getTileAt(x - 1, y).get();
|
||||
coordinate = coordinate.withY(y);
|
||||
if (currentTile.hasWallAt(Direction.RIGHT)) {
|
||||
if (!isPainting) {
|
||||
|
@ -196,7 +196,7 @@ class Generator {
|
|||
}
|
||||
}
|
||||
if (isPainting) {
|
||||
coordinate = coordinate.withY(this.labyrinth.getHeight());
|
||||
coordinate = coordinate.withY(this.maze.getHeight());
|
||||
for (final PDPageContentStream contentStream : contentStreams) {
|
||||
contentStream.lineTo(coordinate.getX(), coordinate.getY());
|
||||
contentStream.stroke();
|
||||
|
@ -208,8 +208,8 @@ class Generator {
|
|||
// Draw the solution in 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.
|
||||
final Position end = this.labyrinth.getEnd();
|
||||
Position currentPosition = this.labyrinth.getStart();
|
||||
final Position end = this.maze.getEnd();
|
||||
Position currentPosition = this.maze.getStart();
|
||||
Position previousPosition = null;
|
||||
SolutionCoordinate coordinate = new SolutionCoordinate(currentPosition.getX(), currentPosition.getY());
|
||||
pageContentStream.moveTo(coordinate.getX(), coordinate.getY());
|
||||
|
@ -225,11 +225,11 @@ class Generator {
|
|||
|
||||
@NonNull
|
||||
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()) {
|
||||
if (!currentTile.hasWallAt(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)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ class Generator {
|
|||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.labyrinth.generator.renderer.Renderer;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.renderer.Renderer;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
public class PDFRenderer implements Renderer<ByteArrayOutputStream> {
|
||||
|
@ -19,8 +20,8 @@ public class PDFRenderer implements Renderer<ByteArrayOutputStream> {
|
|||
|
||||
@NonNull
|
||||
@Override
|
||||
public ByteArrayOutputStream render(@NonNull final Labyrinth labyrinth) {
|
||||
final Generator generator = new Generator(labyrinth);
|
||||
public ByteArrayOutputStream render(@NonNull final Maze maze) {
|
||||
final Generator generator = new Generator(maze);
|
||||
return generator.generate();
|
||||
}
|
||||
}
|
|
@ -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.labyrinth.generator.renderer.Renderer;
|
||||
import ch.fritteli.labyrinth.generator.renderer.pdf.PDFRenderer;
|
||||
import ch.fritteli.maze.generator.model.Maze;
|
||||
import ch.fritteli.maze.generator.renderer.Renderer;
|
||||
import ch.fritteli.maze.generator.renderer.pdf.PDFRenderer;
|
||||
import io.vavr.control.Option;
|
||||
import io.vavr.control.Try;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -24,7 +24,7 @@ public class PDFFileRenderer implements Renderer<Path> {
|
|||
|
||||
private PDFFileRenderer() {
|
||||
this.targetFile = Try
|
||||
.of(() -> Files.createTempFile("labyrinth_", ".pdf"))
|
||||
.of(() -> Files.createTempFile("maze_", ".pdf"))
|
||||
.onFailure(ex -> log.error("Unable to set default target file.", ex))
|
||||
.toOption();
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class PDFFileRenderer implements Renderer<Path> {
|
|||
|
||||
@NonNull
|
||||
@Override
|
||||
public Path render(@NonNull final Labyrinth labyrinth) {
|
||||
public Path render(@NonNull final Maze maze) {
|
||||
if (!this.isTargetFileDefinedAndWritable()) {
|
||||
try {
|
||||
Files.createFile(this.targetFile.get());
|
||||
|
@ -56,7 +56,7 @@ public class PDFFileRenderer implements Renderer<Path> {
|
|||
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();
|
||||
try {
|
||||
bytes.writeTo(Files.newOutputStream(outputFile));
|
|
@ -1,4 +1,4 @@
|
|||
package ch.fritteli.labyrinth.generator.renderer.text;
|
||||
package ch.fritteli.maze.generator.renderer.text;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|