Struct bughouse::Square [−][src]
pub struct Square(_);
Expand description
Represent a square on the chess board
Implementations
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 chess::{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); }
Make a square given a rank and a file
use chess::{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); }
Return the rank given this square.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Seventh, File::D); assert_eq!(sq.get_rank(), Rank::Seventh);
Return the file given this square.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Seventh, File::D); assert_eq!(sq.get_file(), File::D);
If there is a square above me, return that. Otherwise, None.
use chess::{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);
If there is a square below me, return that. Otherwise, None.
use chess::{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);
If there is a square to the left of me, return that. Otherwise, None.
use chess::{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);
If there is a square to the right of me, return that. Otherwise, None.
use chess::{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);
If there is a square “forward”, given my Color
, go in that direction. Otherwise, None.
use chess::{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);
If there is a square “backward” given my Color
, go in that direction. Otherwise, None.
use chess::{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);
If there is a square above me, return that. If not, wrap around to the other side.
use chess::{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));
If there is a square below me, return that. If not, wrap around to the other side.
use chess::{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));
If there is a square to the left of me, return that. If not, wrap around to the other side.
use chess::{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));
If there is a square to the right of me, return that. If not, wrap around to the other side.
use chess::{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));
If there is a square “forward”, given my color, return that. If not, wrap around to the other side.
use chess::{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));
If there is a square “backward”, given my color, return that. If not, wrap around to the other side.
use chess::{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));
Convert this square to an integer.
use chess::{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);
Convert this Square
to a usize
for table lookup purposes
use chess::{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);
👎 Deprecated since 3.1.0: please use Square::from_str(square)?
instead
please use Square::from_str(square)?
instead
Convert a UCI String
to a square. If invalid, return None
use chess::Square; let sq = Square::default(); assert_eq!(Square::from_string("a1".to_owned()).expect("Valid Square"), sq);
The A1 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::A1, Square::make_square(Rank::First, File::A));
The B1 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::B1, Square::make_square(Rank::First, File::B));
The C1 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::C1, Square::make_square(Rank::First, File::C));
The D1 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::D1, Square::make_square(Rank::First, File::D));
The E1 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::E1, Square::make_square(Rank::First, File::E));
The F1 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::F1, Square::make_square(Rank::First, File::F));
The G1 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::G1, Square::make_square(Rank::First, File::G));
The H1 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::H1, Square::make_square(Rank::First, File::H));
The A2 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::A2, Square::make_square(Rank::Second, File::A));
The B2 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::B2, Square::make_square(Rank::Second, File::B));
The C2 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::C2, Square::make_square(Rank::Second, File::C));
The D2 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::D2, Square::make_square(Rank::Second, File::D));
The E2 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::E2, Square::make_square(Rank::Second, File::E));
The F2 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::F2, Square::make_square(Rank::Second, File::F));
The G2 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::G2, Square::make_square(Rank::Second, File::G));
The H2 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::H2, Square::make_square(Rank::Second, File::H));
The A3 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::A3, Square::make_square(Rank::Third, File::A));
The B3 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::B3, Square::make_square(Rank::Third, File::B));
The C3 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::C3, Square::make_square(Rank::Third, File::C));
The D3 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::D3, Square::make_square(Rank::Third, File::D));
The E3 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::E3, Square::make_square(Rank::Third, File::E));
The F3 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::F3, Square::make_square(Rank::Third, File::F));
The G3 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::G3, Square::make_square(Rank::Third, File::G));
The H3 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::H3, Square::make_square(Rank::Third, File::H));
The A4 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::A4, Square::make_square(Rank::Fourth, File::A));
The B4 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::B4, Square::make_square(Rank::Fourth, File::B));
The C4 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::C4, Square::make_square(Rank::Fourth, File::C));
The D4 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::D4, Square::make_square(Rank::Fourth, File::D));
The E4 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::E4, Square::make_square(Rank::Fourth, File::E));
The F4 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::F4, Square::make_square(Rank::Fourth, File::F));
The G4 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::G4, Square::make_square(Rank::Fourth, File::G));
The H4 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::H4, Square::make_square(Rank::Fourth, File::H));
The A5 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::A5, Square::make_square(Rank::Fifth, File::A));
The B5 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::B5, Square::make_square(Rank::Fifth, File::B));
The C5 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::C5, Square::make_square(Rank::Fifth, File::C));
The D5 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::D5, Square::make_square(Rank::Fifth, File::D));
The E5 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::E5, Square::make_square(Rank::Fifth, File::E));
The F5 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::F5, Square::make_square(Rank::Fifth, File::F));
The G5 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::G5, Square::make_square(Rank::Fifth, File::G));
The H5 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::H5, Square::make_square(Rank::Fifth, File::H));
The A6 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::A6, Square::make_square(Rank::Sixth, File::A));
The B6 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::B6, Square::make_square(Rank::Sixth, File::B));
The C6 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::C6, Square::make_square(Rank::Sixth, File::C));
The D6 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::D6, Square::make_square(Rank::Sixth, File::D));
The E6 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::E6, Square::make_square(Rank::Sixth, File::E));
The F6 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::F6, Square::make_square(Rank::Sixth, File::F));
The G6 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::G6, Square::make_square(Rank::Sixth, File::G));
The H6 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::H6, Square::make_square(Rank::Sixth, File::H));
The A7 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::A7, Square::make_square(Rank::Seventh, File::A));
The B7 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::B7, Square::make_square(Rank::Seventh, File::B));
The C7 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::C7, Square::make_square(Rank::Seventh, File::C));
The D7 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::D7, Square::make_square(Rank::Seventh, File::D));
The E7 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::E7, Square::make_square(Rank::Seventh, File::E));
The F7 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::F7, Square::make_square(Rank::Seventh, File::F));
The G7 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::G7, Square::make_square(Rank::Seventh, File::G));
The H7 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::H7, Square::make_square(Rank::Seventh, File::H));
The A8 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::A8, Square::make_square(Rank::Eighth, File::A));
The B8 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::B8, Square::make_square(Rank::Eighth, File::B));
The C8 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::C8, Square::make_square(Rank::Eighth, File::C));
The D8 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::D8, Square::make_square(Rank::Eighth, File::D));
The E8 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::E8, Square::make_square(Rank::Eighth, File::E));
The F8 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::F8, Square::make_square(Rank::Eighth, File::F));
The G8 square on the chess board
use chess::{Square, Rank, File}; assert_eq!(Square::G8, Square::make_square(Rank::Eighth, File::G));
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Square
impl UnwindSafe for Square
Blanket Implementations
Mutably borrows from an owned value. Read more