Struct chess::Board [−][src]
A representation of a chess board. That’s why you’re here, right?
Implementations
impl Board
[src]
pub fn from_fen(fen: String) -> Option<Board>
[src]
please use Board::from_str(fen)?
instead
Construct a board from a FEN string.
use chess::Board; use std::str::FromStr; // This is no longer supported let init_position = Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1".to_owned()).expect("Valid FEN"); assert_eq!(init_position, Board::default()); // This is the new way let init_position_2 = Board::from_str("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")?; assert_eq!(init_position_2, Board::default());
pub fn enumerate_moves(&self, moves: &mut [ChessMove; 256]) -> usize
[src]
please use the MoveGen structure instead. It is faster and more idiomatic.
pub fn status(&self) -> BoardStatus
[src]
Is this game Ongoing, is it Stalemate, or is it Checkmate?
use chess::{Board, BoardStatus, Square, ChessMove}; let mut board = Board::default(); assert_eq!(board.status(), BoardStatus::Ongoing); board = board.make_move_new(ChessMove::new(Square::E2, Square::E4, None)); assert_eq!(board.status(), BoardStatus::Ongoing); board = board.make_move_new(ChessMove::new(Square::F7, Square::F6, None)); assert_eq!(board.status(), BoardStatus::Ongoing); board = board.make_move_new(ChessMove::new(Square::D2, Square::D4, None)); assert_eq!(board.status(), BoardStatus::Ongoing); board = board.make_move_new(ChessMove::new(Square::G7, Square::G5, None)); assert_eq!(board.status(), BoardStatus::Ongoing); board = board.make_move_new(ChessMove::new(Square::D1, Square::H5, None)); assert_eq!(board.status(), BoardStatus::Checkmate);
pub fn combined(&self) -> &BitBoardⓘ
[src]
Grab the “combined” BitBoard
. This is a BitBoard
with every piece.
use chess::{Board, BitBoard, Rank, get_rank}; let board = Board::default(); let combined_should_be = get_rank(Rank::First) | get_rank(Rank::Second) | get_rank(Rank::Seventh) | get_rank(Rank::Eighth); assert_eq!(*board.combined(), combined_should_be);
pub fn color_combined(&self, color: Color) -> &BitBoardⓘ
[src]
Grab the “color combined” BitBoard
. This is a BitBoard
with every piece of a particular
color.
use chess::{Board, BitBoard, Rank, get_rank, Color}; let board = Board::default(); let white_pieces = get_rank(Rank::First) | get_rank(Rank::Second); let black_pieces = get_rank(Rank::Seventh) | get_rank(Rank::Eighth); assert_eq!(*board.color_combined(Color::White), white_pieces); assert_eq!(*board.color_combined(Color::Black), black_pieces);
pub fn king_square(&self, color: Color) -> Square
[src]
Give me the Square
the color
king is on.
use chess::{Board, Square, Color}; let board = Board::default(); assert_eq!(board.king_square(Color::White), Square::E1); assert_eq!(board.king_square(Color::Black), Square::E8);
pub fn pieces(&self, piece: Piece) -> &BitBoardⓘ
[src]
Grab the “pieces” BitBoard
. This is a BitBoard
with every piece of a particular type.
use chess::{Board, BitBoard, Piece, Square}; // The rooks should be in each corner of the board let rooks = BitBoard::from_square(Square::A1) | BitBoard::from_square(Square::H1) | BitBoard::from_square(Square::A8) | BitBoard::from_square(Square::H8); let board = Board::default(); assert_eq!(*board.pieces(Piece::Rook), rooks);
pub fn castle_rights(&self, color: Color) -> CastleRights
[src]
Grab the CastleRights
for a particular side.
use chess::{Board, Square, CastleRights, Color, ChessMove}; let move1 = ChessMove::new(Square::A2, Square::A4, None); let move2 = ChessMove::new(Square::E7, Square::E5, None); let move3 = ChessMove::new(Square::A1, Square::A2, None); let move4 = ChessMove::new(Square::E8, Square::E7, None); let mut board = Board::default(); assert_eq!(board.castle_rights(Color::White), CastleRights::Both); assert_eq!(board.castle_rights(Color::Black), CastleRights::Both); board = board.make_move_new(move1) .make_move_new(move2) .make_move_new(move3) .make_move_new(move4); assert_eq!(board.castle_rights(Color::White), CastleRights::KingSide); assert_eq!(board.castle_rights(Color::Black), CastleRights::NoRights);
pub fn add_castle_rights(&mut self, color: Color, add: CastleRights)
[src]
When doing board setup, use the BoardBuilder structure. It ensures you don’t end up with an invalid position.
Add castle rights for a particular side. Note: this can create an invalid position.
pub fn remove_castle_rights(&mut self, color: Color, remove: CastleRights)
[src]
When doing board setup, use the BoardBuilder structure. It ensures you don’t end up with an invalid position.
Remove castle rights for a particular side.
use chess::{Board, CastleRights, Color}; let mut board = Board::default(); assert_eq!(board.castle_rights(Color::White), CastleRights::Both); board.remove_castle_rights(Color::White, CastleRights::KingSide); assert_eq!(board.castle_rights(Color::White), CastleRights::QueenSide);
pub fn side_to_move(&self) -> Color
[src]
Who’s turn is it?
use chess::{Board, Color}; let mut board = Board::default(); assert_eq!(board.side_to_move(), Color::White);
pub fn my_castle_rights(&self) -> CastleRights
[src]
Grab my CastleRights
.
use chess::{Board, Color, CastleRights}; let mut board = Board::default(); board.remove_castle_rights(Color::White, CastleRights::KingSide); board.remove_castle_rights(Color::Black, CastleRights::QueenSide); assert_eq!(board.my_castle_rights(), board.castle_rights(Color::White));
pub fn add_my_castle_rights(&mut self, add: CastleRights)
[src]
When doing board setup, use the BoardBuilder structure. It ensures you don’t end up with an invalid position.
Add to my CastleRights
. Note: This can make the position invalid.
pub fn remove_my_castle_rights(&mut self, remove: CastleRights)
[src]
When doing board setup, use the BoardBuilder structure. It ensures you don’t end up with an invalid position.
Remove some of my CastleRights
.
use chess::{Board, CastleRights}; let mut board = Board::default(); assert_eq!(board.my_castle_rights(), CastleRights::Both); board.remove_my_castle_rights(CastleRights::KingSide); assert_eq!(board.my_castle_rights(), CastleRights::QueenSide);
pub fn their_castle_rights(&self) -> CastleRights
[src]
My opponents CastleRights
.
use chess::{Board, Color, CastleRights}; let mut board = Board::default(); board.remove_castle_rights(Color::White, CastleRights::KingSide); board.remove_castle_rights(Color::Black, CastleRights::QueenSide); assert_eq!(board.their_castle_rights(), board.castle_rights(Color::Black));
pub fn add_their_castle_rights(&mut self, add: CastleRights)
[src]
When doing board setup, use the BoardBuilder structure. It ensures you don’t end up with an invalid position.
Add to my opponents CastleRights
. Note: This can make the position invalid.
pub fn remove_their_castle_rights(&mut self, remove: CastleRights)
[src]
When doing board setup, use the BoardBuilder structure. It ensures you don’t end up with an invalid position.
Remove some of my opponents CastleRights
.
use chess::{Board, CastleRights}; let mut board = Board::default(); assert_eq!(board.their_castle_rights(), CastleRights::Both); board.remove_their_castle_rights(CastleRights::KingSide); assert_eq!(board.their_castle_rights(), CastleRights::QueenSide);
pub fn set_piece(
&self,
piece: Piece,
color: Color,
square: Square
) -> Option<Board>
[src]
&self,
piece: Piece,
color: Color,
square: Square
) -> Option<Board>
When doing board setup, use the BoardBuilder structure. It ensures you don’t end up with an invalid position.
For a chess UI: set a piece on a particular square.
use chess::{Board, Piece, Color, Square}; let board = Board::default(); let new_board = board.set_piece(Piece::Queen, Color::White, Square::E4) .expect("Valid Position"); assert_eq!(new_board.pieces(Piece::Queen).count(), 3);
pub fn clear_square(&self, square: Square) -> Option<Board>
[src]
When doing board setup, use the BoardBuilder structure. It ensures you don’t end up with an invalid position.
For a chess UI: clear a particular square.
use chess::{Board, Square, Piece}; let board = Board::default(); let new_board = board.clear_square(Square::A1) .expect("Valid Position"); assert_eq!(new_board.pieces(Piece::Rook).count(), 3);
pub fn null_move(&self) -> Option<Board>
[src]
Switch the color of the player without actually making a move. Returns None if the current player is in check.
Note that this erases the en-passant information, so applying this function twice does not always give the same result back.
use chess::{Board, Color}; let board = Board::default(); assert_eq!(board.side_to_move(), Color::White); let new_board = board.null_move().expect("Valid Position"); assert_eq!(new_board.side_to_move(), Color::Black);
pub fn is_sane(&self) -> bool
[src]
Does this board “make sense”? Do all the pieces make sense, do the bitboards combine correctly, etc? This is for sanity checking.
use chess::{Board, Color, Piece, Square}; let board = Board::default(); assert_eq!(board.is_sane(), true); // Remove the king let bad_board = board.clear_square(Square::E1).expect("Valid Position"); assert_eq!(bad_board.is_sane(), false);
pub fn get_hash(&self) -> u64
[src]
Get a hash of the board.
pub fn get_pawn_hash(&self) -> u64
[src]
Get a pawn hash of the board (a hash that only changes on color change and pawn moves).
Currently not implemented…
pub fn piece_on(&self, square: Square) -> Option<Piece>
[src]
What piece is on a particular Square
? Is there even one?
use chess::{Board, Piece, Square}; let board = Board::default(); assert_eq!(board.piece_on(Square::A1), Some(Piece::Rook)); assert_eq!(board.piece_on(Square::D4), None);
pub fn color_on(&self, square: Square) -> Option<Color>
[src]
What color piece is on a particular square?
pub fn en_passant(self) -> Option<Square>
[src]
Give me the en_passant square, if it exists.
use chess::{Board, ChessMove, Square}; let move1 = ChessMove::new(Square::D2, Square::D4, None); let move2 = ChessMove::new(Square::H7, Square::H5, None); let move3 = ChessMove::new(Square::D4, Square::D5, None); let move4 = ChessMove::new(Square::E7, Square::E5, None); let board = Board::default().make_move_new(move1) .make_move_new(move2) .make_move_new(move3) .make_move_new(move4); assert_eq!(board.en_passant(), Some(Square::E5));
pub fn legal(&self, m: ChessMove) -> bool
[src]
Is a particular move legal? This function is very slow, but will work on unsanitized input.
use chess::{Board, ChessMove, Square, MoveGen}; let move1 = ChessMove::new(Square::E2, Square::E4, None); let move2 = ChessMove::new(Square::E2, Square::E5, None); let board = Board::default(); assert_eq!(board.legal(move1), true); assert_eq!(board.legal(move2), false);
pub fn make_move_new(&self, m: ChessMove) -> Board
[src]
Make a chess move onto a new board.
panic!() if king is captured.
use chess::{Board, ChessMove, Square, Color}; let m = ChessMove::new(Square::D2, Square::D4, None); let board = Board::default(); assert_eq!(board.make_move_new(m).side_to_move(), Color::Black);
pub fn make_move(&self, m: ChessMove, result: &mut Board)
[src]
Make a chess move onto an already allocated Board
.
panic!() if king is captured.
use chess::{Board, ChessMove, Square, Color}; let m = ChessMove::new(Square::D2, Square::D4, None); let board = Board::default(); let mut result = Board::default(); board.make_move(m, &mut result); assert_eq!(result.side_to_move(), Color::Black);
pub fn pinned(&self) -> &BitBoardⓘ
[src]
Give me the BitBoard
of my pinned pieces.
pub fn checkers(&self) -> &BitBoardⓘ
[src]
Give me the Bitboard
of the pieces putting me in check.
Trait Implementations
impl Clone for Board
[src]
impl Copy for Board
[src]
impl Debug for Board
[src]
impl Default for Board
[src]
Construct the initial position.
impl Display for Board
[src]
impl Eq for Board
[src]
impl From<&'_ Board> for BoardBuilder
[src]
impl From<Board> for BoardBuilder
[src]
impl FromStr for Board
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(value: &str) -> Result<Self, Self::Err>
[src]
impl Hash for Board
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<Board> for Board
[src]
impl StructuralEq for Board
[src]
impl StructuralPartialEq for Board
[src]
impl TryFrom<&'_ BoardBuilder> for Board
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(fen: &BoardBuilder) -> Result<Self, Self::Error>
[src]
impl TryFrom<&'_ mut BoardBuilder> for Board
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(fen: &mut BoardBuilder) -> Result<Self, Self::Error>
[src]
impl TryFrom<BoardBuilder> for Board
[src]
Auto Trait Implementations
impl RefUnwindSafe for Board
impl Send for Board
impl Sync for Board
impl Unpin for Board
impl UnwindSafe for Board
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,