Class Algorithm
java.lang.Object
net.regsirius06.engine.core.graphics.labyrinth.default2D.Algorithm
This class provides a set of algorithms for generating labyrinths.
It contains methods for transforming grid dimensions, calculating
indices, and generating labyrinths using different algorithms such as
Sirius' and Eller's.
The algorithms create labyrinths as a list of Wall objects,
representing walls, empty spaces, and boundaries. It also includes
helper methods for transforming 2D grid coordinates into 1D indices and vice versa.
-
Method Summary
Modifier and TypeMethodDescriptionEllerGenLabyrinth(int n, long seed) Generates a labyrinth using Eller's algorithm.static intgetIndex(int x, int y, int dimension) Converts 2D grid coordinates (x, y) to a 1D index based on the given dimension.static @NotNull PointgetPoint(int index, int dimension) Converts a 1D index into 2D coordinates based on the given dimension.SiriusGenLabyrinth(int n, long seed) Generates a labyrinth using Sirius' algorithm.static inttransformDimension(int n) Transforms the input dimension to account for the walls of the labyrinth.
-
Method Details
-
transformDimension
public static int transformDimension(int n) Transforms the input dimension to account for the walls of the labyrinth. The labyrinth grid is represented as a square, where each dimension is increased by 1 to include walls around the maze.- Parameters:
n- the size of the labyrinth without walls (number of cells in one row/column)- Returns:
- the transformed dimension, which is equal to 2 * n + 1
-
getIndex
public static int getIndex(int x, int y, int dimension) Converts 2D grid coordinates (x, y) to a 1D index based on the given dimension. This is useful for accessing elements in a list representation of the labyrinth.- Parameters:
x- the row coordinatey- the column coordinatedimension- the total dimension of the grid (including walls)- Returns:
- the 1D index corresponding to the 2D coordinates
-
getPoint
Converts a 1D index into 2D coordinates based on the given dimension. This is the reverse operation ofgetIndex(int, int, int).- Parameters:
index- the 1D indexdimension- the total dimension of the grid (including walls)- Returns:
- a
Pointobject representing the 2D coordinates of the index
-
SiriusGenLabyrinth
Generates a labyrinth using Sirius' algorithm. This algorithm randomly places walls and open spaces within the grid, creating a maze. The generated labyrinth includes boundary walls and random placements of empty spaces and walls.- Parameters:
n- the size of the labyrinth (number of cells in one row/column)seed- a seed for random number generation- Returns:
- a list of
Wallobjects representing the generated labyrinth
-
EllerGenLabyrinth
Generates a labyrinth using Eller's algorithm. This algorithm is more complex and uses a union-find data structure to progressively connect sets of cells, eventually creating a maze. The algorithm generates a maze by connecting cells row by row, then linking them vertically while ensuring there are no loops.- Parameters:
n- the size of the labyrinth (number of cells in one row/column)seed- a seed for random number generation- Returns:
- a list of
Wallobjects representing the generated labyrinth
-