Struct pleco::board::Board
[−]
[src]
pub struct Board { pub magic_helper: &'static MAGIC_HELPER, // some fields omitted }
Represents a ChessBoard.
Board contains everything that needs to be known about the current state of the Game. It is used by both Engines and Players / Bots alike.
Ideally, the Engine contains the original Representation of a board (owns the board), and utilizes [Board::shallow_clone()] to share this representaion with Players.
Examples
use pleco::board::*; fn main() { let mut chessboard = Board::default(); let moves = chessboard.generate_moves(); chessboard.apply_move(moves[0]); let b2 = chessboard.shallow_clone(); // boards allow for easy cloning assert_eq!(chessboard.moves_played(), b2.moves_played()); }
BitBoard Representation
For the majority of the struct, the board utilizes [BitBoard]s, which is a u64 where each bit represents an occupied location, and each bit index represents a certain square (as in bit 0 is Square A1, bit 1 is B1, etc.). Indexes increase first horizontally by File, and then by Rank. See BitBoards article ChessWiki for more information.
The exact mapping from each square to bits is below,
// 8 | 56 57 58 59 60 61 62 63 // 7 | 48 49 50 51 52 53 54 55 // 6 | 40 41 42 43 44 45 46 47 // 5 | 32 33 34 35 36 37 38 39 // 4 | 24 25 26 27 28 29 30 31 // 3 | 16 17 18 19 20 21 22 23 // 2 | 8 9 10 11 12 13 14 15 // 1 | 0 1 2 3 4 5 6 7 // ------------------------- // a b c d e f g h
Fields
magic_helper: &'static MAGIC_HELPER
Methods
impl Board
[src]
fn default() -> Board
[src]
Constructs a board from the starting position
Examples
use pleco::board::*; use pleco::templates::Player; let mut chessboard = Board::default(); assert_eq!(chessboard.count_pieces_player(Player::White),16);
fn shallow_clone(&self) -> Board
[src]
Constructs a shallow clone of the Board.
Contains only the information necessary to apply future moves, more specifically does not clone the moves list, and sets depth to zero. Intended for an Engine or main thread to share the board to users wanting to search.
Safety
After this method has called, [Board::undo_move()] cannot be called immediately after. Undoing moves can only be done once a move has been played, and cannot be called more times than moves have been played since calling [Board::shallow_clone()].
fn parallel_clone(&self) -> Board
[src]
Constructs a parallel clone of the Board.
Similar to [Board::shallow_clone()], but keeps the current search depth the same. Should be used when implementing a searcher, and want to search a list of moves in parallel with different threads.
Safety
After this method has called, [Board::undo_move()] cannot be called immediately after. Undoing moves can only be done once a move has been played, and cannot be called more times than moves have been played since calling [Board::parallel_clone()].
unsafe fn deep_clone(&self) -> Board
[src]
Returns an exact clone of the current board.
Safety
This method is unsafe as it can give the impression of owning and operating a board structure, rather than just being provided shallow clones.
fn new_from_fen(fen: &str) -> Board
[src]
Constructs a board from a FEN String.
FEN stands for Forsyth-Edwards Notation, and is a way of representing a board through a string of characters. More information can be found on the ChessWiki.
Examples
use pleco::board::*; let board = Board::new_from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"); assert_eq!(board.count_all_pieces(),32);
Panics
The FEN string must be valid, or else the method will panic.
There is a possibility of the FEN string representing an unvalid position, with no panics resulting. The Constructed Board may have some Undefined Behavior as a result. It is up to the user to give a valid FEN string.
fn get_fen(&self) -> String
[src]
Creates a FEN String of the Given Board.
FEN stands for Forsyth-Edwards Notation, and is a way of representing a board through a string of characters. More information can be found on the ChessWiki.
Examples
use pleco::board::*; let board = Board::default(); assert_eq!(board.get_fen(),"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
impl Board
[src]
fn apply_move(&mut self, bit_move: BitMove)
[src]
Applies a move to the Board.
Example
use pleco::board::*; fn main() { let mut chessboard = Board::default(); let moves = chessboard.generate_moves(); chessboard.apply_move(moves[0]); }
Panics
The supplied BitMove must be both a valid move for that position, as well as a valid [BitMove], Otherwise, a panic will occur. Valid BitMoves can be generated with [Board::generate_moves()], which guarantees that only Legal moves will be created.
fn undo_move(&mut self)
[src]
Un-does the previously applied move, allowing the Board to return to it's most recently held state.
Panics
Cannot be done if after a [Board::shallow_clone()] or [Board::parallel_clone()] has been done and no subsequent moves have been played. ```rust,should_panic use pleco::board::*;
let mut chessboard = Board::default();
let moves = chessboard.generate_moves(); chessboard.apply_move(moves[0]);
let board_clone = chessboard.shallow_clone();
chessboard.undo_move(); // works, chessboard existed before the move was played board_clone.undo_move(); // error: board_clone was created after the move was applied
unsafe fn apply_null_move(&mut self)
[src]
Apply a "Null Move" to the board, essentially swapping the current turn of the board without moving any pieces.
Safety
This method should only be used for special evaluation purposes, as it does not give an accurate or legal state of the chess board.
Unsafe as it allows for Null Moves to be applied in states of check, which is never a valid state of a chess game.
Panics
Panics if the Board is currently in check.
unsafe fn undo_null_move(&mut self)
[src]
Undo a "Null Move" to the Board, returning to the previous state.
Safety
This method should only be used if it can be guaranteed that the last played move from the current state is a Null-Move. Otherwise, a panic will occur.
fn generate_moves(&self) -> Vec<BitMove>
[src]
Get a List of legal [BitMove]s for the player whose turn it is to move.
This method already takes into account if the Board is currently in check, and will return legal moves only.
fn generate_moves_of_type(&self, gen_type: GenTypes) -> Vec<BitMove>
[src]
Get a List of legal [BitMove]s for the player whose turn it is to move or a certain type.
This method already takes into account if the Board is currently in check, and will return legal moves only. If a non-ALL GenType is supplied, only a subset of the total moves will be given.
Panics
Panics if given [GenTypes::QuietChecks] while the current board is in check
impl Board
[src]
fn turn(&self) -> Player
[src]
Get the Player whose turn it is to move.
fn zobrist(&self) -> u64
[src]
Return the Zobrist Hash.
fn moves_played(&self) -> u16
[src]
Get the total number of moves played.
fn depth(&self) -> u16
[src]
Get the current depth (half moves from a [Board::shallow_clone()].
fn rule_50(&self) -> i16
[src]
Get the number of half-moves since a Pawn Push, castle, or capture.
fn piece_captured_last_turn(&self) -> Option<Piece>
[src]
Return the Piece, if any, that was last captured.
fn magic_helper(&self) -> &'static MagicHelper
[src]
Get a reference to the MagicHelper pre-computed BitBoards.
fn ply(&self) -> u16
[src]
Get the current ply of the board.
fn ep_square(&self) -> SQ
[src]
Get the current square of en_passant.
If the current en-passant square is none, it should return 64.
impl Board
[src]
fn get_occupied(&self) -> BitBoard
[src]
Gets the BitBoard of all pieces.
fn get_occupied_player(&self, player: Player) -> BitBoard
[src]
Get the BitBoard of the squares occupied by the given player.
fn occupied_white(&self) -> BitBoard
[src]
Returns a Bitboard consisting of only the squares occupied by the White Player.
fn occupied_black(&self) -> BitBoard
[src]
Returns a BitBoard consisting of only the squares occupied by the Black Player.
fn piece_bb(&self, player: Player, piece: Piece) -> BitBoard
[src]
Returns BitBoard of a single player and that one type of piece.
fn sliding_piece_bb(&self, player: Player) -> BitBoard
[src]
Returns the BitBoard of the Queens and Rooks of a given player.
fn diagonal_piece_bb(&self, player: Player) -> BitBoard
[src]
Returns the BitBoard of the Queens and Bishops of a given player.
fn piece_bb_both_players(&self, piece: Piece) -> BitBoard
[src]
Returns the combined BitBoard of both players for a given piece.
fn piece_two_bb_both_players(&self, piece: Piece, piece2: Piece) -> BitBoard
[src]
Returns the combined BitBoard of both players for two pieces.
fn count_piece(&self, player: Player, piece: Piece) -> u8
[src]
Get the total number of pieces of the given piece and player.
fn count_pieces_player(&self, player: Player) -> u8
[src]
Get the total number of piees a given player has.
fn count_all_pieces(&self) -> u8
[src]
Get the total number of pieces on the board.
fn piece_at_bb(&self, src_bit: BitBoard, player: Player) -> Option<Piece>
[src]
Returns the piece (if any) at the given BitBoard for a given player.
Safety
Number of bits must be equal to 1, or else a panic will occur.
fn piece_at_bb_all(&self, src_bit: BitBoard) -> Option<Piece>
[src]
Returns the piece (if any) at the given BitBoard for either player.
Safety
Number of bits must be equal to 1, or else a panic will occur.
fn piece_at_sq(&self, sq: SQ) -> Option<Piece>
[src]
Returns the Piece, if any, at the square.
fn color_of_sq(&self, sq: SQ) -> Option<Player>
[src]
Returns the Player, if any, occupying the square.
fn player_at_sq(&self, s: SQ) -> Option<Player>
[src]
Returns the player, if any, at the square.
fn king_sq(&self, player: Player) -> SQ
[src]
Returns the square of the King for a given player
fn pinned_pieces(&self, player: Player) -> BitBoard
[src]
Returns the pinned pieces of the given player.
Pinned is defined as pinned to the same players king
fn all_pinned_pieces(&self, player: Player) -> BitBoard
[src]
Returns the pinned pieces for a given players king. Can contain piece of from both players, but all are garunteed to be pinned to the given player's king.
fn pinning_pieces(&self, player: Player) -> BitBoard
[src]
Returns the pinning pieces of a given player. e.g, pieces that are pinning a piece to the opponent's king.
fn can_castle(&self, player: Player, castle_type: CastleType) -> bool
[src]
Return if a player has the possibility of castling for a given CastleType.
fn castle_impeded(&self, castle_type: CastleType) -> bool
[src]
Check if the castle path is impeded for the current player.
fn castling_rook_square(&self, castle_type: CastleType) -> SQ
[src]
Square of the Rook that is involved with the current player's castle.
fn last_move(&self) -> Option<BitMove>
[src]
Return the last move played, if any.
fn has_castled(&self, player: Player) -> bool
[src]
Returns if the current player has castled ever.
fn piece_last_captured(&self) -> Option<Piece>
[src]
Return if the piece (if any) that was captured last move.
impl Board
[src]
fn in_check(&self) -> bool
[src]
Return if current side to move is in check
fn checkmate(&self) -> bool
[src]
Return if the current side to move is in check_mate.
This method can be computationally expensive, do not use outside of Engines.
fn stalemate(&self) -> bool
[src]
Return if the current side to move is in stalemate.
This method can be computationally expensive, do not use outside of Engines.
fn checkers(&self) -> BitBoard
[src]
Return the BitBoard of Checks on the current player's king.
fn discovered_check_candidates(&self) -> BitBoard
[src]
Returns the BitBoard of pieces the current side can move to discover check.
fn pieces_pinned(&self, player: Player) -> BitBoard
[src]
Gets the Pinned pieces for the given player.
fn attackers_to(&self, sq: SQ, occupied: BitBoard) -> BitBoard
[src]
Returns a BitBoard of possible attacks / defends to a square with a given occupancy.
impl Board
[src]
fn legal_move(&self, m: BitMove) -> bool
[src]
Tests if a given move is legal.
fn gives_check(&self, m: BitMove) -> bool
[src]
Returns if a move will give check to the opposing player's King.
fn moved_piece(&self, m: BitMove) -> Piece
[src]
Returns the piece that was moved from a given BitMove.
fn captured_piece(&self, m: BitMove) -> Option<Piece>
[src]
Returns the piece that was captured, if any from a given BitMove.
impl Board
[src]
fn pretty_string(&self) -> String
[src]
Returns a prettified String of the current board, for Quick Display.
Capital Letters represent White pieces, while lower case represents Black pieces.
fn get_arc_strong_count(&self) -> usize
[src]
Return the current ARC count of the board's BoardState
fn print_debug_info(&self)
[src]
Get Debug Information.
fn pretty_print(&self)
[src]
Prints a prettified representation of the board.
fn fancy_print(&self)
[src]
Print the board alongside useful information.
Mostly for Debugging useage.