feature/wilson-algorithm #10
					 4 changed files with 107 additions and 0 deletions
				
			
		|  | @ -86,6 +86,21 @@ public class Wilson extends AbstractMazeGeneratorAlgorithm { | |||
|         direction = determineDirectionForDigging(maze.getEnd()); | ||||
|         t = maze.getEndTile(); | ||||
|         this.digTo(t, direction); | ||||
|         // seal all walls, mark all as visited | ||||
|         for (int x = 0; x < maze.getWidth(); x++) { | ||||
|             for (int y = 0; y < maze.getHeight(); y++) { | ||||
|                 maze.getTileAt(x, y).forEach(tile -> { | ||||
|                     Stream.of(Direction.values()) | ||||
|                             .forEach(d -> { | ||||
|                                 if (tile.hasWallAt(d)) { | ||||
|                                     tile.preventDiggingToOrFrom(d); | ||||
|                                 } else { | ||||
|                                     tile.digFrom(d); | ||||
|                                 } | ||||
|                             }); | ||||
|                 }); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Nullable | ||||
|  |  | |||
|  | @ -13,6 +13,8 @@ class SerializerDeserializerV1Test { | |||
|         new RandomDepthFirst(expected).run(); | ||||
|         final byte[] bytes = SerializerDeserializerV1.serialize(expected); | ||||
|         final Maze result = SerializerDeserializerV1.deserialize(bytes); | ||||
|         assertThat(result.getAlgorithm()).isNull(); | ||||
|         expected.setAlgorithm(null); | ||||
|         assertThat(result).isEqualTo(expected); | ||||
|     } | ||||
| 
 | ||||
|  | @ -22,6 +24,8 @@ class SerializerDeserializerV1Test { | |||
|         new RandomDepthFirst(expected).run(); | ||||
|         final byte[] bytes = SerializerDeserializerV1.serialize(expected); | ||||
|         final Maze result = SerializerDeserializerV1.deserialize(bytes); | ||||
|         assertThat(result.getAlgorithm()).isNull(); | ||||
|         expected.setAlgorithm(null); | ||||
|         assertThat(result).isEqualTo(expected); | ||||
|     } | ||||
| 
 | ||||
|  | @ -31,6 +35,8 @@ class SerializerDeserializerV1Test { | |||
|         new RandomDepthFirst(expected).run(); | ||||
|         final byte[] bytes = SerializerDeserializerV1.serialize(expected); | ||||
|         final Maze result = SerializerDeserializerV1.deserialize(bytes); | ||||
|         assertThat(result.getAlgorithm()).isNull(); | ||||
|         expected.setAlgorithm(null); | ||||
|         assertThat(result).isEqualTo(expected); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,46 @@ | |||
| package ch.fritteli.maze.generator.serialization.v2; | ||||
| 
 | ||||
| import ch.fritteli.maze.generator.algorithm.RandomDepthFirst; | ||||
| import ch.fritteli.maze.generator.algorithm.Wilson; | ||||
| import ch.fritteli.maze.generator.model.Maze; | ||||
| import ch.fritteli.maze.generator.model.Position; | ||||
| import org.junit.jupiter.api.Test; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| 
 | ||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||
| 
 | ||||
| class SerializerDeserializerV2Test { | ||||
|     @Test | ||||
|     void testSerializeDeserializeTiny() throws IOException { | ||||
|         final Maze expected = new Maze(2, 2, 255, new Position(0, 0), new Position(1, 1)); | ||||
|         new RandomDepthFirst(expected).run(); | ||||
|         final byte[] bytes = SerializerDeserializerV2.serialize(expected); | ||||
|         final Maze result = SerializerDeserializerV2.deserialize(bytes); | ||||
|         assertThat(result.getAlgorithm()).isNull(); | ||||
|         expected.setAlgorithm(null); | ||||
|         assertThat(result).isEqualTo(expected); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void testSerializeDeserializeMedium() throws IOException { | ||||
|         final Maze expected = new Maze(20, 20, -271828182846L); | ||||
|         new Wilson(expected).run(); | ||||
|         final byte[] bytes = SerializerDeserializerV2.serialize(expected); | ||||
|         final Maze result = SerializerDeserializerV2.deserialize(bytes); | ||||
|         assertThat(result.getAlgorithm()).isNull(); | ||||
|         expected.setAlgorithm(null); | ||||
|         assertThat(result).isEqualTo(expected); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void testSerializeDeserializeLarge() throws IOException { | ||||
|         final Maze expected = new Maze(200, 320, 3141592653589793238L); | ||||
|         new Wilson(expected).run(); | ||||
|         final byte[] bytes = SerializerDeserializerV2.serialize(expected); | ||||
|         final Maze result = SerializerDeserializerV2.deserialize(bytes); | ||||
|         assertThat(result.getAlgorithm()).isNull(); | ||||
|         expected.setAlgorithm(null); | ||||
|         assertThat(result).isEqualTo(expected); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,40 @@ | |||
| package ch.fritteli.maze.generator.serialization.v3; | ||||
| 
 | ||||
| import ch.fritteli.maze.generator.algorithm.RandomDepthFirst; | ||||
| import ch.fritteli.maze.generator.algorithm.Wilson; | ||||
| import ch.fritteli.maze.generator.model.Maze; | ||||
| import ch.fritteli.maze.generator.model.Position; | ||||
| import org.junit.jupiter.api.Test; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| 
 | ||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||
| 
 | ||||
| class SerializerDeserializerV3Test { | ||||
|     @Test | ||||
|     void testSerializeDeserializeTiny() throws IOException { | ||||
|         final Maze expected = new Maze(2, 2, 255, new Position(0, 0), new Position(1, 1)); | ||||
|         new RandomDepthFirst(expected).run(); | ||||
|         final byte[] bytes = SerializerDeserializerV3.serialize(expected); | ||||
|         final Maze result = SerializerDeserializerV3.deserialize(bytes); | ||||
|         assertThat(result).isEqualTo(expected); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void testSerializeDeserializeMedium() throws IOException { | ||||
|         final Maze expected = new Maze(20, 20, -271828182846L); | ||||
|         new Wilson(expected).run(); | ||||
|         final byte[] bytes = SerializerDeserializerV3.serialize(expected); | ||||
|         final Maze result = SerializerDeserializerV3.deserialize(bytes); | ||||
|         assertThat(result).isEqualTo(expected); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void testSerializeDeserializeLarge() throws IOException { | ||||
|         final Maze expected = new Maze(200, 320, 3141592653589793238L); | ||||
|         new Wilson(expected).run(); | ||||
|         final byte[] bytes = SerializerDeserializerV3.serialize(expected); | ||||
|         final Maze result = SerializerDeserializerV3.deserialize(bytes); | ||||
|         assertThat(result).isEqualTo(expected); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue