[][src]Trait magpie::othello::SquareExt

pub trait SquareExt: Sized {
    type Iter: Iterator<Item = Self>;
    pub fn squares(&self) -> Self::Iter;
}

Extension trait that extracts all bits from a bitboard.

Associated Types

type Iter: Iterator<Item = Self>[src]

Loading content...

Required methods

pub fn squares(&self) -> Self::Iter[src]

Given a bitboard, extracts each bit as its own bitboard.

For example, given the following (tiny) bitboard:

111
000
111

The iterator will break up that bitboard and yield the following bitboards:

100    010    001    000    000    000    000    000    000
000 => 000 => 000 => 000 => 000 => 000 => 000 => 000 => 000
000    000    000    000    000    000    100    010    001

The iterator always return 64 bitboards since Othello has 64 positions.

StoneExt is a similar extension trait which may be of use as well.

Examples

use magpie::othello::{OthelloBoard, SquareExt};

let mut board = OthelloBoard::standard();
let pos = u64::MAX // Full bitboard (all bits set to 1)
    .squares() // Convert that into multiple bitboards
    .next()
    .unwrap(); // Othello has 64 positions which means that this
               // iterator will always return 64 bitboards
assert_eq!(2_u64.pow(63), pos);
Loading content...

Implementations on Foreign Types

impl SquareExt for u64[src]

type Iter = Box<dyn Iterator<Item = u64>>

Loading content...

Implementors

Loading content...