Maze Builder Docs 8.2.1
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
 
maskoperator= (const mask &)=default
 
 mask (mask &&) noexcept=default
 
maskoperator= (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.
 

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
inlinenodiscardnoexcept

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_txt()

static 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
inlinenodiscardnoexcept

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: