[−][src]Struct sweeper::Field
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(width: NonZeroUsize, height: NonZeroUsize) -> 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<(usize, usize)>
)
[src]
&mut self,
mine_percentage: f64,
safe_spot: Option<(usize, usize)>
)
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) -> (NonZeroUsize, NonZeroUsize)
[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: (usize, usize)) -> 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: (usize, usize)) -> Option<bool>
[src]
Detects whether a location is a mine, or None
if it's out of bounds.
pub fn get(&self, index: (usize, usize)) -> 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, index: (usize, usize)) -> 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, index: (usize, usize)) -> 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, index: (usize, usize)) -> 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, index: (usize, usize)) -> [ClickOutcome; 8]
[src]
Performs a chord on the specified tile. Optionally can
Returns the oucomes for all 8 tiles touched.
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.
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.
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: (usize, usize)) -> 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: (usize, usize)
) -> Option<ClearingMut>
[src]
&mut self,
anchor_location: (usize, usize)
) -> 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.
#[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]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Index<(usize, usize)> for Field
[src]
type Output = Tile
The returned type after indexing.
fn index(&self, index: (usize, usize)) -> &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, usize)> for Field
[src]
fn index_mut(&mut self, index: (usize, usize)) -> &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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,