Expand description
§chess_move_gen
Provides structs and methods for generating chess moves efficiently
Example usage:
use chess_move_gen::*;
let mut list = MoveVec::new();
let position = &Position::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w QqKk - 0 1").unwrap();
legal_moves::<MoveVec>(position, &mut list);
assert_eq!(list.len(), 20);Ways to store moves:
MoveVec: Wraps a vector of generated moves, useful if you need to access the actual moves being generated MoveCounter: Counts moves of each kind (captures, castles, promotions etc). Useful if you are making a perft function or need statistics about moves for a position, but don’t care about the actual moves SortedMoveAdder + SortedMoveHeap: Stores genarated moves in a sorted binary heap, which are efficiently ordered as they are inserted based on a heuristic scoring and piece-square table that you provide. Use this if you want the moves to have a reasonably good initial ordering so moves that are checked first are more likely to lead to eg alpha-beta cutoffs and reduce the search tree size.
Re-exports§
pub use crate::bb::BB;
Modules§
Structs§
- Board
- Castle
- Represents a castleove
- Castling
Rights - Represents the right to castle in a particular director for a particular side
- Kind
- Represents a kind of piece (eg knight)
- Kinds
Iter - Move
- Represents a move on the chess position. Uses a compact 16 bit representation
- Move
Counter - MoveCounter implements MoveAdder and keeps a count of different types of moves added to it.
- Move
GenPreprocessing - Contains data about checkers, pinned pieces, and pinners
- Move
Score - MoveScore encodes a move and the piece-square score change that the move creates
- MoveVec
- MoveVec implements MoveAdder and collects moves in a vector.
Use
iterto access the moves once they have been added. - Piece
- Represents a piece for a particular side (eg black knight)
- Piece
Square Table - PieceSquareTable gives scores for pieces on squares from the perspective of white. See https://www.chessprogramming.org/Piece-Square_Tables
- Pieces
Iter - Position
- Position encodes all positional information and non-positional game state
- Side
- Represents a side to move
- Sorted
Move Adder - SortedMoveAdder collects moves including the piece-square score for making the move Moves are sorted by an ‘ordering score’ and stored in a provided SortedMoveHeap
- Sorted
Move Heap - Sorted
Move Heap Item - Square
- Represents a square on the chessboard
- Squares
Iter - State
- State encodes all game state except position
Constants§
- A1
- A2
- A3
- A4
- A5
- A6
- A7
- A8
- B1
- B2
- B3
- B4
- B5
- B6
- B7
- B8
- BISHOP
- BLACK
- BLACK_
BISHOP - BLACK_
KING - BLACK_
KNIGHT - BLACK_
KS - BLACK_
PAWN - BLACK_
QS - BLACK_
QUEEN - BLACK_
ROOK - C1
- C2
- C3
- C4
- C5
- C6
- C7
- C8
- D1
- D2
- D3
- D4
- D5
- D6
- D7
- D8
- E1
- E2
- E3
- E4
- E5
- E6
- E7
- E8
- F1
- F2
- F3
- F4
- F5
- F6
- F7
- F8
- G1
- G2
- G3
- G4
- G5
- G6
- G7
- G8
- H1
- H2
- H3
- H4
- H5
- H6
- H7
- H8
- KING
- KING_
SIDE - KING_
SIDE_ CASTLE - KNIGHT
- NULL_
KIND - NULL_
MOVE - NULL_
PIECE - PAWN
- QUEEN
- QUEEN_
SIDE - QUEEN_
SIDE_ CASTLE - ROOK
- STARTING_
POSITION_ FEN - WHITE
- WHITE_
BISHOP - WHITE_
KING - WHITE_
KNIGHT - WHITE_
KS - WHITE_
PAWN - WHITE_
QS - WHITE_
QUEEN - WHITE_
ROOK
Traits§
- Move
Adder - MoveAdder represents a way to collect moves from move generation functions Implementations: MoveCounter (count moves only) MoveVec (adds move to Vec) SortedMoveAdder (adds moves along with piece-square-scores to a sorted binary heap)
Functions§
- legal_
moves - Adds all legal moves to the provided MoveAdder. Returns true if mover is in check
- legal_
moves_ with_ preprocessing - Adds all legal moves to the provided MoveAdder. Returns true if moving side is in check
- loud_
legal_ moves - Adds ‘loud’ legal moves to the move list. Returns true if moving side is in check
- loud_
legal_ moves_ with_ preprocessing - movegen_
preprocessing - Generates data about checkers, pinned pieces and pinners to be used by legal_moves_with_preprocessing()
- perft
- Returns the number of nodes at the provided depth cache_bytes_per_thread must be of form 2^N bytes if multi_threading_enabled is set to true search will run concurrently accross threads equal to your CPU count
- perft_
detailed - Returns the number of moves, captures, promotions, castles and en-passant captures at the provided depth if multi_threading_enabled is set to true search will run concurrently accross threads equal to your CPU count