[][src]Struct sweeper::Field

pub struct Field { /* fields omitted */ }

Represents a playfield.

Methods

impl Field[src]

#[must_use = "this performs a memory allocation as big as the area of the field"]pub fn empty(dimensions: FieldDimensions) -> Self[src]

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

pub fn populate(
    &mut self,
    mine_percentage: f64,
    safe_spot: Option<FieldCoordinates>
)
[src]

Adds mines with the selected percentage of mines and, optionally, a safe spot, which can never have any surrounding mines.

pub const fn dimensions(&self) -> FieldDimensions[src]

Returns the width and height of the field.

#[must_use = "traversing the entire field is obscenely expensive"]pub fn solved(&self) -> bool[src]

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

#[must_use = "traversing the entire field is obscenely expensive"]pub fn count_open_tiles(&self) -> usize[src]

Returns the amount of tiles which have been already opened.

#[must_use = "traversing the entire field is obscenely expensive"]pub fn count_closed_tiles(&self) -> usize[src]

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

#[must_use = "traversing the entire field is obscenely expensive"]pub fn tiles_to_open(&self) -> usize[src]

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.

#[must_use = "this is a rather complex lookup with 16 branch points"]pub fn count_neighboring_mines(&self, location: FieldCoordinates) -> u8[src]

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.

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

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

pub fn get(&self, coordinates: FieldCoordinates) -> Option<&Tile>[src]

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.

pub fn get_mut(&mut self, coordinates: FieldCoordinates) -> Option<&mut Tile>[src]

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.

pub fn peek(&self, coordinates: FieldCoordinates) -> Option<ClickOutcome>[src]

Returns the outcome of clicking the specified tile without affecting the field, or None if the index is out of bounds.

pub fn open(&mut self, coordinates: FieldCoordinates) -> Option<ClickOutcome>[src]

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.

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

Performs a chord on the specified tile.

Returns the oucomes for all 8 tiles touched.

pub fn recursive_chord(
    &mut self,
    index: FieldCoordinates
) -> Vec<RecursiveChordOutcome>
[src]

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

pub fn row(&self, row: usize) -> RowIter[src]

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.

pub fn column(&self, column: usize) -> ColumnIter[src]

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.

pub fn rows(&self) -> FieldRowsIter[src]

Returns an iterator over the field's columns.

pub fn columns(&self) -> FieldColumnsIter[src]

Returns an iterator over the field's columns.

pub fn clearing(&self, anchor_location: FieldCoordinates) -> Option<Clearing>[src]

Returns a Clearing on the specified Field, or None if the location has 1 or more neighboring mines or is out of bounds.

pub fn clearing_mut(
    &mut self,
    anchor_location: FieldCoordinates
) -> Option<ClearingMut>
[src]

Returns a ClearingMut on the specified Field, or None if the location has 1 or more neighboring mines or is out of bounds.

#[must_use = "calculating the 3BV value for any possible field requires traversing the entire field two times and opening clearings"]pub fn calculate_3bv(self) -> usize[src]

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

impl<'de> Deserialize<'de> for Field[src]

impl Index<[usize; 2]> for Field[src]

type Output = Tile

The returned type after indexing.

fn index(&self, coordinates: FieldCoordinates) -> &Self::Output[src]

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.

impl IndexMut<[usize; 2]> for Field[src]

fn index_mut(&mut self, coordinates: FieldCoordinates) -> &mut Self::Output[src]

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.

impl Serialize for Field[src]

Auto Trait Implementations

impl RefUnwindSafe for Field

impl Send for Field

impl Sync for Field

impl Unpin for Field

impl UnwindSafe for Field

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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