Struct magpie::othello::Position

source ·
pub struct Position(/* private fields */);
Expand description

Represents a single position on a 8x8 board as a u64.

Unlike the similar Bitboard which places no restrictions on the bits it represents, this struct represents exactly a single set bit.

Bitboard representations are quite inconvenient in some contexts which is why some convenience functions are provided to convert between different formats. In these contexts, MSB denotes A1 while LSB denotes H8, as can be seen in the graphic below.

    A    B    C    D    E    F    G    H
  +----+----+----+----+----+----+----+----+
1 | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 |
  +----+----+----+----+----+----+----+----+
2 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 |
  +----+----+----+----+----+----+----+----+
3 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
  +----+----+----+----+----+----+----+----+
4 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
  +----+----+----+----+----+----+----+----+
5 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
  +----+----+----+----+----+----+----+----+
6 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
  +----+----+----+----+----+----+----+----+
7 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
  +----+----+----+----+----+----+----+----+
8 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
  +----+----+----+----+----+----+----+----+

Implementations§

source§

impl Position

source

pub fn raw(self) -> u64

Retrieves the underlying u64.

§Examples
use magpie::othello::Position;

let p: Position = (1 << 32).try_into().unwrap();
assert_eq!(p.raw(), (1 << 32));
source

pub fn rank(self) -> u8

Calculates the zero-indexed rank the position is referring to.

How ranks and files are represented can be found in the top-level documentation for Position.

§Examples
use magpie::othello::Position;

let rank_and_file = (3, 4);
let p = Position::try_from(rank_and_file).unwrap();
assert_eq!(p.rank(), rank_and_file.0);
assert_eq!(p.file(), rank_and_file.1);
source

pub fn file(self) -> u8

Calculates the zero-indexed file the position is referring to.

How ranks and files are represented can be found in the top-level documentation for Position.

§Examples
use magpie::othello::Position;

let rank_and_file = (3, 4);
let p = Position::try_from(rank_and_file).unwrap();
assert_eq!(p.rank(), rank_and_file.0);
assert_eq!(p.file(), rank_and_file.1);
source

pub fn to_notation(self) -> String

Calculates a human-readable board position.

How board positions are represented can be found in the top-level documentation for Position.

§Examples
use magpie::othello::Position;

let notation = "A1";
let p = Position::try_from(notation).unwrap();
assert_eq!(p.to_notation().to_lowercase(), notation.to_lowercase());

Trait Implementations§

source§

impl BitAnd<Bitboard> for Position

§

type Output = Bitboard

The resulting type after applying the & operator.
source§

fn bitand(self, Bitboard: Bitboard) -> Self::Output

Performs the & operation. Read more
source§

impl BitAnd<Position> for Bitboard

§

type Output = Bitboard

The resulting type after applying the & operator.
source§

fn bitand(self, Position: Position) -> Self::Output

Performs the & operation. Read more
source§

impl BitAnd<Position> for u64

§

type Output = u64

The resulting type after applying the & operator.
source§

fn bitand(self, Position: Position) -> Self::Output

Performs the & operation. Read more
source§

impl BitAnd for Position

§

type Output = Position

The resulting type after applying the & operator.
source§

fn bitand(self, Position: Position) -> Self::Output

Performs the & operation. Read more
source§

impl BitAndAssign<Bitboard> for Position

source§

fn bitand_assign(&mut self, Bitboard: Bitboard)

Performs the &= operation. Read more
source§

impl BitAndAssign<Position> for Bitboard

source§

fn bitand_assign(&mut self, Position: Position)

Performs the &= operation. Read more
source§

impl BitAndAssign<Position> for u64

source§

fn bitand_assign(&mut self, Position: Position)

Performs the &= operation. Read more
source§

impl BitOr<Bitboard> for Position

§

type Output = Bitboard

The resulting type after applying the | operator.
source§

fn bitor(self, Bitboard: Bitboard) -> Self::Output

Performs the | operation. Read more
source§

impl BitOr<Position> for Bitboard

§

type Output = Bitboard

The resulting type after applying the | operator.
source§

fn bitor(self, Position: Position) -> Self::Output

Performs the | operation. Read more
source§

impl BitOr<Position> for u64

§

type Output = u64

The resulting type after applying the | operator.
source§

fn bitor(self, Position: Position) -> Self::Output

Performs the | operation. Read more
source§

impl BitOrAssign<Position> for Bitboard

source§

fn bitor_assign(&mut self, Position: Position)

Performs the |= operation. Read more
source§

impl BitOrAssign<Position> for u64

source§

fn bitor_assign(&mut self, Position: Position)

Performs the |= operation. Read more
source§

impl BitXor<Bitboard> for Position

§

type Output = Bitboard

The resulting type after applying the ^ operator.
source§

fn bitxor(self, Bitboard: Bitboard) -> Self::Output

Performs the ^ operation. Read more
source§

impl BitXor<Position> for Bitboard

§

type Output = Bitboard

The resulting type after applying the ^ operator.
source§

fn bitxor(self, Position: Position) -> Self::Output

Performs the ^ operation. Read more
source§

impl BitXor<Position> for u64

§

type Output = u64

The resulting type after applying the ^ operator.
source§

fn bitxor(self, Position: Position) -> Self::Output

Performs the ^ operation. Read more
source§

impl BitXorAssign<Position> for Bitboard

source§

fn bitxor_assign(&mut self, Position: Position)

Performs the ^= operation. Read more
source§

impl BitXorAssign<Position> for u64

source§

fn bitxor_assign(&mut self, Position: Position)

Performs the ^= operation. Read more
source§

impl Clone for Position

source§

fn clone(&self) -> Position

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Position

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Position

source§

fn default() -> Position

Returns the “default value” for a type. Read more
source§

impl From<Position> for Bitboard

source§

fn from(position: Position) -> Self

Converts to this type from the input type.
source§

impl From<Position> for u64

source§

fn from(position: Position) -> Self

Converts to this type from the input type.
source§

impl Hash for Position

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Position

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Bitboard> for Position

source§

fn eq(&self, b: &Bitboard) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Position> for Bitboard

source§

fn eq(&self, b: &Position) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Position> for u64

source§

fn eq(&self, b: &Position) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u64> for Position

source§

fn eq(&self, b: &u64) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for Position

source§

fn eq(&self, b: &Position) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Bitboard> for Position

source§

fn partial_cmp(&self, b: &Bitboard) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<Position> for Bitboard

source§

fn partial_cmp(&self, b: &Position) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<Position> for u64

source§

fn partial_cmp(&self, b: &Position) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<u64> for Position

source§

fn partial_cmp(&self, b: &u64) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd for Position

source§

fn partial_cmp(&self, b: &Position) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Shl<i128> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: i128) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<i16> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: i16) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<i32> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: i32) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<i64> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: i64) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<i8> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: i8) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<isize> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: isize) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<u128> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: u128) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<u16> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: u16) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<u32> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: u32) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<u64> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: u64) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<u8> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: u8) -> Self::Output

Performs the << operation. Read more
source§

impl Shl<usize> for Position

§

type Output = Position

The resulting type after applying the << operator.
source§

fn shl(self, b: usize) -> Self::Output

Performs the << operation. Read more
source§

impl ShlAssign<i128> for Position

source§

fn shl_assign(&mut self, b: i128)

Performs the <<= operation. Read more
source§

impl ShlAssign<i16> for Position

source§

fn shl_assign(&mut self, b: i16)

Performs the <<= operation. Read more
source§

impl ShlAssign<i32> for Position

source§

fn shl_assign(&mut self, b: i32)

Performs the <<= operation. Read more
source§

impl ShlAssign<i64> for Position

source§

fn shl_assign(&mut self, b: i64)

Performs the <<= operation. Read more
source§

impl ShlAssign<i8> for Position

source§

fn shl_assign(&mut self, b: i8)

Performs the <<= operation. Read more
source§

impl ShlAssign<isize> for Position

source§

fn shl_assign(&mut self, b: isize)

Performs the <<= operation. Read more
source§

impl ShlAssign<u128> for Position

source§

fn shl_assign(&mut self, b: u128)

Performs the <<= operation. Read more
source§

impl ShlAssign<u16> for Position

source§

fn shl_assign(&mut self, b: u16)

Performs the <<= operation. Read more
source§

impl ShlAssign<u32> for Position

source§

fn shl_assign(&mut self, b: u32)

Performs the <<= operation. Read more
source§

impl ShlAssign<u64> for Position

source§

fn shl_assign(&mut self, b: u64)

Performs the <<= operation. Read more
source§

impl ShlAssign<u8> for Position

source§

fn shl_assign(&mut self, b: u8)

Performs the <<= operation. Read more
source§

impl ShlAssign<usize> for Position

source§

fn shl_assign(&mut self, b: usize)

Performs the <<= operation. Read more
source§

impl Shr<i128> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: i128) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<i16> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: i16) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<i32> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: i32) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<i64> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: i64) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<i8> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: i8) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<isize> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: isize) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<u128> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: u128) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<u16> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: u16) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<u32> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: u32) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<u64> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: u64) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<u8> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: u8) -> Self::Output

Performs the >> operation. Read more
source§

impl Shr<usize> for Position

§

type Output = Position

The resulting type after applying the >> operator.
source§

fn shr(self, b: usize) -> Self::Output

Performs the >> operation. Read more
source§

impl ShrAssign<i128> for Position

source§

fn shr_assign(&mut self, b: i128)

Performs the >>= operation. Read more
source§

impl ShrAssign<i16> for Position

source§

fn shr_assign(&mut self, b: i16)

Performs the >>= operation. Read more
source§

impl ShrAssign<i32> for Position

source§

fn shr_assign(&mut self, b: i32)

Performs the >>= operation. Read more
source§

impl ShrAssign<i64> for Position

source§

fn shr_assign(&mut self, b: i64)

Performs the >>= operation. Read more
source§

impl ShrAssign<i8> for Position

source§

fn shr_assign(&mut self, b: i8)

Performs the >>= operation. Read more
source§

impl ShrAssign<isize> for Position

source§

fn shr_assign(&mut self, b: isize)

Performs the >>= operation. Read more
source§

impl ShrAssign<u128> for Position

source§

fn shr_assign(&mut self, b: u128)

Performs the >>= operation. Read more
source§

impl ShrAssign<u16> for Position

source§

fn shr_assign(&mut self, b: u16)

Performs the >>= operation. Read more
source§

impl ShrAssign<u32> for Position

source§

fn shr_assign(&mut self, b: u32)

Performs the >>= operation. Read more
source§

impl ShrAssign<u64> for Position

source§

fn shr_assign(&mut self, b: u64)

Performs the >>= operation. Read more
source§

impl ShrAssign<u8> for Position

source§

fn shr_assign(&mut self, b: u8)

Performs the >>= operation. Read more
source§

impl ShrAssign<usize> for Position

source§

fn shr_assign(&mut self, b: usize)

Performs the >>= operation. Read more
source§

impl TryFrom<&str> for Position

source§

fn try_from(text: &str) -> Result<Self, Self::Error>

Constructs a position from human-readable notation.

Returns an error if the notation is invalid.

The conversion is case-insensitive.

How board positions are represented can be found in the top-level documentation for Position.

§Examples
use magpie::othello::Position;

let notation = "A1";
let p = Position::try_from(notation).unwrap();
assert_eq!(p.to_notation().to_lowercase(), notation.to_lowercase());
§

type Error = PositionError

The type returned in the event of a conversion error.
source§

impl TryFrom<(u8, u8)> for Position

source§

fn try_from(pair: (u8, u8)) -> Result<Self, Self::Error>

Constructs a position from a zero-indexed rank and file pair.

Returns an error if either the rank or file does not fit into a 8x8 board.

How ranks and files are represented can be found in the top-level documentation for Position.

§Examples
use magpie::othello::Position;

let rank_and_file = (3, 4);
let p = Position::try_from(rank_and_file).unwrap();
assert_eq!(p.rank(), rank_and_file.0);
assert_eq!(p.file(), rank_and_file.1);
§

type Error = PositionError

The type returned in the event of a conversion error.
source§

impl TryFrom<Bitboard> for Position

source§

fn try_from(bitboard: Bitboard) -> Result<Self, Self::Error>

Constructs a position from a Bitboard.

Returns an error if the Bitboard does not have exactly one bit set.

§Examples
use magpie::othello::{Bitboard, Position};

let bitboard = Bitboard::from(1 << 32);
let p = Position::try_from(bitboard).unwrap();
assert_eq!(p.raw(), bitboard);
§

type Error = PositionError

The type returned in the event of a conversion error.
source§

impl TryFrom<String> for Position

source§

fn try_from(text: String) -> Result<Self, Self::Error>

Constructs a position from human-readable notation.

Returns an error if the notation is invalid.

The conversion is case-insensitive.

How board positions are represented can be found in the top-level documentation for Position.

§Examples
use magpie::othello::Position;

let notation = "A1";
let p = Position::try_from(notation).unwrap();
assert_eq!(p.to_notation().to_lowercase(), notation.to_lowercase());
§

type Error = PositionError

The type returned in the event of a conversion error.
source§

impl TryFrom<u64> for Position

source§

fn try_from(bitboard: u64) -> Result<Self, Self::Error>

Constructs a position from a u64.

Returns an error if the u64 does not have exactly one bit set.

§Examples
use magpie::othello::Position;

let num = 1 << 32;
let p = Position::try_from(num).unwrap();
assert_eq!(p.raw(), num);
§

type Error = PositionError

The type returned in the event of a conversion error.
source§

impl Copy for Position

source§

impl Eq for Position

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.