pub struct Square(_);
Expand description
Represent a square on the chess board
Implementations§
source§impl Square
impl Square
sourcepub unsafe fn new(sq: u8) -> Square
pub unsafe fn new(sq: u8) -> Square
Create a new square, given an index. Note: It is invalid, but allowed, to pass in a number >= 64. Doing so will crash stuff.
use candidate::{Square, Rank, File, EMPTY};
assert_eq!(unsafe { Square::new(0) }, Square::default());
let bad_sq = unsafe { Square::new(64) };
// Iterate over all possible squares and ensure that *none* of them are equal to `bad_sq`.
for sq in !EMPTY {
assert_ne!(bad_sq, sq);
}
sourcepub fn make_square(rank: Rank, file: File) -> Square
pub fn make_square(rank: Rank, file: File) -> Square
Make a square given a rank and a file
use candidate::{Square, Rank, File, BitBoard};
// Make the A1 square
let sq = Square::make_square(Rank::First, File::A);
// Convert it to a bitboard
let bb = BitBoard::from_square(sq);
// loop over all squares in the bitboard (should be only one), and ensure that the square
// is what we created
for x in bb {
assert_eq!(sq, x);
}
sourcepub fn get_rank(&self) -> Rank
pub fn get_rank(&self) -> Rank
Return the rank given this square.
use candidate::{Square, Rank, File};
let sq = Square::make_square(Rank::Seventh, File::D);
assert_eq!(sq.get_rank(), Rank::Seventh);
sourcepub fn get_file(&self) -> File
pub fn get_file(&self) -> File
Return the file given this square.
use candidate::{Square, Rank, File};
let sq = Square::make_square(Rank::Seventh, File::D);
assert_eq!(sq.get_file(), File::D);
sourcepub fn up(&self) -> Option<Square>
pub fn up(&self) -> Option<Square>
If there is a square above me, return that. Otherwise, None.
use candidate::{Square, Rank, File};
let sq = Square::make_square(Rank::Seventh, File::D);
assert_eq!(sq.up().expect("Valid Square"), Square::make_square(Rank::Eighth, File::D));
assert_eq!(sq.up().expect("Valid Square").up(), None);
sourcepub fn down(&self) -> Option<Square>
pub fn down(&self) -> Option<Square>
If there is a square below me, return that. Otherwise, None.
use candidate::{Square, Rank, File};
let sq = Square::make_square(Rank::Second, File::D);
assert_eq!(sq.down().expect("Valid Square"), Square::make_square(Rank::First, File::D));
assert_eq!(sq.down().expect("Valid Square").down(), None);
sourcepub fn left(&self) -> Option<Square>
pub fn left(&self) -> Option<Square>
If there is a square to the left of me, return that. Otherwise, None.
use candidate::{Square, Rank, File};
let sq = Square::make_square(Rank::Seventh, File::B);
assert_eq!(sq.left().expect("Valid Square"), Square::make_square(Rank::Seventh, File::A));
assert_eq!(sq.left().expect("Valid Square").left(), None);
sourcepub fn right(&self) -> Option<Square>
pub fn right(&self) -> Option<Square>
If there is a square to the right of me, return that. Otherwise, None.
use candidate::{Square, Rank, File};
let sq = Square::make_square(Rank::Seventh, File::G);
assert_eq!(sq.right().expect("Valid Square"), Square::make_square(Rank::Seventh, File::H));
assert_eq!(sq.right().expect("Valid Square").right(), None);
sourcepub fn forward(&self, color: Color) -> Option<Square>
pub fn forward(&self, color: Color) -> Option<Square>
If there is a square “forward”, given my Color
, go in that direction. Otherwise, None.
use candidate::{Square, Rank, File, Color};
let mut sq = Square::make_square(Rank::Seventh, File::D);
assert_eq!(sq.forward(Color::White).expect("Valid Square"), Square::make_square(Rank::Eighth, File::D));
assert_eq!(sq.forward(Color::White).expect("Valid Square").forward(Color::White), None);
sq = Square::make_square(Rank::Second, File::D);
assert_eq!(sq.forward(Color::Black).expect("Valid Square"), Square::make_square(Rank::First, File::D));
assert_eq!(sq.forward(Color::Black).expect("Valid Square").forward(Color::Black), None);
sourcepub fn backward(&self, color: Color) -> Option<Square>
pub fn backward(&self, color: Color) -> Option<Square>
If there is a square “backward” given my Color
, go in that direction. Otherwise, None.
use candidate::{Square, Rank, File, Color};
let mut sq = Square::make_square(Rank::Seventh, File::D);
assert_eq!(sq.backward(Color::Black).expect("Valid Square"), Square::make_square(Rank::Eighth, File::D));
assert_eq!(sq.backward(Color::Black).expect("Valid Square").backward(Color::Black), None);
sq = Square::make_square(Rank::Second, File::D);
assert_eq!(sq.backward(Color::White).expect("Valid Square"), Square::make_square(Rank::First, File::D));
assert_eq!(sq.backward(Color::White).expect("Valid Square").backward(Color::White), None);
sourcepub fn uup(&self) -> Square
pub fn uup(&self) -> Square
If there is a square above me, return that. If not, wrap around to the other side.
use candidate::{Square, Rank, File};
let sq = Square::make_square(Rank::Seventh, File::D);
assert_eq!(sq.uup(), Square::make_square(Rank::Eighth, File::D));
assert_eq!(sq.uup().uup(), Square::make_square(Rank::First, File::D));
sourcepub fn udown(&self) -> Square
pub fn udown(&self) -> Square
If there is a square below me, return that. If not, wrap around to the other side.
use candidate::{Square, Rank, File};
let sq = Square::make_square(Rank::Second, File::D);
assert_eq!(sq.udown(), Square::make_square(Rank::First, File::D));
assert_eq!(sq.udown().udown(), Square::make_square(Rank::Eighth, File::D));
sourcepub fn uleft(&self) -> Square
pub fn uleft(&self) -> Square
If there is a square to the left of me, return that. If not, wrap around to the other side.
use candidate::{Square, Rank, File};
let sq = Square::make_square(Rank::Seventh, File::B);
assert_eq!(sq.uleft(), Square::make_square(Rank::Seventh, File::A));
assert_eq!(sq.uleft().uleft(), Square::make_square(Rank::Seventh, File::H));
sourcepub fn uright(&self) -> Square
pub fn uright(&self) -> Square
If there is a square to the right of me, return that. If not, wrap around to the other side.
use candidate::{Square, Rank, File};
let sq = Square::make_square(Rank::Seventh, File::G);
assert_eq!(sq.uright(), Square::make_square(Rank::Seventh, File::H));
assert_eq!(sq.uright().uright(), Square::make_square(Rank::Seventh, File::A));
sourcepub fn uforward(&self, color: Color) -> Square
pub fn uforward(&self, color: Color) -> Square
If there is a square “forward”, given my color, return that. If not, wrap around to the other side.
use candidate::{Square, Rank, File, Color};
let mut sq = Square::make_square(Rank::Seventh, File::D);
assert_eq!(sq.uforward(Color::White), Square::make_square(Rank::Eighth, File::D));
assert_eq!(sq.uforward(Color::White).uforward(Color::White), Square::make_square(Rank::First, File::D));
sq = Square::make_square(Rank::Second, File::D);
assert_eq!(sq.uforward(Color::Black), Square::make_square(Rank::First, File::D));
assert_eq!(sq.uforward(Color::Black).uforward(Color::Black), Square::make_square(Rank::Eighth, File::D));
sourcepub fn ubackward(&self, color: Color) -> Square
pub fn ubackward(&self, color: Color) -> Square
If there is a square “backward”, given my color, return that. If not, wrap around to the other side.
use candidate::{Square, Rank, File, Color};
let mut sq = Square::make_square(Rank::Seventh, File::D);
assert_eq!(sq.ubackward(Color::Black), Square::make_square(Rank::Eighth, File::D));
assert_eq!(sq.ubackward(Color::Black).ubackward(Color::Black), Square::make_square(Rank::First, File::D));
sq = Square::make_square(Rank::Second, File::D);
assert_eq!(sq.ubackward(Color::White), Square::make_square(Rank::First, File::D));
assert_eq!(sq.ubackward(Color::White).ubackward(Color::White), Square::make_square(Rank::Eighth, File::D));
sourcepub fn to_int(&self) -> u8
pub fn to_int(&self) -> u8
Convert this square to an integer.
use candidate::{Square, Rank, File};
assert_eq!(Square::make_square(Rank::First, File::A).to_int(), 0);
assert_eq!(Square::make_square(Rank::Second, File::A).to_int(), 8);
assert_eq!(Square::make_square(Rank::First, File::B).to_int(), 1);
assert_eq!(Square::make_square(Rank::Eighth, File::H).to_int(), 63);
sourcepub fn to_index(&self) -> usize
pub fn to_index(&self) -> usize
Convert this Square
to a usize
for table lookup purposes
use candidate::{Square, Rank, File};
assert_eq!(Square::make_square(Rank::First, File::A).to_index(), 0);
assert_eq!(Square::make_square(Rank::Second, File::A).to_index(), 8);
assert_eq!(Square::make_square(Rank::First, File::B).to_index(), 1);
assert_eq!(Square::make_square(Rank::Eighth, File::H).to_index(), 63);
sourcepub fn from_string(s: String) -> Option<Square>
👎Deprecated since 3.1.0: please use Square::from_str(square)?
instead
pub fn from_string(s: String) -> Option<Square>
Square::from_str(square)?
insteadConvert a UCI String
to a square. If invalid, return None
use candidate::Square;
let sq = Square::default();
assert_eq!(Square::from_string("a1".to_owned()).expect("Valid Square"), sq);
sourcepub const A1: Square = _
pub const A1: Square = _
The A1 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::A1, Square::make_square(Rank::First, File::A));
sourcepub const B1: Square = _
pub const B1: Square = _
The B1 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::B1, Square::make_square(Rank::First, File::B));
sourcepub const C1: Square = _
pub const C1: Square = _
The C1 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::C1, Square::make_square(Rank::First, File::C));
sourcepub const D1: Square = _
pub const D1: Square = _
The D1 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::D1, Square::make_square(Rank::First, File::D));
sourcepub const E1: Square = _
pub const E1: Square = _
The E1 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::E1, Square::make_square(Rank::First, File::E));
sourcepub const F1: Square = _
pub const F1: Square = _
The F1 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::F1, Square::make_square(Rank::First, File::F));
sourcepub const G1: Square = _
pub const G1: Square = _
The G1 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::G1, Square::make_square(Rank::First, File::G));
sourcepub const H1: Square = _
pub const H1: Square = _
The H1 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::H1, Square::make_square(Rank::First, File::H));
sourcepub const A2: Square = _
pub const A2: Square = _
The A2 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::A2, Square::make_square(Rank::Second, File::A));
sourcepub const B2: Square = _
pub const B2: Square = _
The B2 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::B2, Square::make_square(Rank::Second, File::B));
sourcepub const C2: Square = _
pub const C2: Square = _
The C2 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::C2, Square::make_square(Rank::Second, File::C));
sourcepub const D2: Square = _
pub const D2: Square = _
The D2 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::D2, Square::make_square(Rank::Second, File::D));
sourcepub const E2: Square = _
pub const E2: Square = _
The E2 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::E2, Square::make_square(Rank::Second, File::E));
sourcepub const F2: Square = _
pub const F2: Square = _
The F2 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::F2, Square::make_square(Rank::Second, File::F));
sourcepub const G2: Square = _
pub const G2: Square = _
The G2 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::G2, Square::make_square(Rank::Second, File::G));
sourcepub const H2: Square = _
pub const H2: Square = _
The H2 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::H2, Square::make_square(Rank::Second, File::H));
sourcepub const A3: Square = _
pub const A3: Square = _
The A3 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::A3, Square::make_square(Rank::Third, File::A));
sourcepub const B3: Square = _
pub const B3: Square = _
The B3 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::B3, Square::make_square(Rank::Third, File::B));
sourcepub const C3: Square = _
pub const C3: Square = _
The C3 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::C3, Square::make_square(Rank::Third, File::C));
sourcepub const D3: Square = _
pub const D3: Square = _
The D3 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::D3, Square::make_square(Rank::Third, File::D));
sourcepub const E3: Square = _
pub const E3: Square = _
The E3 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::E3, Square::make_square(Rank::Third, File::E));
sourcepub const F3: Square = _
pub const F3: Square = _
The F3 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::F3, Square::make_square(Rank::Third, File::F));
sourcepub const G3: Square = _
pub const G3: Square = _
The G3 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::G3, Square::make_square(Rank::Third, File::G));
sourcepub const H3: Square = _
pub const H3: Square = _
The H3 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::H3, Square::make_square(Rank::Third, File::H));
sourcepub const A4: Square = _
pub const A4: Square = _
The A4 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::A4, Square::make_square(Rank::Fourth, File::A));
sourcepub const B4: Square = _
pub const B4: Square = _
The B4 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::B4, Square::make_square(Rank::Fourth, File::B));
sourcepub const C4: Square = _
pub const C4: Square = _
The C4 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::C4, Square::make_square(Rank::Fourth, File::C));
sourcepub const D4: Square = _
pub const D4: Square = _
The D4 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::D4, Square::make_square(Rank::Fourth, File::D));
sourcepub const E4: Square = _
pub const E4: Square = _
The E4 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::E4, Square::make_square(Rank::Fourth, File::E));
sourcepub const F4: Square = _
pub const F4: Square = _
The F4 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::F4, Square::make_square(Rank::Fourth, File::F));
sourcepub const G4: Square = _
pub const G4: Square = _
The G4 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::G4, Square::make_square(Rank::Fourth, File::G));
sourcepub const H4: Square = _
pub const H4: Square = _
The H4 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::H4, Square::make_square(Rank::Fourth, File::H));
sourcepub const A5: Square = _
pub const A5: Square = _
The A5 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::A5, Square::make_square(Rank::Fifth, File::A));
sourcepub const B5: Square = _
pub const B5: Square = _
The B5 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::B5, Square::make_square(Rank::Fifth, File::B));
sourcepub const C5: Square = _
pub const C5: Square = _
The C5 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::C5, Square::make_square(Rank::Fifth, File::C));
sourcepub const D5: Square = _
pub const D5: Square = _
The D5 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::D5, Square::make_square(Rank::Fifth, File::D));
sourcepub const E5: Square = _
pub const E5: Square = _
The E5 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::E5, Square::make_square(Rank::Fifth, File::E));
sourcepub const F5: Square = _
pub const F5: Square = _
The F5 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::F5, Square::make_square(Rank::Fifth, File::F));
sourcepub const G5: Square = _
pub const G5: Square = _
The G5 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::G5, Square::make_square(Rank::Fifth, File::G));
sourcepub const H5: Square = _
pub const H5: Square = _
The H5 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::H5, Square::make_square(Rank::Fifth, File::H));
sourcepub const A6: Square = _
pub const A6: Square = _
The A6 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::A6, Square::make_square(Rank::Sixth, File::A));
sourcepub const B6: Square = _
pub const B6: Square = _
The B6 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::B6, Square::make_square(Rank::Sixth, File::B));
sourcepub const C6: Square = _
pub const C6: Square = _
The C6 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::C6, Square::make_square(Rank::Sixth, File::C));
sourcepub const D6: Square = _
pub const D6: Square = _
The D6 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::D6, Square::make_square(Rank::Sixth, File::D));
sourcepub const E6: Square = _
pub const E6: Square = _
The E6 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::E6, Square::make_square(Rank::Sixth, File::E));
sourcepub const F6: Square = _
pub const F6: Square = _
The F6 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::F6, Square::make_square(Rank::Sixth, File::F));
sourcepub const G6: Square = _
pub const G6: Square = _
The G6 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::G6, Square::make_square(Rank::Sixth, File::G));
sourcepub const H6: Square = _
pub const H6: Square = _
The H6 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::H6, Square::make_square(Rank::Sixth, File::H));
sourcepub const A7: Square = _
pub const A7: Square = _
The A7 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::A7, Square::make_square(Rank::Seventh, File::A));
sourcepub const B7: Square = _
pub const B7: Square = _
The B7 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::B7, Square::make_square(Rank::Seventh, File::B));
sourcepub const C7: Square = _
pub const C7: Square = _
The C7 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::C7, Square::make_square(Rank::Seventh, File::C));
sourcepub const D7: Square = _
pub const D7: Square = _
The D7 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::D7, Square::make_square(Rank::Seventh, File::D));
sourcepub const E7: Square = _
pub const E7: Square = _
The E7 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::E7, Square::make_square(Rank::Seventh, File::E));
sourcepub const F7: Square = _
pub const F7: Square = _
The F7 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::F7, Square::make_square(Rank::Seventh, File::F));
sourcepub const G7: Square = _
pub const G7: Square = _
The G7 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::G7, Square::make_square(Rank::Seventh, File::G));
sourcepub const H7: Square = _
pub const H7: Square = _
The H7 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::H7, Square::make_square(Rank::Seventh, File::H));
sourcepub const A8: Square = _
pub const A8: Square = _
The A8 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::A8, Square::make_square(Rank::Eighth, File::A));
sourcepub const B8: Square = _
pub const B8: Square = _
The B8 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::B8, Square::make_square(Rank::Eighth, File::B));
sourcepub const C8: Square = _
pub const C8: Square = _
The C8 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::C8, Square::make_square(Rank::Eighth, File::C));
sourcepub const D8: Square = _
pub const D8: Square = _
The D8 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::D8, Square::make_square(Rank::Eighth, File::D));
sourcepub const E8: Square = _
pub const E8: Square = _
The E8 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::E8, Square::make_square(Rank::Eighth, File::E));
sourcepub const F8: Square = _
pub const F8: Square = _
The F8 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::F8, Square::make_square(Rank::Eighth, File::F));
Trait Implementations§
source§impl Index<Square> for BoardBuilder
impl Index<Square> for BoardBuilder
source§impl IndexMut<Square> for BoardBuilder
impl IndexMut<Square> for BoardBuilder
source§impl Ord for Square
impl Ord for Square
source§impl PartialOrd<Square> for Square
impl PartialOrd<Square> for Square
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more