Class Maze
java.lang.Object
mazealgo.model.algorithms.mazeGenerators.Maze
- All Implemented Interfaces:
Serializable
A 2D maze: an int grid where 1 is a wall and 0 is a passable cell,
with a start position and a goal position.
Two wire formats:
- Default Java serialization (via
Serializable) — convenient but verbose. Used by SolveMazeStrategy where the maze travels client-to-server once and the overhead doesn't dominate. toByteArray()/Maze(byte[])— compact, fixed header + flat grid bytes. Wrapped by MyCompressorOutputStream's run-length encoding when shipping back from GenerateMazeStrategy.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMaze(byte[] bytes) Reconstructs a maze fromtoByteArray().Maze(int rows, int columns) -
Method Summary
Modifier and TypeMethodDescriptionintgetCell(int row, int column) intintgetRows()voidprint()Prints the maze.voidsetCell(int row, int column, int value) voidsetGoalPosition(Position goal) voidsetStartPosition(Position start) byte[]Compact byte representation: six big-endian ints (rows, columns, start row/col, goal row/col) followed by rows*columns single bytes — one per cell, value 0 or 1.
-
Constructor Details
-
Maze
public Maze(int rows, int columns) -
Maze
public Maze(byte[] bytes) Reconstructs a maze fromtoByteArray(). ThrowsIllegalArgumentExceptionif the byte stream is truncated or malformed (typically: caller passed something that wasn't produced by toByteArray).
-
-
Method Details
-
toByteArray
public byte[] toByteArray()Compact byte representation: six big-endian ints (rows, columns, start row/col, goal row/col) followed by rows*columns single bytes — one per cell, value 0 or 1. Mirrored byMaze(byte[]).The grid portion is what
MyCompressorOutputStreamruns RLE over; the header is varied enough that compression doesn't help it, but the grid (long runs of 0 or 1) shrinks dramatically. -
getRows
public int getRows() -
getColumns
public int getColumns() -
getCell
public int getCell(int row, int column) -
setCell
public void setCell(int row, int column, int value) -
getStartPosition
-
setStartPosition
-
getGoalPosition
-
setGoalPosition
-
print
public void print()Prints the maze. Walls are 1, passages are 0, the start is marked S and the goal is marked E.
-