2008-08-31 23:59:13 -06:00
|
|
|
/*
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
|
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
2013-02-18 23:54:14 -07:00
|
|
|
Copyright (C) 2008-2013 Marco Costalba, Joona Kiiski, Tord Romstad
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is free software: you can redistribute it and/or modify
|
2008-08-31 23:59:13 -06:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2008-10-25 08:28:24 -06:00
|
|
|
|
2008-10-26 14:44:58 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is distributed in the hope that it will be useful,
|
2008-08-31 23:59:13 -06:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2008-10-25 08:28:24 -06:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include "movepick.h"
|
2012-08-18 03:43:13 -06:00
|
|
|
#include "thread.h"
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-01-21 05:43:24 -07:00
|
|
|
enum Sequencer {
|
2012-01-22 06:25:31 -07:00
|
|
|
MAIN_SEARCH, CAPTURES_S1, KILLERS_S1, QUIETS_1_S1, QUIETS_2_S1, BAD_CAPTURES_S1,
|
|
|
|
EVASION, EVASIONS_S2,
|
|
|
|
QSEARCH_0, CAPTURES_S3, QUIET_CHECKS_S3,
|
|
|
|
QSEARCH_1, CAPTURES_S4,
|
|
|
|
PROBCUT, CAPTURES_S5,
|
|
|
|
RECAPTURE, CAPTURES_S6,
|
|
|
|
STOP
|
2009-08-31 06:28:11 -06:00
|
|
|
};
|
|
|
|
|
2013-02-10 11:10:01 -07:00
|
|
|
// Our insertion sort, guaranteed to be stable, as is needed
|
|
|
|
void insertion_sort(MoveStack* begin, MoveStack* end)
|
|
|
|
{
|
|
|
|
MoveStack tmp, *p, *q;
|
|
|
|
|
|
|
|
for (p = begin + 1; p < end; ++p)
|
|
|
|
{
|
|
|
|
tmp = *p;
|
|
|
|
for (q = p; q != begin && *(q-1) < tmp; --q)
|
|
|
|
*q = *(q-1);
|
|
|
|
*q = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-15 15:24:18 -06:00
|
|
|
// Unary predicate used by std::partition to split positive scores from remaining
|
2011-07-14 05:12:49 -06:00
|
|
|
// ones so to sort separately the two sets, and with the second sort delayed.
|
2012-09-09 02:17:31 -06:00
|
|
|
inline bool has_positive_score(const MoveStack& ms) { return ms.score > 0; }
|
2011-07-14 05:12:49 -06:00
|
|
|
|
2012-09-09 02:17:31 -06:00
|
|
|
// Picks and moves to the front the best move in the range [begin, end),
|
2011-07-15 15:24:18 -06:00
|
|
|
// it is faster than sorting all the moves in advance when moves are few, as
|
2011-07-14 05:12:49 -06:00
|
|
|
// normally are the possible captures.
|
2012-09-09 02:17:31 -06:00
|
|
|
inline MoveStack* pick_best(MoveStack* begin, MoveStack* end)
|
2011-07-14 05:12:49 -06:00
|
|
|
{
|
2012-09-09 02:17:31 -06:00
|
|
|
std::swap(*begin, *std::max_element(begin, end));
|
|
|
|
return begin;
|
2011-07-14 05:12:49 -06:00
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-21 15:32:48 -07:00
|
|
|
|
|
|
|
/// Constructors of the MovePicker class. As arguments we pass information
|
2008-08-31 23:59:13 -06:00
|
|
|
/// to help it to return the presumably good moves first, to decide which
|
|
|
|
/// moves to return (in the quiescence search, for instance, we only want to
|
|
|
|
/// search captures, promotions and some checks) and about how important good
|
|
|
|
/// move ordering is at the current node.
|
|
|
|
|
2013-05-19 13:32:52 -06:00
|
|
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h, Move* cm,
|
2013-05-15 12:35:54 -06:00
|
|
|
Search::Stack* s, Value beta) : pos(p), history(h), depth(d) {
|
2009-08-31 06:28:11 -06:00
|
|
|
|
2011-01-23 14:59:05 -07:00
|
|
|
assert(d > DEPTH_ZERO);
|
|
|
|
|
2012-01-21 15:32:48 -07:00
|
|
|
captureThreshold = 0;
|
2012-09-09 02:17:31 -06:00
|
|
|
cur = end = moves;
|
|
|
|
endBadCaptures = moves + MAX_MOVES - 1;
|
2012-08-18 03:43:13 -06:00
|
|
|
ss = s;
|
2012-01-21 15:32:48 -07:00
|
|
|
|
2012-12-25 09:59:35 -07:00
|
|
|
if (p.checkers())
|
2012-01-22 06:25:31 -07:00
|
|
|
phase = EVASION;
|
2012-01-21 15:32:48 -07:00
|
|
|
|
2011-01-23 14:59:05 -07:00
|
|
|
else
|
2009-06-02 02:35:49 -06:00
|
|
|
{
|
2012-01-22 06:25:31 -07:00
|
|
|
phase = MAIN_SEARCH;
|
|
|
|
|
2009-08-29 01:02:30 -06:00
|
|
|
killers[0].move = ss->killers[0];
|
|
|
|
killers[1].move = ss->killers[1];
|
2013-05-19 13:32:52 -06:00
|
|
|
killers[2].move = cm[0];
|
|
|
|
killers[3].move = cm[1];
|
2009-06-02 02:35:49 -06:00
|
|
|
|
2011-12-08 05:48:18 -07:00
|
|
|
// Consider sligtly negative captures as good if at low depth and far from beta
|
2012-10-22 01:50:00 -06:00
|
|
|
if (ss && ss->staticEval < beta - PawnValueMg && d < 3 * ONE_PLY)
|
2012-08-20 11:41:28 -06:00
|
|
|
captureThreshold = -PawnValueMg;
|
2010-02-27 09:09:07 -07:00
|
|
|
|
2011-12-08 05:48:18 -07:00
|
|
|
// Consider negative captures as good if still enough to reach beta
|
2012-10-22 01:50:00 -06:00
|
|
|
else if (ss && ss->staticEval > beta)
|
|
|
|
captureThreshold = beta - ss->staticEval;
|
2010-06-19 09:48:36 -06:00
|
|
|
}
|
2011-01-23 14:59:05 -07:00
|
|
|
|
2011-10-03 02:56:49 -06:00
|
|
|
ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE);
|
2012-09-09 02:17:31 -06:00
|
|
|
end += (ttMove != MOVE_NONE);
|
2011-01-23 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2013-05-15 12:35:54 -06:00
|
|
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
|
|
|
|
Square sq) : pos(p), history(h), cur(moves), end(moves) {
|
2011-01-23 14:59:05 -07:00
|
|
|
|
|
|
|
assert(d <= DEPTH_ZERO);
|
|
|
|
|
2012-12-25 09:59:35 -07:00
|
|
|
if (p.checkers())
|
2012-01-22 06:25:31 -07:00
|
|
|
phase = EVASION;
|
2012-01-21 05:43:24 -07:00
|
|
|
|
2012-01-22 03:57:42 -07:00
|
|
|
else if (d > DEPTH_QS_NO_CHECKS)
|
2012-01-22 06:25:31 -07:00
|
|
|
phase = QSEARCH_0;
|
2012-01-21 05:43:24 -07:00
|
|
|
|
2012-01-22 03:57:42 -07:00
|
|
|
else if (d > DEPTH_QS_RECAPTURES)
|
2010-01-29 08:47:04 -07:00
|
|
|
{
|
2012-01-22 06:25:31 -07:00
|
|
|
phase = QSEARCH_1;
|
2008-11-15 05:00:56 -07:00
|
|
|
|
2012-01-21 15:32:48 -07:00
|
|
|
// Skip TT move if is not a capture or a promotion, this avoids qsearch
|
|
|
|
// tree explosion due to a possible perpetual check or similar rare cases
|
|
|
|
// when TT table is full.
|
|
|
|
if (ttm && !pos.is_capture_or_promotion(ttm))
|
2011-05-25 14:36:16 -06:00
|
|
|
ttm = MOVE_NONE;
|
2010-01-29 08:47:04 -07:00
|
|
|
}
|
2011-06-12 00:25:51 -06:00
|
|
|
else
|
|
|
|
{
|
2012-01-22 06:25:31 -07:00
|
|
|
phase = RECAPTURE;
|
2012-01-21 15:32:48 -07:00
|
|
|
recaptureSquare = sq;
|
2011-06-12 00:25:51 -06:00
|
|
|
ttm = MOVE_NONE;
|
|
|
|
}
|
2010-01-29 08:47:04 -07:00
|
|
|
|
2011-10-03 02:56:49 -06:00
|
|
|
ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE);
|
2012-09-09 02:17:31 -06:00
|
|
|
end += (ttMove != MOVE_NONE);
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2013-05-15 12:35:54 -06:00
|
|
|
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, PieceType pt)
|
|
|
|
: pos(p), history(h), cur(moves), end(moves) {
|
2011-05-21 10:17:11 -06:00
|
|
|
|
2012-12-25 09:59:35 -07:00
|
|
|
assert(!pos.checkers());
|
2011-05-21 10:17:11 -06:00
|
|
|
|
2012-01-21 05:43:24 -07:00
|
|
|
phase = PROBCUT;
|
2011-05-21 10:17:11 -06:00
|
|
|
|
2012-01-22 03:57:42 -07:00
|
|
|
// In ProbCut we generate only captures better than parent's captured piece
|
2012-10-21 03:49:05 -06:00
|
|
|
captureThreshold = PieceValue[MG][pt];
|
2012-01-22 06:25:31 -07:00
|
|
|
ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE);
|
2012-01-22 03:57:42 -07:00
|
|
|
|
2012-01-22 06:25:31 -07:00
|
|
|
if (ttMove && (!pos.is_capture(ttMove) || pos.see(ttMove) <= captureThreshold))
|
|
|
|
ttMove = MOVE_NONE;
|
2011-05-21 10:17:11 -06:00
|
|
|
|
2012-09-09 02:17:31 -06:00
|
|
|
end += (ttMove != MOVE_NONE);
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2008-10-25 08:28:24 -06:00
|
|
|
|
2013-02-03 01:52:39 -07:00
|
|
|
/// score() assign a numerical move ordering score to each move in a move list.
|
|
|
|
/// The moves with highest scores will be picked first.
|
|
|
|
template<>
|
|
|
|
void MovePicker::score<CAPTURES>() {
|
2008-10-25 08:28:24 -06:00
|
|
|
// Winning and equal captures in the main search are ordered by MVV/LVA.
|
2008-08-31 23:59:13 -06:00
|
|
|
// Suprisingly, this appears to perform slightly better than SEE based
|
2009-07-23 00:13:06 -06:00
|
|
|
// move ordering. The reason is probably that in a position with a winning
|
2008-08-31 23:59:13 -06:00
|
|
|
// capture, capturing a more valuable (but sufficiently defended) piece
|
2009-07-23 00:13:06 -06:00
|
|
|
// first usually doesn't hurt. The opponent will have to recapture, and
|
2008-08-31 23:59:13 -06:00
|
|
|
// the hanging piece will still be hanging (except in the unusual cases
|
2008-10-26 06:47:31 -06:00
|
|
|
// where it is possible to recapture with the hanging piece). Exchanging
|
2008-08-31 23:59:13 -06:00
|
|
|
// big pieces before capturing a hanging piece probably helps to reduce
|
2008-11-02 07:58:10 -07:00
|
|
|
// the subtree size.
|
2009-07-23 00:13:06 -06:00
|
|
|
// In main search we want to push captures with negative SEE values to
|
|
|
|
// badCaptures[] array, but instead of doing it now we delay till when
|
|
|
|
// the move has been picked up in pick_move_from_list(), this way we save
|
|
|
|
// some SEE calls in case we get a cutoff (idea from Pablo Vazquez).
|
2008-10-26 06:51:12 -06:00
|
|
|
Move m;
|
|
|
|
|
2012-09-09 02:17:31 -06:00
|
|
|
for (MoveStack* it = moves; it != end; ++it)
|
2008-10-16 06:25:56 -06:00
|
|
|
{
|
2012-09-09 02:17:31 -06:00
|
|
|
m = it->move;
|
2012-10-21 03:49:05 -06:00
|
|
|
it->score = PieceValue[MG][pos.piece_on(to_sq(m))]
|
2012-09-09 02:17:31 -06:00
|
|
|
- type_of(pos.piece_moved(m));
|
2011-06-11 15:11:17 -06:00
|
|
|
|
2012-06-24 03:08:16 -06:00
|
|
|
if (type_of(m) == PROMOTION)
|
2013-02-03 01:01:55 -07:00
|
|
|
it->score += PieceValue[MG][promotion_type(m)] - PieceValue[MG][PAWN];
|
|
|
|
|
|
|
|
else if (type_of(m) == ENPASSANT)
|
|
|
|
it->score += PieceValue[MG][PAWN];
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-03 01:52:39 -07:00
|
|
|
template<>
|
|
|
|
void MovePicker::score<QUIETS>() {
|
2011-04-16 03:25:22 -06:00
|
|
|
|
2009-08-29 01:02:30 -06:00
|
|
|
Move m;
|
2008-10-15 00:18:05 -06:00
|
|
|
|
2012-09-09 02:17:31 -06:00
|
|
|
for (MoveStack* it = moves; it != end; ++it)
|
2008-10-15 00:18:05 -06:00
|
|
|
{
|
2012-09-09 02:17:31 -06:00
|
|
|
m = it->move;
|
2013-05-15 12:35:54 -06:00
|
|
|
it->score = history[pos.piece_moved(m)][to_sq(m)];
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-03 01:52:39 -07:00
|
|
|
template<>
|
|
|
|
void MovePicker::score<EVASIONS>() {
|
2012-01-21 15:32:48 -07:00
|
|
|
// Try good captures ordered by MVV/LVA, then non-captures if destination square
|
|
|
|
// is not under attack, ordered by history value, then bad-captures and quiet
|
|
|
|
// moves with a negative SEE. This last group is ordered by the SEE score.
|
2009-08-29 01:02:30 -06:00
|
|
|
Move m;
|
2009-10-31 03:51:04 -06:00
|
|
|
int seeScore;
|
2009-08-29 01:02:30 -06:00
|
|
|
|
2012-09-09 02:17:31 -06:00
|
|
|
for (MoveStack* it = moves; it != end; ++it)
|
2008-11-02 07:58:10 -07:00
|
|
|
{
|
2012-09-09 02:17:31 -06:00
|
|
|
m = it->move;
|
2009-11-05 06:40:51 -07:00
|
|
|
if ((seeScore = pos.see_sign(m)) < 0)
|
2013-05-15 12:35:54 -06:00
|
|
|
it->score = seeScore - HistoryStats::Max; // At the bottom
|
2013-02-03 01:52:39 -07:00
|
|
|
|
2011-10-03 02:56:49 -06:00
|
|
|
else if (pos.is_capture(m))
|
2012-10-21 03:49:05 -06:00
|
|
|
it->score = PieceValue[MG][pos.piece_on(to_sq(m))]
|
2013-05-15 12:35:54 -06:00
|
|
|
- type_of(pos.piece_moved(m)) + HistoryStats::Max;
|
2009-10-31 03:51:04 -06:00
|
|
|
else
|
2013-05-15 12:35:54 -06:00
|
|
|
it->score = history[pos.piece_moved(m)][to_sq(m)];
|
2008-11-02 07:58:10 -07:00
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-21 15:32:48 -07:00
|
|
|
|
2013-02-03 01:52:39 -07:00
|
|
|
/// generate_next() generates, scores and sorts the next bunch of moves, when
|
|
|
|
/// there are no more moves to try for the current phase.
|
2012-01-21 15:32:48 -07:00
|
|
|
|
2012-01-22 06:25:31 -07:00
|
|
|
void MovePicker::generate_next() {
|
2012-01-21 15:32:48 -07:00
|
|
|
|
2012-09-09 02:17:31 -06:00
|
|
|
cur = moves;
|
2012-01-21 15:32:48 -07:00
|
|
|
|
|
|
|
switch (++phase) {
|
|
|
|
|
2012-01-22 03:57:42 -07:00
|
|
|
case CAPTURES_S1: case CAPTURES_S3: case CAPTURES_S4: case CAPTURES_S5: case CAPTURES_S6:
|
2012-09-09 02:17:31 -06:00
|
|
|
end = generate<CAPTURES>(pos, moves);
|
2013-02-03 01:52:39 -07:00
|
|
|
score<CAPTURES>();
|
2012-01-21 15:32:48 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
case KILLERS_S1:
|
2012-09-09 02:17:31 -06:00
|
|
|
cur = killers;
|
2013-05-15 13:31:45 -06:00
|
|
|
end = cur + 2;
|
|
|
|
|
|
|
|
if ((cur+3)->move && (cur+3)->move == (cur+2)->move) // Due to a SMP race
|
|
|
|
(cur+3)->move = MOVE_NONE;
|
|
|
|
|
|
|
|
// Be sure countermoves are different from killers
|
|
|
|
if ((cur+2)->move != cur->move && (cur+2)->move != (cur+1)->move)
|
|
|
|
end++;
|
|
|
|
|
|
|
|
if ((cur+3)->move != cur->move && (cur+3)->move != (cur+1)->move)
|
|
|
|
(end++)->move = (cur+3)->move;
|
2012-01-21 15:32:48 -07:00
|
|
|
return;
|
|
|
|
|
2012-01-21 10:45:18 -07:00
|
|
|
case QUIETS_1_S1:
|
2012-09-09 02:17:31 -06:00
|
|
|
endQuiets = end = generate<QUIETS>(pos, moves);
|
2013-02-03 01:52:39 -07:00
|
|
|
score<QUIETS>();
|
2012-09-09 02:17:31 -06:00
|
|
|
end = std::partition(cur, end, has_positive_score);
|
2013-02-10 11:10:01 -07:00
|
|
|
insertion_sort(cur, end);
|
2012-01-21 15:32:48 -07:00
|
|
|
return;
|
|
|
|
|
2012-01-21 10:45:18 -07:00
|
|
|
case QUIETS_2_S1:
|
2012-09-09 02:17:31 -06:00
|
|
|
cur = end;
|
|
|
|
end = endQuiets;
|
2012-01-21 15:32:48 -07:00
|
|
|
if (depth >= 3 * ONE_PLY)
|
2013-02-10 11:10:01 -07:00
|
|
|
insertion_sort(cur, end);
|
2012-01-21 15:32:48 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
case BAD_CAPTURES_S1:
|
2012-01-21 12:53:42 -07:00
|
|
|
// Just pick them in reverse order to get MVV/LVA ordering
|
2012-09-09 02:17:31 -06:00
|
|
|
cur = moves + MAX_MOVES - 1;
|
|
|
|
end = endBadCaptures;
|
2012-01-21 15:32:48 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
case EVASIONS_S2:
|
2012-09-09 02:17:31 -06:00
|
|
|
end = generate<EVASIONS>(pos, moves);
|
2013-02-03 01:52:39 -07:00
|
|
|
if (end > moves + 1)
|
|
|
|
score<EVASIONS>();
|
2012-01-21 15:32:48 -07:00
|
|
|
return;
|
|
|
|
|
2012-01-21 10:45:18 -07:00
|
|
|
case QUIET_CHECKS_S3:
|
2012-09-09 02:17:31 -06:00
|
|
|
end = generate<QUIET_CHECKS>(pos, moves);
|
2012-01-21 15:32:48 -07:00
|
|
|
return;
|
|
|
|
|
2012-01-22 06:25:31 -07:00
|
|
|
case EVASION: case QSEARCH_0: case QSEARCH_1: case PROBCUT: case RECAPTURE:
|
|
|
|
phase = STOP;
|
|
|
|
case STOP:
|
2012-09-09 02:17:31 -06:00
|
|
|
end = cur + 1; // Avoid another next_phase() call
|
2012-01-21 15:32:48 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-03 01:52:39 -07:00
|
|
|
/// next_move() is the most important method of the MovePicker class. It returns
|
|
|
|
/// a new pseudo legal move every time is called, until there are no more moves
|
|
|
|
/// left. It picks the move with the biggest score from a list of generated moves
|
|
|
|
/// taking care not returning the ttMove if has already been searched previously.
|
2012-08-18 03:43:13 -06:00
|
|
|
template<>
|
|
|
|
Move MovePicker::next_move<false>() {
|
2008-10-16 06:25:56 -06:00
|
|
|
|
2009-08-30 02:42:55 -06:00
|
|
|
Move move;
|
|
|
|
|
2009-08-27 01:12:51 -06:00
|
|
|
while (true)
|
|
|
|
{
|
2012-09-09 02:17:31 -06:00
|
|
|
while (cur == end)
|
2012-01-22 06:25:31 -07:00
|
|
|
generate_next();
|
2010-02-05 10:17:52 -07:00
|
|
|
|
2011-04-16 04:24:30 -06:00
|
|
|
switch (phase) {
|
2010-02-05 10:17:52 -07:00
|
|
|
|
2012-01-22 06:25:31 -07:00
|
|
|
case MAIN_SEARCH: case EVASION: case QSEARCH_0: case QSEARCH_1: case PROBCUT:
|
2012-09-09 02:17:31 -06:00
|
|
|
cur++;
|
2011-05-25 14:36:16 -06:00
|
|
|
return ttMove;
|
2011-04-16 04:24:30 -06:00
|
|
|
|
2012-01-21 10:45:18 -07:00
|
|
|
case CAPTURES_S1:
|
2012-09-09 02:17:31 -06:00
|
|
|
move = pick_best(cur++, end)->move;
|
2011-05-25 14:36:16 -06:00
|
|
|
if (move != ttMove)
|
2011-04-16 04:24:30 -06:00
|
|
|
{
|
2012-01-21 15:32:48 -07:00
|
|
|
assert(captureThreshold <= 0); // Otherwise we cannot use see_sign()
|
2011-05-21 10:17:11 -06:00
|
|
|
|
2012-01-21 12:53:42 -07:00
|
|
|
if (pos.see_sign(move) >= captureThreshold)
|
2009-08-27 01:12:51 -06:00
|
|
|
return move;
|
2009-08-30 02:42:55 -06:00
|
|
|
|
2011-09-17 09:41:01 -06:00
|
|
|
// Losing capture, move it to the tail of the array
|
2012-09-09 02:17:31 -06:00
|
|
|
(endBadCaptures--)->move = move;
|
2011-04-16 04:24:30 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-01-21 05:43:24 -07:00
|
|
|
case KILLERS_S1:
|
2012-09-09 02:17:31 -06:00
|
|
|
move = (cur++)->move;
|
2012-04-28 04:08:10 -06:00
|
|
|
if ( move != MOVE_NONE
|
|
|
|
&& pos.is_pseudo_legal(move)
|
|
|
|
&& move != ttMove
|
2011-10-03 02:56:49 -06:00
|
|
|
&& !pos.is_capture(move))
|
2011-04-16 04:24:30 -06:00
|
|
|
return move;
|
|
|
|
break;
|
|
|
|
|
2012-01-22 06:25:31 -07:00
|
|
|
case QUIETS_1_S1: case QUIETS_2_S1:
|
2012-09-09 02:17:31 -06:00
|
|
|
move = (cur++)->move;
|
2011-05-25 14:36:16 -06:00
|
|
|
if ( move != ttMove
|
2011-04-16 04:24:30 -06:00
|
|
|
&& move != killers[0].move
|
2013-05-12 14:21:46 -06:00
|
|
|
&& move != killers[1].move
|
2013-05-15 13:31:45 -06:00
|
|
|
&& move != killers[2].move
|
|
|
|
&& move != killers[3].move)
|
2009-08-30 02:42:55 -06:00
|
|
|
return move;
|
2011-04-16 04:24:30 -06:00
|
|
|
break;
|
2009-08-30 02:42:55 -06:00
|
|
|
|
2012-01-21 05:43:24 -07:00
|
|
|
case BAD_CAPTURES_S1:
|
2012-09-09 02:17:31 -06:00
|
|
|
return (cur--)->move;
|
2009-10-20 04:38:20 -06:00
|
|
|
|
2012-01-22 06:25:31 -07:00
|
|
|
case EVASIONS_S2: case CAPTURES_S3: case CAPTURES_S4:
|
2012-09-09 02:17:31 -06:00
|
|
|
move = pick_best(cur++, end)->move;
|
2011-05-25 14:36:16 -06:00
|
|
|
if (move != ttMove)
|
2011-04-16 04:24:30 -06:00
|
|
|
return move;
|
|
|
|
break;
|
2009-08-26 07:33:17 -06:00
|
|
|
|
2012-01-21 15:32:48 -07:00
|
|
|
case CAPTURES_S5:
|
2012-09-09 02:17:31 -06:00
|
|
|
move = pick_best(cur++, end)->move;
|
2012-01-22 03:57:42 -07:00
|
|
|
if (move != ttMove && pos.see(move) > captureThreshold)
|
2012-01-21 15:32:48 -07:00
|
|
|
return move;
|
|
|
|
break;
|
|
|
|
|
2012-01-21 10:45:18 -07:00
|
|
|
case CAPTURES_S6:
|
2012-09-09 02:17:31 -06:00
|
|
|
move = pick_best(cur++, end)->move;
|
2012-01-01 08:00:00 -07:00
|
|
|
if (to_sq(move) == recaptureSquare)
|
2011-06-12 00:25:51 -06:00
|
|
|
return move;
|
|
|
|
break;
|
|
|
|
|
2012-01-21 10:45:18 -07:00
|
|
|
case QUIET_CHECKS_S3:
|
2012-09-09 02:17:31 -06:00
|
|
|
move = (cur++)->move;
|
2011-05-25 14:36:16 -06:00
|
|
|
if (move != ttMove)
|
2011-04-16 04:24:30 -06:00
|
|
|
return move;
|
|
|
|
break;
|
2009-08-26 07:33:17 -06:00
|
|
|
|
2012-01-22 06:25:31 -07:00
|
|
|
case STOP:
|
2011-04-16 04:24:30 -06:00
|
|
|
return MOVE_NONE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(false);
|
2008-10-25 08:28:24 -06:00
|
|
|
}
|
2009-08-27 01:12:51 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-18 03:43:13 -06:00
|
|
|
|
|
|
|
|
|
|
|
/// 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
|
2013-02-03 01:52:39 -07:00
|
|
|
/// safe so must be lock protected by the caller.
|
2012-08-18 03:43:13 -06:00
|
|
|
template<>
|
2013-03-01 01:38:43 -07:00
|
|
|
Move MovePicker::next_move<true>() { return ss->splitPoint->movePicker->next_move<false>(); }
|