|
io-chess
UCI chess engine
|
Lazily selects the best move at each step of the search. More...
#include <MovePicker.h>
Public Member Functions | |
| MovePicker (const Movelist &moves, Move ttMove, const std::array< std::array< Move, 2 >, SearchConstants::MAX_PLY > *killers, const std::array< std::array< int, 64 >, 64 > *history, const std::array< std::array< int, 64 >, 16 > *captureHist, std::array< Move, MAX_MOVES > &captures, std::array< int, MAX_MOVES > &captureScores, std::array< Move, MAX_MOVES > &quiets, std::array< int, MAX_MOVES > &quietScores, std::array< Move, MAX_MOVES > &badCaptures, int ply, int threadId=0, Move countermove=Move(0)) | |
| Constructs a MovePicker for a specific search node. | |
| Move | nextMove (const Board &board, const Negamax *search, bool inCheck) |
| Returns the next best move according to the current phase. | |
| int | scoreMove (const Move &move, const Board &board, const Negamax *search, bool isCapture) |
| Scores a move using various heuristics depending on its type. | |
| void | generateAndScoreCaptures (const Board &board, const Negamax *search) |
| Generates, scores, and stores all valid capture moves for the current node. | |
| void | generateAndScoreKillers (const Board &board, const Negamax *search) |
| Extracts valid killer moves for the current ply and board state. | |
| void | generateAndScoreQuiets (const Board &board, const Negamax *search) |
| Generates, scores, and stores all quiet moves for the current node. | |
| template<size_t N> | |
| Move | selectBestMove (std::array< Move, N > &list, std::array< int, N > &scores, int &nextIdx, int count) |
| Selects and removes the highest-scoring move from the remaining buffer. | |
Private Attributes | |
| const Movelist & | allMoves_ |
| Reference to all legal moves generated for the current node. | |
| std::array< Move, MAX_MOVES > & | captures_ |
| External buffer for capture moves. | |
| std::array< int, MAX_MOVES > & | captureScores_ |
| External buffer for capture scores. | |
| int | captureCount_ = 0 |
| Number of captures populated. | |
| std::array< Move, 2 > | killerMoves_ |
| Local cache of killer moves for this ply. | |
| int | killerCount_ = 0 |
| Number of valid killer moves found. | |
| std::array< Move, MAX_MOVES > & | quiets_ |
| External buffer for quiet moves. | |
| std::array< int, MAX_MOVES > & | quietScores_ |
| External buffer for quiet scores. | |
| int | quietCount_ = 0 |
| Number of quiets populated. | |
| Move | ttMove_ |
| Best move retrieved from the Transposition Table (searched first). | |
| Move | countermove_ |
| Countermove heuristic response to the opponent's previous move. | |
| const std::array< std::array< Move, 2 >, SearchConstants::MAX_PLY > * | killers_ |
| Pointer to global killer heuristic table. | |
| const std::array< std::array< int, 64 >, 64 > * | history_ |
| Pointer to global history heuristic table. | |
| const std::array< std::array< int, 64 >, 16 > * | captureHist_ |
| Pointer to global capture history table. | |
| int | ply_ |
| Current distance from root. | |
| int | threadId_ |
| Thread ID for diversified move ordering in Lazy SMP. | |
| int | nextCapture_ = 0 |
| Index of the next capture to return. | |
| int | nextKiller_ = 0 |
| Index of the next killer to return. | |
| int | nextQuiet_ = 0 |
| Index of the next quiet move to return. | |
| std::array< Move, MAX_MOVES > & | badCaptures_ |
| External buffer for captures that fail SEE. | |
| int | badCaptureCount_ = 0 |
| Number of bad captures found. | |
| int | nextBadCapture_ = 0 |
| Index of the next bad capture to return. | |
| bool | capturesGenerated_ = false |
| True if capture moves have been scored and sorted. | |
| bool | killersGenerated_ = false |
| True if killer moves have been extracted. | |
| bool | quietsGenerated_ = false |
| True if quiet moves have been scored and sorted. | |
| int | nextQueenPromo_ = 0 |
| Index of the next queen promotion to return. | |
| int | queenPromoCount_ = 0 |
| Number of queen promotions found. | |
| bool | countermoveReturned_ = false |
| True if the countermove has already been returned. | |
| int | phase_ = 0 |
| Current phase: 0: Promos, 1: TT, 2: Captures, 3: Killers, 4: Countermove, 5: Quiets, 6: Bad Captures. | |
Static Private Attributes | |
| static constexpr int | MAX_MOVES = 256 |
| Maximum allowed moves, aligned to power of 2 for safety. | |
Lazily selects the best move at each step of the search.
Avoids scoring and sorting all moves upfront, which is crucial for cutoff-heavy nodes. Uses a phased approach: Transposition Table move, Queen Promotions, Good Captures (SEE > 0), Killer Moves, Countermoves, Quiet Moves, and finally Bad Captures (SEE < 0).
|
inline |
Constructs a MovePicker for a specific search node.
| moves | Generated legal moves. |
| ttMove | Best move from TT. |
| killers | Pointer to killer heuristics. |
| history | Pointer to history heuristics. |
| captureHist | Pointer to capture history heuristics. |
| captures | Pre-allocated buffer for captures. |
| captureScores | Pre-allocated buffer for capture scores. |
| quiets | Pre-allocated buffer for quiets. |
| quietScores | Pre-allocated buffer for quiet scores. |
| badCaptures | Pre-allocated buffer for bad captures. |
| ply | Current ply from root. |
| threadId | Thread ID for diversity. |
| countermove | Candidate countermove. |
Generates, scores, and stores all valid capture moves for the current node.


Extracts valid killer moves for the current ply and board state.


Generates, scores, and stores all quiet moves for the current node.


Returns the next best move according to the current phase.
Lazily processes and sorts moves only when a phase transition occurs.
| board | The current board state. |
| search | Pointer to the active Negamax search instance for SEE evaluation. |
| inCheck | True if the side to move is currently in check. |


| int MovePicker::scoreMove | ( | const Move & | move, |
| const Board & | board, | ||
| const Negamax * | search, | ||
| bool | isCapture ) |
Scores a move using various heuristics depending on its type.
| move | The move to score. |
| board | The current board state. |
| search | Pointer to the Negamax search instance. |
| isCapture | True if the move is a capture. |

| Move MovePicker::selectBestMove | ( | std::array< Move, N > & | list, |
| std::array< int, N > & | scores, | ||
| int & | nextIdx, | ||
| int | count ) |
Selects and removes the highest-scoring move from the remaining buffer.
| N | The size of the buffer. |
| list | The array of moves. |
| scores | The array of corresponding scores. |
| nextIdx | The index marking the start of unselected moves. |
| count | The total number of valid moves in the buffer. |

|
private |
Reference to all legal moves generated for the current node.
|
private |
Number of bad captures found.
External buffer for captures that fail SEE.
|
private |
Number of captures populated.
|
private |
Pointer to global capture history table.
|
private |
External buffer for capture scores.
|
private |
True if capture moves have been scored and sorted.
|
private |
Countermove heuristic response to the opponent's previous move.
|
private |
True if the countermove has already been returned.
|
private |
Pointer to global history heuristic table.
|
private |
Number of valid killer moves found.
|
private |
Local cache of killer moves for this ply.
|
private |
Pointer to global killer heuristic table.
|
private |
True if killer moves have been extracted.
|
staticconstexprprivate |
Maximum allowed moves, aligned to power of 2 for safety.
|
private |
Index of the next bad capture to return.
|
private |
Index of the next capture to return.
|
private |
Index of the next killer to return.
|
private |
Index of the next queen promotion to return.
|
private |
Index of the next quiet move to return.
|
private |
Current phase: 0: Promos, 1: TT, 2: Captures, 3: Killers, 4: Countermove, 5: Quiets, 6: Bad Captures.
|
private |
Current distance from root.
|
private |
Number of queen promotions found.
|
private |
Number of quiets populated.
|
private |
External buffer for quiet scores.
|
private |
True if quiet moves have been scored and sorted.
|
private |
Thread ID for diversified move ordering in Lazy SMP.
|
private |
Best move retrieved from the Transposition Table (searched first).