1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 17:19:36 +00:00

Templetize move generation API

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-01-05 19:00:30 +01:00
parent 1e7aaed8bc
commit 12f4bbc8f2
4 changed files with 29 additions and 31 deletions

View file

@ -161,8 +161,8 @@ namespace {
/// generate_captures() generates all pseudo-legal captures and queen /// generate_captures() generates all pseudo-legal captures and queen
/// promotions. Returns a pointer to the end of the move list. /// promotions. Returns a pointer to the end of the move list.
template<>
MoveStack* generate_captures(const Position& pos, MoveStack* mlist) { MoveStack* generate<CAPTURES>(const Position& pos, MoveStack* mlist) {
assert(pos.is_ok()); assert(pos.is_ok());
assert(!pos.is_check()); 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 /// generate_noncaptures() generates all pseudo-legal non-captures and
/// underpromotions. Returns a pointer to the end of the move list. /// underpromotions. Returns a pointer to the end of the move list.
template<>
MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) { MoveStack* generate<NON_CAPTURES>(const Position& pos, MoveStack* mlist) {
assert(pos.is_ok()); assert(pos.is_ok());
assert(!pos.is_check()); 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 /// generate_non_evasions() generates all pseudo-legal captures and
/// non-captures. Returns a pointer to the end of the move list. /// non-captures. Returns a pointer to the end of the move list.
template<>
MoveStack* generate_non_evasions(const Position& pos, MoveStack* mlist) { MoveStack* generate<NON_EVASIONS>(const Position& pos, MoveStack* mlist) {
assert(pos.is_ok()); assert(pos.is_ok());
assert(!pos.is_check()); 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 /// 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. /// underpromotions that give check. Returns a pointer to the end of the move list.
template<>
MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist) { MoveStack* generate<NON_CAPTURE_CHECKS>(const Position& pos, MoveStack* mlist) {
assert(pos.is_ok()); assert(pos.is_ok());
assert(!pos.is_check()); 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 /// 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. /// the side to move is in check. Returns a pointer to the end of the move list.
template<>
MoveStack* generate_evasions(const Position& pos, MoveStack* mlist) { MoveStack* generate<EVASIONS>(const Position& pos, MoveStack* mlist) {
assert(pos.is_ok()); assert(pos.is_ok());
assert(pos.is_check()); 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()); Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
// Generate pseudo-legal moves // Generate pseudo-legal moves
last = pos.is_check() ? generate_evasions(pos, mlist) last = pos.is_check() ? generate<EVASIONS>(pos, mlist)
: generate_non_evasions(pos, mlist); : generate<NON_EVASIONS>(pos, mlist);
if (pseudoLegal) if (pseudoLegal)
return last; return last;

View file

@ -21,22 +21,20 @@
#if !defined(MOVEGEN_H_INCLUDED) #if !defined(MOVEGEN_H_INCLUDED)
#define MOVEGEN_H_INCLUDED #define MOVEGEN_H_INCLUDED
////
//// Includes
////
#include "position.h" #include "position.h"
enum MoveGeneration {
CAPTURES,
NON_CAPTURES,
NON_CAPTURE_CHECKS,
EVASIONS,
NON_EVASIONS,
ALL_MOVES
};
//// template<MoveGeneration T>
//// Prototypes 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 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, Bitboard pinned);
extern bool move_is_legal(const Position& pos, const Move m); extern bool move_is_legal(const Position& pos, const Move m);

View file

@ -132,7 +132,7 @@ void MovePicker::go_next_phase() {
return; return;
case PH_GOOD_CAPTURES: case PH_GOOD_CAPTURES:
lastMove = generate_captures(pos, moves); lastMove = generate<CAPTURES>(pos, moves);
score_captures(); score_captures();
return; return;
@ -142,7 +142,7 @@ void MovePicker::go_next_phase() {
return; return;
case PH_NONCAPTURES: case PH_NONCAPTURES:
lastMove = generate_noncaptures(pos, moves); lastMove = generate<NON_CAPTURES>(pos, moves);
score_noncaptures(); score_noncaptures();
sort_moves(moves, lastMove, &lastGoodNonCapture); sort_moves(moves, lastMove, &lastGoodNonCapture);
return; return;
@ -156,17 +156,17 @@ void MovePicker::go_next_phase() {
case PH_EVASIONS: case PH_EVASIONS:
assert(pos.is_check()); assert(pos.is_check());
lastMove = generate_evasions(pos, moves); lastMove = generate<EVASIONS>(pos, moves);
score_evasions(); score_evasions();
return; return;
case PH_QCAPTURES: case PH_QCAPTURES:
lastMove = generate_captures(pos, moves); lastMove = generate<CAPTURES>(pos, moves);
score_captures(); score_captures();
return; return;
case PH_QCHECKS: case PH_QCHECKS:
lastMove = generate_non_capture_checks(pos, moves); lastMove = generate<NON_CAPTURE_CHECKS>(pos, moves);
return; return;
case PH_STOP: case PH_STOP:

View file

@ -1730,8 +1730,8 @@ bool Position::has_mate_threat() {
do_null_move(st1); do_null_move(st1);
// Then generate pseudo-legal moves that could give check // Then generate pseudo-legal moves that could give check
last = generate_non_capture_checks(*this, mlist); last = generate<NON_CAPTURE_CHECKS>(*this, mlist);
last = generate_captures(*this, last); last = generate<CAPTURES>(*this, last);
// Loop through the moves, and see if one of them gives mate // Loop through the moves, and see if one of them gives mate
Bitboard pinned = pinned_pieces(sideToMove); Bitboard pinned = pinned_pieces(sideToMove);