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

Game board, including the minefield, placed flags and uncovered cells. More...

Public Member Functions

template<typename RandomEngine>
void generate_minefield (std::uint32_t start_x, std::uint32_t start_y, RandomEngine &random_engine)
 Generate a minefield and associate it with the board.
void uncover (std::uint32_t x, std::uint32_t y)
 Uncover a cell.
void flag (std::uint32_t x, std::uint32_t y)
 Place a flag on a cell.
void mark (std::uint32_t x, std::uint32_t y)
 Place a mark on a cell.
void reset (std::uint32_t x, std::uint32_t y)
 Reset flag or mark placed on a cell.
CellState get_state (std::uint32_t x, std::uint32_t y) const
 Get the current state of a cell.
const std::optional< Minefield > & get_minefield () const
 Get minefield.
std::uint32_t get_flags () const
 Get the number of flagged fields.
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::uint32_t get_covered_fields () const
 Get the number of covered fields.
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.

Static Public Member Functions

static Board create (std::uint32_t width, std::uint32_t height, std::uint32_t mines)
 Construct a board.
static Board from_minefield (Minefield minefield)
 Construct a board and associate it with a given minefield.

Detailed Description

Game board, including the minefield, placed flags and uncovered cells.

Member Function Documentation

◆ create()

Board Board::create ( std::uint32_t width,
std::uint32_t height,
std::uint32_t mines )
inlinestatic

Construct a board.

This does not associate a minefield with the board. generate_minefield must be called once before uncover to generate a minefield, otherwise NoMinefield will be thrown.

Parameters
widthWidth.
heightHeight.
minesNumber of mines.
Returns
New board.
Exceptions
TooManyMinesThe number of mines is more than what is possible given the size of the minefield.

◆ flag()

void Board::flag ( std::uint32_t x,
std::uint32_t y )
inline

Place a flag on a cell.

Does nothing if the cell is uncovered or already flagged.

Parameters
xCell X position.
yCell Y position.

◆ from_minefield()

Board Board::from_minefield ( Minefield minefield)
inlinestatic

Construct a board and associate it with a given minefield.

Parameters
minefieldMinefield.

◆ generate_minefield()

template<typename RandomEngine>
void Board::generate_minefield ( std::uint32_t start_x,
std::uint32_t start_y,
RandomEngine & random_engine )
inline

Generate a minefield and associate it with the board.

This uses Minefield::generate to generate the minefield, using the parameters (width, height, mines) of the board. If a minefield is already associated, it will be replaced with the new one.

Parameters
start_xX coordinate of starting position.
start_yY coordinate of starting position.
random_engineRandom engine used to generate the minefield. Must satisfy RandomNumberEngine.

◆ get_covered_fields()

std::uint32_t Board::get_covered_fields ( ) const
inline

Get the number of covered fields.

Returns
Number of covered fields.

◆ get_flags()

std::uint32_t Board::get_flags ( ) const
inline

Get the number of flagged fields.

Returns
Number of flagged fields.

◆ get_height()

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

Get height.

Returns
Height.

◆ get_minefield()

const std::optional< Minefield > & Board::get_minefield ( ) const
inline

Get minefield.

Returns
Minefield.

◆ get_mines()

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

Get the number of mines.

Returns
Number of mines.

◆ get_state()

CellState Board::get_state ( std::uint32_t x,
std::uint32_t y ) const
inline

Get the current state of a cell.

Parameters
xCell X position.
yCell Y position.
Returns
Cell state.

◆ get_width()

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

Get width.

Returns
Width.

◆ mark()

void Board::mark ( std::uint32_t x,
std::uint32_t y )
inline

Place a mark on a cell.

Does nothing if the cell is uncovered or already marked.

Parameters
xCell X position.
yCell Y position.

◆ position_to_index()

std::uint64_t Board::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
xCell X position.
yCell Y position.
Returns
Cell index in the list.

◆ reset()

void Board::reset ( std::uint32_t x,
std::uint32_t y )
inline

Reset flag or mark placed on a cell.

Does nothing if the cell is uncovered or not marked nor flagged.

Parameters
xCell X position.
yCell Y position.

◆ uncover()

void Board::uncover ( std::uint32_t x,
std::uint32_t y )
inline

Uncover a cell.

If the cell is not a mine and has no close mines, all adjacent cells that aren't flagged and aren't mines will be uncovered recursively.

Does nothing if the cell is already uncovered or flagged.

Parameters
xCell X position.
yCell Y position.
Exceptions
NoMinefieldThe board has no associated minefield.

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