java.lang.Object
mazealgo.model.algorithms.mazeGenerators.Maze
All Implemented Interfaces:
Serializable

public class Maze extends Object implements 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 Details

    • Maze

      public Maze(int rows, int columns)
    • Maze

      public Maze(byte[] bytes)
      Reconstructs a maze from toByteArray(). Throws IllegalArgumentException if 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 by Maze(byte[]).

      The grid portion is what MyCompressorOutputStream runs 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

      public Position getStartPosition()
    • setStartPosition

      public void setStartPosition(Position start)
    • getGoalPosition

      public Position getGoalPosition()
    • setGoalPosition

      public void setGoalPosition(Position goal)
    • print

      public void print()
      Prints the maze. Walls are 1, passages are 0, the start is marked S and the goal is marked E.