Struct bitboard::Bitboard
[−]
[src]
pub struct Bitboard<N: Unsigned> { pub ptr: *mut u64, // some fields omitted }
A square bitboard of size NxN
, with alignment A
There are no aliases provided, but I suggest you create one for whatever application you have. Something like:
extern crate typenum; extern crate bitboard; use typenum::consts::U8; use bitboard::Bitboard; type Chessboard = bitboard::Bitboard<U8>; fn main() { let cc : Chessboard = Bitboard::new(); // ... }
Will save a lot of typing and will also probably prevent screwups.
Fields
ptr: *mut u64
Methods
impl<N: Unsigned> Bitboard<N>
[src]
fn new() -> Bitboard<N>
[src]
Construct a new, blank bitboard of size NxN
, with alignment A
Examples
extern crate typenum; extern crate bitboard; use typenum::consts::U8; use bitboard::Bitboard; fn main() { let bb = Bitboard::<U8>::new(); // ... }
fn set(&mut self, x: usize, y: usize) -> Result<(), BitboardError>
[src]
Set the bit at location (x,y)
Origin is in the top-left, starting at 0, high values of x
move to the right, high values
of y
move downward.
Examples
extern crate typenum; extern crate bitboard; use typenum::consts::U3; use bitboard::Bitboard; type TicTacToe = bitboard::Bitboard<U3>; fn main() { let mut x_positions : TicTacToe = Bitboard::new(); // X has taken no positions // 000 // 000 // 000 assert!(!x_positions.is_set(1,1).ok().unwrap()); // the center square is free! x_positions.set(1,1); // take the center square // x_positions now looks like: // 000 // 010 // 000 assert!(x_positions.is_set(1,1).ok().unwrap()); // ... snip }
fn is_set(&self, x: usize, y: usize) -> Result<bool, BitboardError>
[src]
Returns true if the bit at the given coords is set, false otherwise. May error out if given out-of-bounds coordinates. See #set for examples
fn any_set(&self) -> bool
[src]
fn flip(&mut self, x: usize, y: usize) -> Result<(), BitboardError>
[src]
Flip the value of the bit at (x,y)
Examples
extern crate typenum; extern crate bitboard; use typenum::consts::U3; use bitboard::Bitboard; type TicTacToe = bitboard::Bitboard<U3>; fn main() { let mut x_positions : TicTacToe = Bitboard::new(); // X has taken no positions // 000 // 000 // 000 assert!(!x_positions.is_set(1,1).ok().unwrap()); // the center square is free! x_positions.flip(1,1); // take the center square // x_positions now looks like: // 000 // 010 // 000 assert!(x_positions.is_set(1,1).ok().unwrap()); x_positions.flip(1,1); // undo that assert!(!x_positions.is_set(1,1).ok().unwrap()); }
fn unset(&mut self, x: usize, y: usize) -> Result<(), BitboardError>
[src]
Unset the bit at location (x,y)
fn is_unset(&self, x: usize, y: usize) -> Result<bool, BitboardError>
[src]
Returns true if the bit at the given coords is set, false otherwise. May error out if given out-of-bounds coordinates. See #set for examples
fn alignment() -> usize
[src]
Return the alignment, in bytes, of the Bitboard
# Examples
extern crate typenum; extern crate bitboard; use typenum::consts::U8; use bitboard::Bitboard; fn main() { assert_eq!(Bitboard::<U8>::alignment(), 8); }
fn alignment_bits() -> usize
[src]
Return the alignment, in bits, of the Bitboard
# Examples
extern crate typenum; extern crate bitboard; use typenum::consts::U8; use bitboard::Bitboard; fn main() { assert_eq!(Bitboard::<U8>::alignment_bits(), 64); }
fn byte_size() -> usize
[src]
Return the size, in bytes, needed to allocate the bitboard.
# Examples
extern crate typenum; extern crate bitboard; use typenum::consts::{U8,U19}; use bitboard::Bitboard; fn main() { // chess boards assert_eq!(Bitboard::<U8>::byte_size(), 8); // go boards assert_eq!(Bitboard::<U19>::byte_size(), 48); }
Trait Implementations
impl<N: Unsigned> Drop for Bitboard<N>
[src]
impl<N: Unsigned> Debug for Bitboard<N>
[src]
impl<N: Unsigned> Display for Bitboard<N>
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<N: Unsigned> PartialEq for Bitboard<N>
[src]
fn eq(&self, other: &Bitboard<N>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<N: Unsigned> Eq for Bitboard<N>
[src]
impl<N: Unsigned> Hash for Bitboard<N>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<N: Unsigned> Clone for Bitboard<N>
[src]
fn clone(&self) -> Bitboard<N>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<N: Unsigned> BitAnd for Bitboard<N>
[src]
type Output = Bitboard<N>
The resulting type after applying the &
operator.
fn bitand(self, other: Bitboard<N>) -> Bitboard<N>
[src]
Performs the &
operation.
impl<N: Unsigned> BitAndAssign for Bitboard<N>
[src]
fn bitand_assign(&mut self, other: Bitboard<N>)
[src]
Performs the &=
operation.
impl<N: Unsigned> BitOr for Bitboard<N>
[src]
type Output = Bitboard<N>
The resulting type after applying the |
operator.
fn bitor(self, other: Bitboard<N>) -> Bitboard<N>
[src]
Performs the |
operation.
impl<N: Unsigned> BitOrAssign for Bitboard<N>
[src]
fn bitor_assign(&mut self, other: Bitboard<N>)
[src]
Performs the |=
operation.
impl<N: Unsigned> BitXor for Bitboard<N>
[src]
type Output = Bitboard<N>
The resulting type after applying the ^
operator.
fn bitxor(self, other: Bitboard<N>) -> Bitboard<N>
[src]
Performs the ^
operation.
impl<N: Unsigned> BitXorAssign for Bitboard<N>
[src]
fn bitxor_assign(&mut self, other: Bitboard<N>)
[src]
Performs the ^=
operation.