mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Templetize move generation API
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
1e7aaed8bc
commit
12f4bbc8f2
4 changed files with 29 additions and 31 deletions
|
@ -161,8 +161,8 @@ namespace {
|
|||
|
||||
/// generate_captures() generates all pseudo-legal captures and queen
|
||||
/// promotions. Returns a pointer to the end of the move list.
|
||||
|
||||
MoveStack* generate_captures(const Position& pos, MoveStack* mlist) {
|
||||
template<>
|
||||
MoveStack* generate<CAPTURES>(const Position& pos, MoveStack* mlist) {
|
||||
|
||||
assert(pos.is_ok());
|
||||
assert(!pos.is_check());
|
||||
|
@ -181,8 +181,8 @@ MoveStack* generate_captures(const Position& pos, MoveStack* mlist) {
|
|||
|
||||
/// generate_noncaptures() generates all pseudo-legal non-captures and
|
||||
/// underpromotions. Returns a pointer to the end of the move list.
|
||||
|
||||
MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
|
||||
template<>
|
||||
MoveStack* generate<NON_CAPTURES>(const Position& pos, MoveStack* mlist) {
|
||||
|
||||
assert(pos.is_ok());
|
||||
assert(!pos.is_check());
|
||||
|
@ -203,8 +203,8 @@ MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
|
|||
|
||||
/// generate_non_evasions() generates all pseudo-legal captures and
|
||||
/// non-captures. Returns a pointer to the end of the move list.
|
||||
|
||||
MoveStack* generate_non_evasions(const Position& pos, MoveStack* mlist) {
|
||||
template<>
|
||||
MoveStack* generate<NON_EVASIONS>(const Position& pos, MoveStack* mlist) {
|
||||
|
||||
assert(pos.is_ok());
|
||||
assert(!pos.is_check());
|
||||
|
@ -229,8 +229,8 @@ MoveStack* generate_non_evasions(const Position& pos, MoveStack* mlist) {
|
|||
|
||||
/// generate_non_capture_checks() generates all pseudo-legal non-captures and knight
|
||||
/// underpromotions that give check. Returns a pointer to the end of the move list.
|
||||
|
||||
MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist) {
|
||||
template<>
|
||||
MoveStack* generate<NON_CAPTURE_CHECKS>(const Position& pos, MoveStack* mlist) {
|
||||
|
||||
assert(pos.is_ok());
|
||||
assert(!pos.is_check());
|
||||
|
@ -270,8 +270,8 @@ MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist) {
|
|||
|
||||
/// generate_evasions() generates all pseudo-legal check evasions when
|
||||
/// the side to move is in check. Returns a pointer to the end of the move list.
|
||||
|
||||
MoveStack* generate_evasions(const Position& pos, MoveStack* mlist) {
|
||||
template<>
|
||||
MoveStack* generate<EVASIONS>(const Position& pos, MoveStack* mlist) {
|
||||
|
||||
assert(pos.is_ok());
|
||||
assert(pos.is_check());
|
||||
|
@ -347,8 +347,8 @@ MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLega
|
|||
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||
|
||||
// Generate pseudo-legal moves
|
||||
last = pos.is_check() ? generate_evasions(pos, mlist)
|
||||
: generate_non_evasions(pos, mlist);
|
||||
last = pos.is_check() ? generate<EVASIONS>(pos, mlist)
|
||||
: generate<NON_EVASIONS>(pos, mlist);
|
||||
if (pseudoLegal)
|
||||
return last;
|
||||
|
||||
|
|
|
@ -21,22 +21,20 @@
|
|||
#if !defined(MOVEGEN_H_INCLUDED)
|
||||
#define MOVEGEN_H_INCLUDED
|
||||
|
||||
////
|
||||
//// Includes
|
||||
////
|
||||
|
||||
#include "position.h"
|
||||
|
||||
enum MoveGeneration {
|
||||
CAPTURES,
|
||||
NON_CAPTURES,
|
||||
NON_CAPTURE_CHECKS,
|
||||
EVASIONS,
|
||||
NON_EVASIONS,
|
||||
ALL_MOVES
|
||||
};
|
||||
|
||||
////
|
||||
//// Prototypes
|
||||
////
|
||||
template<MoveGeneration T>
|
||||
MoveStack* generate(const Position& pos, MoveStack* mlist);
|
||||
|
||||
extern MoveStack* generate_captures(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_evasions(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_non_evasions(const Position& pos, MoveStack* mlist);
|
||||
extern MoveStack* generate_moves(const Position& pos, MoveStack* mlist, bool pseudoLegal = false);
|
||||
extern bool move_is_legal(const Position& pos, const Move m, Bitboard pinned);
|
||||
extern bool move_is_legal(const Position& pos, const Move m);
|
||||
|
|
|
@ -132,7 +132,7 @@ void MovePicker::go_next_phase() {
|
|||
return;
|
||||
|
||||
case PH_GOOD_CAPTURES:
|
||||
lastMove = generate_captures(pos, moves);
|
||||
lastMove = generate<CAPTURES>(pos, moves);
|
||||
score_captures();
|
||||
return;
|
||||
|
||||
|
@ -142,7 +142,7 @@ void MovePicker::go_next_phase() {
|
|||
return;
|
||||
|
||||
case PH_NONCAPTURES:
|
||||
lastMove = generate_noncaptures(pos, moves);
|
||||
lastMove = generate<NON_CAPTURES>(pos, moves);
|
||||
score_noncaptures();
|
||||
sort_moves(moves, lastMove, &lastGoodNonCapture);
|
||||
return;
|
||||
|
@ -156,17 +156,17 @@ void MovePicker::go_next_phase() {
|
|||
|
||||
case PH_EVASIONS:
|
||||
assert(pos.is_check());
|
||||
lastMove = generate_evasions(pos, moves);
|
||||
lastMove = generate<EVASIONS>(pos, moves);
|
||||
score_evasions();
|
||||
return;
|
||||
|
||||
case PH_QCAPTURES:
|
||||
lastMove = generate_captures(pos, moves);
|
||||
lastMove = generate<CAPTURES>(pos, moves);
|
||||
score_captures();
|
||||
return;
|
||||
|
||||
case PH_QCHECKS:
|
||||
lastMove = generate_non_capture_checks(pos, moves);
|
||||
lastMove = generate<NON_CAPTURE_CHECKS>(pos, moves);
|
||||
return;
|
||||
|
||||
case PH_STOP:
|
||||
|
|
|
@ -1730,8 +1730,8 @@ bool Position::has_mate_threat() {
|
|||
do_null_move(st1);
|
||||
|
||||
// Then generate pseudo-legal moves that could give check
|
||||
last = generate_non_capture_checks(*this, mlist);
|
||||
last = generate_captures(*this, last);
|
||||
last = generate<NON_CAPTURE_CHECKS>(*this, mlist);
|
||||
last = generate<CAPTURES>(*this, last);
|
||||
|
||||
// Loop through the moves, and see if one of them gives mate
|
||||
Bitboard pinned = pinned_pieces(sideToMove);
|
||||
|
|
Loading…
Add table
Reference in a new issue