pub struct Square(/* private fields */);
Expand description
Represent a square on the chess board
Implementations§
Source§impl Square
impl Square
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));
Sourcepub const G8: Square
pub const G8: Square
The G8 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::G8, Square::make_square(Rank::Eighth, File::G));
Sourcepub const H8: Square
pub const H8: Square
The H8 square on the chess board
use candidate::{Square, Rank, File};
assert_eq!(Square::H8, Square::make_square(Rank::Eighth, File::H));
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);