Struct chess::Board [−][src]
pub struct Board { /* fields omitted */ }
A representation of a chess board. That's why you're here, right?
Methods
impl Board
[src]
impl Board
pub fn from_fen(fen: String) -> Option<Board>
[src]
pub fn from_fen(fen: String) -> Option<Board>
Construct a board from a FEN string.
use chess::Board; 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());
pub fn status(&self) -> BoardStatus
[src]
pub fn status(&self) -> BoardStatus
Is this game Ongoing, is it Stalemate, or is it Checkmate?
use chess::{Board, BoardStatus, Square, Rank, File, ChessMove}; let mut board = Board::default(); assert_eq!(board.status(), BoardStatus::Ongoing); board = board.make_move(ChessMove::new(Square::make_square(Rank::Second, File::E), Square::make_square(Rank::Fourth, File::E), None)); assert_eq!(board.status(), BoardStatus::Ongoing); board = board.make_move(ChessMove::new(Square::make_square(Rank::Seventh, File::F), Square::make_square(Rank::Sixth, File::F), None)); assert_eq!(board.status(), BoardStatus::Ongoing); board = board.make_move(ChessMove::new(Square::make_square(Rank::Second, File::D), Square::make_square(Rank::Fourth, File::D), None)); assert_eq!(board.status(), BoardStatus::Ongoing); board = board.make_move(ChessMove::new(Square::make_square(Rank::Seventh, File::G), Square::make_square(Rank::Fifth, File::G), None)); assert_eq!(board.status(), BoardStatus::Ongoing); board = board.make_move(ChessMove::new(Square::make_square(Rank::First, File::D), Square::make_square(Rank::Fifth, File::H), None)); assert_eq!(board.status(), BoardStatus::Checkmate);
ⓘImportant traits for BitBoardpub fn combined(&self) -> BitBoard
[src]
pub fn combined(&self) -> BitBoard
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);
ⓘImportant traits for BitBoardpub fn color_combined(&self, color: Color) -> BitBoard
[src]
pub fn color_combined(&self, color: Color) -> BitBoard
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]
pub fn king_square(&self, color: Color) -> Square
Give me the Square
the color
king is on.
use chess::{Board, Square, Color, Rank, File}; let board = Board::default(); assert_eq!(board.king_square(Color::White), Square::make_square(Rank::First, File::E)); assert_eq!(board.king_square(Color::Black), Square::make_square(Rank::Eighth, File::E));
ⓘImportant traits for BitBoardpub fn pieces(&self, piece: Piece) -> BitBoard
[src]
pub fn pieces(&self, piece: Piece) -> BitBoard
Grab the "pieces" BitBoard
. This is a BitBoard
with every piece of a particular type.
use chess::{Board, BitBoard, Piece, Square, Rank, File}; // The rooks should be in each corner of the board let rooks = BitBoard::from_square(Square::make_square(Rank::First, File::A)) | BitBoard::from_square(Square::make_square(Rank::First, File::H)) | BitBoard::from_square(Square::make_square(Rank::Eighth, File::A)) | BitBoard::from_square(Square::make_square(Rank::Eighth, File::H)); let board = Board::default(); assert_eq!(board.pieces(Piece::Rook), rooks);
pub fn castle_rights(&self, color: Color) -> CastleRights
[src]
pub fn castle_rights(&self, color: Color) -> CastleRights
Grab the CastleRights
for a particular side.
use chess::{Board, Square, Rank, File, CastleRights, Color, ChessMove}; let move1 = ChessMove::new(Square::make_square(Rank::Second, File::A), Square::make_square(Rank::Fourth, File::A), None); let move2 = ChessMove::new(Square::make_square(Rank::Seventh, File::E), Square::make_square(Rank::Fifth, File::E), None); let move3 = ChessMove::new(Square::make_square(Rank::First, File::A), Square::make_square(Rank::Second, File::A), None); let move4 = ChessMove::new(Square::make_square(Rank::Eighth, File::E), Square::make_square(Rank::Seventh, File::E), 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(move1) .make_move(move2) .make_move(move3) .make_move(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]
pub fn add_castle_rights(&mut self, color: Color, add: CastleRights)
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]
pub fn remove_castle_rights(&mut self, color: Color, remove: CastleRights)
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]
pub fn side_to_move(&self) -> Color
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]
pub fn my_castle_rights(&self) -> CastleRights
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]
pub fn add_my_castle_rights(&mut self, add: CastleRights)
Add to my CastleRights
. Note: This can make the position invalid.
pub fn remove_my_castle_rights(&mut self, remove: CastleRights)
[src]
pub fn remove_my_castle_rights(&mut self, remove: CastleRights)
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]
pub fn their_castle_rights(&self) -> CastleRights
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]
pub fn add_their_castle_rights(&mut self, add: CastleRights)
Add to my opponents CastleRights
. Note: This can make the position invalid.
pub fn remove_their_castle_rights(&mut self, remove: CastleRights)
[src]
pub fn remove_their_castle_rights(&mut self, remove: CastleRights)
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]
pub fn set_piece(
&self,
piece: Piece,
color: Color,
square: Square
) -> Option<Board>
For a chess UI: set a piece on a particular square.
use chess::{Board, Piece, Color, Square, Rank, File}; let board = Board::default(); let new_board = board.set_piece(Piece::Queen, Color::White, Square::make_square(Rank::Fourth, File::E)) .expect("Valid Position"); assert_eq!(new_board.pieces(Piece::Queen).count(), 3);
pub fn clear_square(&self, square: Square) -> Option<Board>
[src]
pub fn clear_square(&self, square: Square) -> Option<Board>
For a chess UI: clear a particular square.
use chess::{Board, Square, Rank, File, Piece}; let board = Board::default(); let new_board = board.clear_square(Square::make_square(Rank::First, File::A)) .expect("Valid Position"); assert_eq!(new_board.pieces(Piece::Rook).count(), 3);
pub fn null_move(&self) -> Option<Board>
[src]
pub fn null_move(&self) -> Option<Board>
Switch the color of the player without actually making a move. Returns None if the current player is in check.
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]
pub fn is_sane(&self) -> bool
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, Rank, File}; let board = Board::default(); assert_eq!(board.is_sane(), true); // Remove the king let bad_board = board.clear_square(Square::make_square(Rank::First, File::E)).expect("Valid Position"); assert_eq!(bad_board.is_sane(), false);
pub fn get_hash(&self) -> u64
[src]
pub fn get_hash(&self) -> u64
Get a hash of the board.
pub fn get_pawn_hash(&self) -> u64
[src]
pub fn get_pawn_hash(&self) -> u64
Get a pawn hash of the board (a hash that only changes on color change and pawn moves).
pub fn piece_on(&self, square: Square) -> Option<Piece>
[src]
pub fn piece_on(&self, square: Square) -> Option<Piece>
What piece is on a particular Square
? Is there even one?
use chess::{Board, Piece, Square, Rank, File}; let board = Board::default(); let sq1 = Square::make_square(Rank::First, File::A); let sq2 = Square::make_square(Rank::Fourth, File::D); assert_eq!(board.piece_on(sq1), Some(Piece::Rook)); assert_eq!(board.piece_on(sq2), None);
pub fn enumerate_moves(&self, moves: &mut [ChessMove; 256]) -> usize
[src]
pub fn enumerate_moves(&self, moves: &mut [ChessMove; 256]) -> usize
Give me all the legal moves for this board.
Note: You may want to build a MoveGen
structure to iterate over
the moves instead.
Additionally, you must allocate the move array yourself if you want to call this function. it massively helps with performance to reuse that array.
use chess::{Board, ChessMove}; let board = Board::default(); let mut moves = [ChessMove::default(); 256]; let count = board.enumerate_moves(&mut moves); assert_eq!(count, 20);
pub fn en_passant(self) -> Option<Square>
[src]
pub fn en_passant(self) -> Option<Square>
Give me the en_passant square, if it exists.
use chess::{Board, ChessMove, Square, Rank, File}; let move1 = ChessMove::new(Square::make_square(Rank::Second, File::D), Square::make_square(Rank::Fourth, File::D), None); let move2 = ChessMove::new(Square::make_square(Rank::Seventh, File::H), Square::make_square(Rank::Fifth, File::H), None); let move3 = ChessMove::new(Square::make_square(Rank::Fourth, File::D), Square::make_square(Rank::Fifth, File::D), None); let move4 = ChessMove::new(Square::make_square(Rank::Seventh, File::E), Square::make_square(Rank::Fifth, File::E), None); let board = Board::default().make_move(move1) .make_move(move2) .make_move(move3) .make_move(move4); assert_eq!(board.en_passant(), Some(Square::make_square(Rank::Fifth, File::E)));
pub fn legal(&self, m: ChessMove) -> bool
[src]
pub fn legal(&self, m: ChessMove) -> bool
Is a particular move legal?
use chess::{Board, ChessMove, Square, Rank, File}; let move1 = ChessMove::new(Square::make_square(Rank::Second, File::E), Square::make_square(Rank::Fourth, File::E), None); let move2 = ChessMove::new(Square::make_square(Rank::Second, File::E), Square::make_square(Rank::Fifth, File::E), None); let board = Board::default(); assert_eq!(board.legal(move1), true); assert_eq!(board.legal(move2), false);
pub fn legal_quick(&self, chess_move: ChessMove) -> bool
[src]
pub fn legal_quick(&self, chess_move: ChessMove) -> bool
This function checks the legality only for moves generated by MoveGen
.
Calling this function for moves not generated by MoveGen
will result in possibly
incorrect results, and making that move on the Board
will result in undefined behavior.
This function may panic! if these rules are not followed.
If you are validating a move from a user, you should call the .legal() function.
pub fn make_move(&self, m: ChessMove) -> Board
[src]
pub fn make_move(&self, m: ChessMove) -> Board
Make a chess move.
panic!() if king is captured.
use chess::{Board, ChessMove, Square, Rank, File, Color}; let m = ChessMove::new(Square::make_square(Rank::Second, File::D), Square::make_square(Rank::Fourth, File::D), None); let board = Board::default(); assert_eq!(board.make_move(m).side_to_move(), Color::Black);
pub fn perft(&self, depth: u64) -> u64
[src]
pub fn perft(&self, depth: u64) -> u64
Run a perft-test.
pub fn perft_brute_force(&self, depth: u64) -> u64
[src]
pub fn perft_brute_force(&self, depth: u64) -> u64
Run a perft-test using brute force move generation.
pub fn perft_cache(&self, depth: u64, cache_size_per_depth: usize) -> u64
[src]
pub fn perft_cache(&self, depth: u64, cache_size_per_depth: usize) -> u64
Run a perft test with a cache table.
ⓘImportant traits for BitBoardpub fn pinned(&self) -> BitBoard
[src]
pub fn pinned(&self) -> BitBoard
Give me the BitBoard
of my pinned pieces.
ⓘImportant traits for BitBoardpub fn checkers(&self) -> BitBoard
[src]
pub fn checkers(&self) -> BitBoard
Give me the Bitboard
of the pieces putting me in check.
pub fn legal_king_move(&self, dest: Square) -> bool
[src]
pub fn legal_king_move(&self, dest: Square) -> bool
Is a particular king move legal?
pub fn legal_ep_move(&self, source: Square, dest: Square) -> bool
[src]
pub fn legal_ep_move(&self, source: Square, dest: Square) -> bool
Is a particular en-passant capture legal?
pub fn perft_test(fen: String, depth: u64, result: u64)
[src]
pub fn perft_test(fen: String, depth: u64, result: u64)
Run every type of perft test, and panic! if the leaf-node count of any version is not equal
to result
.
Trait Implementations
impl Copy for Board
[src]
impl Copy for Board
impl Clone for Board
[src]
impl Clone for Board
fn clone(&self) -> Board
[src]
fn clone(&self) -> Board
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl PartialEq for Board
[src]
impl PartialEq for Board
fn eq(&self, other: &Board) -> bool
[src]
fn eq(&self, other: &Board) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Board) -> bool
[src]
fn ne(&self, other: &Board) -> bool
This method tests for !=
.
impl Debug for Board
[src]
impl Debug for Board
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Default for Board
[src]
impl Default for Board
Construct the initial position.
impl Display for Board
[src]
impl Display for Board