mines
Loading...
Searching...
No Matches
Minefield Class Referenceexport
module mines

Field of cells, each being either a mine or a blank space. More...

Public Member Functions

CellType get_cell (std::uint32_t x, std::uint32_t y) const
 Get type of a cell at a position.
std::uint8_t mines_close_to_cell (std::uint32_t x, std::uint32_t y)
std::uint32_t get_width () const
 Get width.
std::uint32_t get_height () const
 Get height.
std::uint32_t get_mines () const
 Get the number of mines.
std::uint64_t position_to_index (std::uint32_t x, std::uint32_t y) const
 Convert the position of a cell to it's index in the cell list.
std::uint8_t close_mines_count (std::uint32_t x, std::uint32_t y) const
 Get the count of mines close to a cell.
std::vector< std::tuple< std::uint32_t, std::uint32_t > > get_adjacent (std::uint32_t x, std::uint32_t y)
 Get cells adjacent to a cell.

Static Public Member Functions

template<typename RandomEngine>
static Minefield generate (std::uint32_t width, std::uint32_t height, std::uint32_t mines, std::uint32_t start_x, std::uint32_t start_y, RandomEngine &random_engine)
 Construct a random minefield.
template<typename RandomEngine>
static Minefield generate_pure_skill (std::uint32_t width, std::uint32_t height, std::uint32_t mines, std::uint32_t start_x, std::uint32_t start_y, RandomEngine &random_engine)
 Construct a random minefield that does not require guessing to solve.
static Minefield from_cells (std::vector< CellType > cells, std::uint32_t width, std::uint32_t height)
 Construct a minefield from pregenerated cells.

Detailed Description

Field of cells, each being either a mine or a blank space.

Does not define other game elements, like flags or which cells are uncovered.

Member Function Documentation

◆ close_mines_count()

std::uint8_t Minefield::close_mines_count ( std::uint32_t x,
std::uint32_t y ) const
inline

Get the count of mines close to a cell.

Close mines are mines positioned on adjacent cells.

In game, this number is shown to the player on uncovered cells, typically unless it's equal to 0.

Parameters
xCell X position.
yCell Y position.
Returns
Count of close mines.

◆ from_cells()

Minefield Minefield::from_cells ( std::vector< CellType > cells,
std::uint32_t width,
std::uint32_t height )
inlinestatic

Construct a minefield from pregenerated cells.

Parameters
cellsList of cells.
widthWidth.
heightHeight.
Returns
Minefield.

◆ generate()

template<typename RandomEngine>
Minefield Minefield::generate ( std::uint32_t width,
std::uint32_t height,
std::uint32_t mines,
std::uint32_t start_x,
std::uint32_t start_y,
RandomEngine & random_engine )
inlinestatic

Construct a random minefield.

The cell at the starting position is guaranteed to not be a mine.

Parameters
widthWidth.
heightHeight.
minesAmount of mines to place on the field.
start_xX coordinate of starting position.
start_yY coordinate of starting position.
random_engineRandom engine used to generate the minefield. Must satisfy RandomNumberEngine.
Returns
Minefield.
Exceptions
TooManyMinesRequested generating more mines than it is possible given the size of the minefield.

◆ generate_pure_skill()

template<typename RandomEngine>
Minefield Minefield::generate_pure_skill ( std::uint32_t width,
std::uint32_t height,
std::uint32_t mines,
std::uint32_t start_x,
std::uint32_t start_y,
RandomEngine & random_engine )
inlinestatic

Construct a random minefield that does not require guessing to solve.

Like generate, but it's also guaranteed that a game with the minefield is possible to win without ever guessing.

Parameters
widthWidth.
heightHeight.
minesAmount of mines to place on the field.
start_xX position of the starting position.
start_yY position of the starting position.
random_engineRandom engine used to generate the minefield. Must satisfy RandomNumberEngine.
Returns
Minefield.
Exceptions
TooManyMinesRequested generating more mines than it is possible given the size of the minefield.

◆ get_adjacent()

std::vector< std::tuple< std::uint32_t, std::uint32_t > > Minefield::get_adjacent ( std::uint32_t x,
std::uint32_t y )
inline

Get cells adjacent to a cell.

A cell is adjacent to another if their coordinates differ by 1 on either the x axis, the y axis, or both. This means a cell is not adjacent to itself.

Parameters
xCell X position.
yCell Y position.
Returns
List of (x, y) coordinates of adjacent cells.

◆ get_cell()

CellType Minefield::get_cell ( std::uint32_t x,
std::uint32_t y ) const
inline

Get type of a cell at a position.

Parameters
xX position.
yY position.
Returns
Cell type.

◆ get_height()

std::uint32_t Minefield::get_height ( ) const
inline

Get height.

Returns
Height.

◆ get_mines()

std::uint32_t Minefield::get_mines ( ) const
inline

Get the number of mines.

Returns
Number of mines.

◆ get_width()

std::uint32_t Minefield::get_width ( ) const
inline

Get width.

Returns
Width.

◆ position_to_index()

std::uint64_t Minefield::position_to_index ( std::uint32_t x,
std::uint32_t y ) const
inline

Convert the position of a cell to it's index in the cell list.

Parameters
xX position.
yY position.
Returns
Index in the cell list.

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