Struct open_ttt_lib::board::Board [−][src]
pub struct Board { /* fields omitted */ }
Expand description
Represents the Tic Tac Toe board providing multiple ways to access individual squares.
Implementations
impl Board
[src]
impl Board
[src]pub fn contains(&self, position: Position) -> bool
[src]
pub fn contains(&self, position: Position) -> bool
[src]Returns true
if the board contains the given position.
Note positions are zero based.
Examples
use open_ttt_lib::board; let b = board::Board::new(board::Size::from((3, 3))); assert!(b.contains(board::Position { row: 2, column: 2 })); // Since the positions are zero indexed, the board does not // contain the following position. assert!(!b.contains(board::Position { row: 3, column: 3 })); // A negative row or column is also not contained in the board. assert!(!b.contains(board::Position { row: -1, column: -1 }));
pub fn get(&self, position: Position) -> Option<Owner>
[src]
pub fn get(&self, position: Position) -> Option<Owner>
[src]Returns a copy of the owner at the indicated position, or None
if the board does not contain the provided position.
Examples
use open_ttt_lib::board; let b = board::Board::new(board::Size::from((3, 3))); assert!(b.get(board::Position { row: 0, column: 0 }).is_some()); assert!(b.get(board::Position { row: -1, column: -1 }).is_none());
pub fn get_mut(&mut self, position: Position) -> Option<&mut Owner>
[src]
pub fn get_mut(&mut self, position: Position) -> Option<&mut Owner>
[src]Gets a mutable reference to the owner at the indicated position.
This allows the owner of the position to be changed. None
is returned
if the board does not contain the provided position.
Examples
use open_ttt_lib::board; let mut b = board::Board::new(board::Size::from((3, 3))); let position = board::Position { row: 2, column: 2 }; // Change the owner of the position to Player X. if let Some(owner) = b.get_mut(position) { *owner = board::Owner::PlayerX; } assert_eq!(b.get(position), Some(board::Owner::PlayerX));
pub fn iter(&self) -> Iter<'_>ⓘ
[src]
pub fn iter(&self) -> Iter<'_>ⓘ
[src]Gets an iterator over all the positions in the board.
The iterator provides tuples containing the position and the owner of the position. The items are returned in arbitrary order.
Examples
use open_ttt_lib::board; let b = board::Board::new(board::Size::from((3, 3))); // Print the owner of every position. for (position, owner) in b.iter() { println!("{:?} is owned by {:?}", position, owner); }
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Board
impl Send for Board
impl Sync for Board
impl Unpin for Board
impl UnwindSafe for Board
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,