pub struct Field { /* private fields */ }
Expand description
Represents a playfield.
Implementations§
Source§impl Field
impl Field
Sourcepub fn empty(dimensions: FieldDimensions) -> Self
pub fn empty(dimensions: FieldDimensions) -> Self
Creates an empty field filled with unopened tiles, with the given dimensions.
Sourcepub fn populate(
&mut self,
mine_percentage: f64,
safe_spot: Option<FieldCoordinates>,
)
pub fn populate( &mut self, mine_percentage: f64, safe_spot: Option<FieldCoordinates>, )
Adds mines with the selected percentage of mines and, optionally, a safe spot, which can never have any surrounding mines.
Sourcepub const fn dimensions(&self) -> FieldDimensions
pub const fn dimensions(&self) -> FieldDimensions
Returns the width and height of the field.
Sourcepub fn solved(&self) -> bool
pub fn solved(&self) -> bool
Returns true
if the field is fully solved (game win condition), false
otherwise.
Sourcepub fn count_open_tiles(&self) -> usize
pub fn count_open_tiles(&self) -> usize
Returns the amount of tiles which have been already opened.
Sourcepub fn count_closed_tiles(&self) -> usize
pub fn count_closed_tiles(&self) -> usize
Returns the amount of tiles which have not been opened yet.
Sourcepub fn tiles_to_open(&self) -> usize
pub fn tiles_to_open(&self) -> usize
Returns the amount of tiles which the player needs to open in order to win the game.
This does not include already opened tiles and is not equal to the 3BV value for the field.
Sourcepub fn count_neighboring_mines(&self, location: FieldCoordinates) -> u8
pub fn count_neighboring_mines(&self, location: FieldCoordinates) -> u8
Counts all neigboring mines around a spot.
All directly and diagonally adjacent mines are considered neighboring. If the tile is a mine, the tile itself isn’t counted.
Sourcepub fn is_mine(&self, location: FieldCoordinates) -> Option<bool>
pub fn is_mine(&self, location: FieldCoordinates) -> Option<bool>
Detects whether a location is a mine, or None
if it’s out of bounds.
Sourcepub fn get(&self, coordinates: FieldCoordinates) -> Option<&Tile>
pub fn get(&self, coordinates: FieldCoordinates) -> Option<&Tile>
Returns the tile at the column index.0
and row index.1
, both starting at zero, or None
if the index is out of bounds.
This is the immutable version of get_mut
.
Sourcepub fn get_mut(&mut self, coordinates: FieldCoordinates) -> Option<&mut Tile>
pub fn get_mut(&mut self, coordinates: FieldCoordinates) -> Option<&mut Tile>
Returns a mutable reference to the tile at the column index.0
and row index.1
, both starting at zero, or None
if the index is out of bounds.
This is the mutable version of get
.
Sourcepub fn peek(&self, coordinates: FieldCoordinates) -> Option<ClickOutcome>
pub fn peek(&self, coordinates: FieldCoordinates) -> Option<ClickOutcome>
Returns the outcome of clicking the specified tile without affecting the field, or None
if the index is out of bounds.
Sourcepub fn open(&mut self, coordinates: FieldCoordinates) -> Option<ClickOutcome>
pub fn open(&mut self, coordinates: FieldCoordinates) -> Option<ClickOutcome>
Opens exactly one tile and returns the outcome of clicking it. Chords and clearings are not handled and must be executed manually.
Essentially, this replaces a ClosedEmpty
tile with either an OpenEmpty
or an OpenNumber
tile.
Sourcepub fn chord(&mut self, coordinates: FieldCoordinates) -> ChordOutcome
pub fn chord(&mut self, coordinates: FieldCoordinates) -> ChordOutcome
Performs a chord on the specified tile.
Returns the oucomes for all 8 tiles touched.
Sourcepub fn recursive_chord(
&mut self,
index: FieldCoordinates,
) -> Vec<RecursiveChordOutcome> ⓘ
pub fn recursive_chord( &mut self, index: FieldCoordinates, ) -> Vec<RecursiveChordOutcome> ⓘ
Performs a chord on the specified tile recursively, i.e. runs chords for all number tiles which were uncovered from chording.
The returned value contains one entry per chord operation
Sourcepub fn row(&self, row: usize) -> RowIter<'_> ⓘ
pub fn row(&self, row: usize) -> RowIter<'_> ⓘ
Returns an iterator over a single row.
Said iterator can then also be indexed, thus serving as a versatile reference to a specific row.
§Panics
Panics if the specified row is out of range.
Sourcepub fn column(&self, column: usize) -> ColumnIter<'_> ⓘ
pub fn column(&self, column: usize) -> ColumnIter<'_> ⓘ
Returns an iterator over a single column.
Said iterator can then also be indexed, thus serving as a versatile reference to a specific column.
§Panics
Panics if the specified column is out of range.
Sourcepub fn rows(&self) -> FieldRowsIter<'_> ⓘ
pub fn rows(&self) -> FieldRowsIter<'_> ⓘ
Returns an iterator over the field’s columns.
Sourcepub fn columns(&self) -> FieldColumnsIter<'_> ⓘ
pub fn columns(&self) -> FieldColumnsIter<'_> ⓘ
Returns an iterator over the field’s columns.
Sourcepub fn clearing(
&self,
anchor_location: FieldCoordinates,
) -> Option<Clearing<'_>>
pub fn clearing( &self, anchor_location: FieldCoordinates, ) -> Option<Clearing<'_>>
Returns a Clearing
on the specified Field
, or None
if the location has 1 or more neighboring mines or is out of bounds.
Sourcepub fn clearing_mut(
&mut self,
anchor_location: FieldCoordinates,
) -> Option<ClearingMut<'_>>
pub fn clearing_mut( &mut self, anchor_location: FieldCoordinates, ) -> Option<ClearingMut<'_>>
Returns a ClearingMut
on the specified Field
, or None
if the location has 1 or more neighboring mines or is out of bounds.
Sourcepub fn calculate_3bv(self) -> usize
pub fn calculate_3bv(self) -> usize
Calculates the smallest amount of clicks required to clear a field.
Since the field is modified in an undefined way in the process, it is taken by value.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Field
impl<'de> Deserialize<'de> for Field
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Index<[usize; 2]> for Field
impl Index<[usize; 2]> for Field
Source§impl IndexMut<[usize; 2]> for Field
impl IndexMut<[usize; 2]> for Field
Source§fn index_mut(&mut self, coordinates: FieldCoordinates) -> &mut Self::Output
fn index_mut(&mut self, coordinates: FieldCoordinates) -> &mut Self::Output
Returns the tile at the column index.0
and row index.1
, both starting at zero.
§Panics
Index checking is enabled for this method. For a version which returns an Option
instead of panicking if the index is out of bounds, see get_mut
.