Maze Builder Docs 8.8.13
Loading...
Searching...
No Matches
mazes::mask Class Reference

2D boolean mask for controlling which cells are available in maze generation More...

#include <mask.h>

Public Member Functions

 mask (unsigned int rows, unsigned int columns)
 Construct a mask with specified dimensions, all cells enabled.
 mask (const mask &)=default
mask & operator= (const mask &)=default
 mask (mask &&) noexcept=default
mask & operator= (mask &&) noexcept=default
bool operator() (unsigned int row, unsigned int column) const noexcept
 Check if a cell at (row, column) is available.
void set (unsigned int row, unsigned int column, bool is_on) noexcept
 Set a cell's availability.
int count () const noexcept
 Count the number of available cells.
std::pair< unsigned int, unsigned int > random_location (randomizer &rng) const noexcept
 Get a random available cell location.
unsigned int rows () const noexcept
 Get the number of rows.
unsigned int columns () const noexcept
 Get the number of columns.

Static Public Member Functions

static mask from_txt (const std::string &filename)
 Load a mask from a text file.
static mask from_string (std::string_view text)
 Load a mask from an inline string.
static mask from_source (std::string_view source)
 Load a mask from either a file path or an inline string.

Detailed Description

2D boolean mask for controlling which cells are available in maze generation

Cells marked as blocked (false) are excluded from maze generation. "X" characters in text files denote blocked cells.

Constructor & Destructor Documentation

◆ mask()

mazes::mask::mask ( unsigned int rows,
unsigned int columns )
explicit

Construct a mask with specified dimensions, all cells enabled.

Parameters
rowsNumber of rows
columnsNumber of columns

Member Function Documentation

◆ columns()

unsigned int mazes::mask::columns ( ) const
nodiscardnoexcept

Get the number of columns.

Returns
Number of columns

◆ count()

int mazes::mask::count ( ) const
noexcept

Count the number of available cells.

Returns
Number of available cells

◆ from_source()

mask mazes::mask::from_source ( std::string_view source)
static

Load a mask from either a file path or an inline string.

Parameters
sourceFile path or inline mask string
Returns
A mask loaded from the given source
Exceptions
std::runtime_errorif the source cannot be resolved

◆ from_string()

mask mazes::mask::from_string ( std::string_view text)
static

Load a mask from an inline string.

Parameters
textMask text ('X' = blocked, other = available)
Returns
A mask loaded from the string
Exceptions
std::runtime_errorif the string is empty or invalid
Note
Supports embedded newlines and escaped newline sequences such as "\n"

◆ from_txt()

mask mazes::mask::from_txt ( const std::string & filename)
static

Load a mask from a text file.

Parameters
filenamePath to the text file ('X' = blocked, other = available)
Returns
A mask loaded from the file
Exceptions
std::runtime_errorif the file cannot be opened or is empty
Note
Lines of different lengths are supported; shorter rows default to available

◆ operator()()

bool mazes::mask::operator() ( unsigned int row,
unsigned int column ) const
noexcept

Check if a cell at (row, column) is available.

Parameters
rowRow index
columnColumn index
Returns
true if available, false if blocked or out of bounds

◆ random_location()

std::pair< unsigned int, unsigned int > mazes::mask::random_location ( randomizer & rng) const
noexcept

Get a random available cell location.

Parameters
rngRandomizer to use
Returns
A pair (row, col) of a random available cell
Precondition
count() > 0 — callers must ensure at least one cell is available

◆ rows()

unsigned int mazes::mask::rows ( ) const
nodiscardnoexcept

Get the number of rows.

Returns
Number of rows

◆ set()

void mazes::mask::set ( unsigned int row,
unsigned int column,
bool is_on )
noexcept

Set a cell's availability.

Parameters
rowRow index
columnColumn index
is_ontrue to enable, false to block

The documentation for this class was generated from the following file: