Struct Field

Source
pub struct Field { /* private fields */ }
Expand description

Represents a playfield.

Implementations§

Source§

impl Field

Source

pub fn empty(dimensions: FieldDimensions) -> Self

Creates an empty field filled with unopened tiles, with the given dimensions.

Source

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.

Source

pub const fn dimensions(&self) -> FieldDimensions

Returns the width and height of the field.

Source

pub fn solved(&self) -> bool

Returns true if the field is fully solved (game win condition), false otherwise.

Source

pub fn count_open_tiles(&self) -> usize

Returns the amount of tiles which have been already opened.

Source

pub fn count_closed_tiles(&self) -> usize

Returns the amount of tiles which have not been opened yet.

Source

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.

Source

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.

Source

pub fn is_mine(&self, location: FieldCoordinates) -> Option<bool>

Detects whether a location is a mine, or None if it’s out of bounds.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn chord(&mut self, coordinates: FieldCoordinates) -> ChordOutcome

Performs a chord on the specified tile.

Returns the oucomes for all 8 tiles touched.

Source

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

Source

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.

Source

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.

Source

pub fn rows(&self) -> FieldRowsIter<'_>

Returns an iterator over the field’s columns.

Source

pub fn columns(&self) -> FieldColumnsIter<'_>

Returns an iterator over the field’s columns.

Source

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.

Source

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.

Source

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

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Index<[usize; 2]> for Field

Source§

fn index(&self, coordinates: FieldCoordinates) -> &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.

Source§

type Output = Tile

The returned type after indexing.
Source§

impl IndexMut<[usize; 2]> for Field

Source§

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.

Source§

impl Serialize for Field

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Field

§

impl RefUnwindSafe for Field

§

impl Send for Field

§

impl Sync for Field

§

impl Unpin for Field

§

impl UnwindSafe for Field

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,