mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Retire MovePickerExt struct
Templetize MovePicker::next_move() member function instead. It is easier and we also avoid the forwarding of MovePicker() c'tor arguments in the common case. Suggested by Rein Halbersma. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
90ec4a403a
commit
9de4ee6d32
3 changed files with 19 additions and 29 deletions
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -58,13 +59,14 @@ namespace {
|
||||||
/// move ordering is at the current node.
|
/// move ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
|
||||||
Search::Stack* ss, Value beta) : pos(p), H(h), depth(d) {
|
Search::Stack* s, Value beta) : pos(p), H(h), depth(d) {
|
||||||
|
|
||||||
assert(d > DEPTH_ZERO);
|
assert(d > DEPTH_ZERO);
|
||||||
|
|
||||||
captureThreshold = 0;
|
captureThreshold = 0;
|
||||||
curMove = lastMove = moves;
|
curMove = lastMove = moves;
|
||||||
lastBadCapture = moves + MAX_MOVES - 1;
|
lastBadCapture = moves + MAX_MOVES - 1;
|
||||||
|
ss = s;
|
||||||
|
|
||||||
if (p.in_check())
|
if (p.in_check())
|
||||||
phase = EVASION;
|
phase = EVASION;
|
||||||
|
@ -270,10 +272,9 @@ void MovePicker::generate_next() {
|
||||||
/// It returns a new pseudo legal move every time it is called, until there
|
/// It returns a new pseudo legal move every time it is called, until there
|
||||||
/// are no more moves left. It picks the move with the biggest score from a list
|
/// are no more moves left. It picks the move with the biggest score from a list
|
||||||
/// of generated moves taking care not to return the tt move if has already been
|
/// of generated moves taking care not to return the tt move if has already been
|
||||||
/// searched previously. Note that this function is not thread safe so should be
|
/// searched previously.
|
||||||
/// lock protected by caller when accessed through a shared MovePicker object.
|
template<>
|
||||||
|
Move MovePicker::next_move<false>() {
|
||||||
Move MovePicker::next_move() {
|
|
||||||
|
|
||||||
Move move;
|
Move move;
|
||||||
|
|
||||||
|
@ -354,3 +355,10 @@ Move MovePicker::next_move() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Version of next_move() to use at split point nodes where the move is grabbed
|
||||||
|
/// from the split point's shared MovePicker object. This function is not thread
|
||||||
|
/// safe so should be lock protected by the caller.
|
||||||
|
template<>
|
||||||
|
Move MovePicker::next_move<true>() { return ss->sp->mp->next_move<false>(); }
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
MovePicker(const Position&, Move, Depth, const History&, Search::Stack*, Value);
|
MovePicker(const Position&, Move, Depth, const History&, Search::Stack*, Value);
|
||||||
MovePicker(const Position&, Move, Depth, const History&, Square);
|
MovePicker(const Position&, Move, Depth, const History&, Square);
|
||||||
MovePicker(const Position&, Move, const History&, PieceType);
|
MovePicker(const Position&, Move, const History&, PieceType);
|
||||||
Move next_move();
|
template<bool SpNode> Move next_move();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void score_captures();
|
void score_captures();
|
||||||
|
@ -51,6 +51,7 @@ private:
|
||||||
|
|
||||||
const Position& pos;
|
const Position& pos;
|
||||||
const History& H;
|
const History& H;
|
||||||
|
Search::Stack* ss;
|
||||||
Depth depth;
|
Depth depth;
|
||||||
Move ttMove;
|
Move ttMove;
|
||||||
MoveStack killers[2];
|
MoveStack killers[2];
|
||||||
|
|
|
@ -146,25 +146,6 @@ namespace {
|
||||||
Move do_skill_level();
|
Move do_skill_level();
|
||||||
string uci_pv(const Position& pos, int depth, Value alpha, Value beta);
|
string uci_pv(const Position& pos, int depth, Value alpha, Value beta);
|
||||||
|
|
||||||
// MovePickerExt class template extends MovePicker and allows to choose at
|
|
||||||
// compile time the proper moves source according to the type of node. In the
|
|
||||||
// default case we simply create and use a standard MovePicker object.
|
|
||||||
template<bool SpNode> struct MovePickerExt : public MovePicker {
|
|
||||||
|
|
||||||
MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, Stack* ss, Value b)
|
|
||||||
: MovePicker(p, ttm, d, h, ss, b) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
// In case of a SpNode we use split point's shared MovePicker object as moves source
|
|
||||||
template<> struct MovePickerExt<true> : public MovePicker {
|
|
||||||
|
|
||||||
MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, Stack* ss, Value b)
|
|
||||||
: MovePicker(p, ttm, d, h, ss, b), mp(ss->sp->mp) {}
|
|
||||||
|
|
||||||
Move next_move() { return mp->next_move(); }
|
|
||||||
MovePicker* mp;
|
|
||||||
};
|
|
||||||
|
|
||||||
// is_dangerous() checks whether a move belongs to some classes of known
|
// is_dangerous() checks whether a move belongs to some classes of known
|
||||||
// 'dangerous' moves so that we avoid to prune it.
|
// 'dangerous' moves so that we avoid to prune it.
|
||||||
FORCE_INLINE bool is_dangerous(const Position& pos, Move m, bool captureOrPromotion) {
|
FORCE_INLINE bool is_dangerous(const Position& pos, Move m, bool captureOrPromotion) {
|
||||||
|
@ -779,7 +760,7 @@ namespace {
|
||||||
MovePicker mp(pos, ttMove, H, pos.captured_piece_type());
|
MovePicker mp(pos, ttMove, H, pos.captured_piece_type());
|
||||||
CheckInfo ci(pos);
|
CheckInfo ci(pos);
|
||||||
|
|
||||||
while ((move = mp.next_move()) != MOVE_NONE)
|
while ((move = mp.next_move<false>()) != MOVE_NONE)
|
||||||
if (pos.pl_move_is_legal(move, ci.pinned))
|
if (pos.pl_move_is_legal(move, ci.pinned))
|
||||||
{
|
{
|
||||||
ss->currentMove = move;
|
ss->currentMove = move;
|
||||||
|
@ -808,7 +789,7 @@ namespace {
|
||||||
|
|
||||||
split_point_start: // At split points actual search starts from here
|
split_point_start: // At split points actual search starts from here
|
||||||
|
|
||||||
MovePickerExt<SpNode> mp(pos, ttMove, depth, H, ss, PvNode ? -VALUE_INFINITE : beta);
|
MovePicker mp(pos, ttMove, depth, H, ss, PvNode ? -VALUE_INFINITE : beta);
|
||||||
CheckInfo ci(pos);
|
CheckInfo ci(pos);
|
||||||
futilityBase = ss->eval + ss->evalMargin;
|
futilityBase = ss->eval + ss->evalMargin;
|
||||||
singularExtensionNode = !RootNode
|
singularExtensionNode = !RootNode
|
||||||
|
@ -822,7 +803,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
// Step 11. Loop through moves
|
// Step 11. Loop through moves
|
||||||
// Loop through all pseudo-legal moves until no moves remain or a beta cutoff occurs
|
// Loop through all pseudo-legal moves until no moves remain or a beta cutoff occurs
|
||||||
while ( bestValue < beta
|
while ( bestValue < beta
|
||||||
&& (move = mp.next_move()) != MOVE_NONE
|
&& (move = mp.next_move<SpNode>()) != MOVE_NONE
|
||||||
&& !thisThread->cutoff_occurred()
|
&& !thisThread->cutoff_occurred()
|
||||||
&& !Signals.stop)
|
&& !Signals.stop)
|
||||||
{
|
{
|
||||||
|
@ -1213,7 +1194,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
|
|
||||||
// Loop through the moves until no moves remain or a beta cutoff occurs
|
// Loop through the moves until no moves remain or a beta cutoff occurs
|
||||||
while ( bestValue < beta
|
while ( bestValue < beta
|
||||||
&& (move = mp.next_move()) != MOVE_NONE)
|
&& (move = mp.next_move<false>()) != MOVE_NONE)
|
||||||
{
|
{
|
||||||
assert(is_ok(move));
|
assert(is_ok(move));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue