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)
|
2016-01-02 02:43:25 -07:00
|
|
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
2017-01-11 00:46:29 -07:00
|
|
|
Copyright (C) 2015-2017 Marco Costalba, Joona Kiiski, Gary Linscott, 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-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 {
|
|
|
|
|
2013-07-21 01:54:56 -06:00
|
|
|
enum Stages {
|
2016-09-15 00:38:20 -06:00
|
|
|
MAIN_SEARCH, CAPTURES_INIT, GOOD_CAPTURES, KILLERS, COUNTERMOVE, QUIET_INIT, QUIET, BAD_CAPTURES,
|
|
|
|
EVASION, EVASIONS_INIT, ALL_EVASIONS,
|
|
|
|
PROBCUT, PROBCUT_INIT, PROBCUT_CAPTURES,
|
|
|
|
QSEARCH_WITH_CHECKS, QCAPTURES_1_INIT, QCAPTURES_1, QCHECKS,
|
|
|
|
QSEARCH_NO_CHECKS, QCAPTURES_2_INIT, QCAPTURES_2,
|
|
|
|
QSEARCH_RECAPTURES, QRECAPTURES
|
2009-08-31 06:28:11 -06:00
|
|
|
};
|
|
|
|
|
2017-04-20 12:15:48 -06:00
|
|
|
// An insertion sort, which sorts moves in descending order up to and including a given limit.
|
|
|
|
// The order of moves smaller than the limit is left unspecified.
|
|
|
|
// To keep the implementation simple, *begin is always included in the list of sorted moves.
|
2017-04-23 08:57:48 -06:00
|
|
|
void partial_insertion_sort(ExtMove* begin, ExtMove* end, int limit)
|
2013-02-10 11:10:01 -07:00
|
|
|
{
|
2017-04-20 12:15:48 -06:00
|
|
|
for (ExtMove *sortedEnd = begin + 1, *p = begin + 1; p < end; ++p)
|
|
|
|
if (p->value >= limit)
|
|
|
|
{
|
|
|
|
ExtMove tmp = *p, *q;
|
|
|
|
*p = *sortedEnd;
|
|
|
|
for (q = sortedEnd; q != begin && *(q-1) < tmp; --q)
|
|
|
|
*q = *(q-1);
|
|
|
|
*q = tmp;
|
|
|
|
++sortedEnd;
|
|
|
|
}
|
2013-02-10 11:10:01 -07:00
|
|
|
}
|
|
|
|
|
2015-02-01 02:59:01 -07:00
|
|
|
// pick_best() finds the best move in the range (begin, end) and moves it to
|
|
|
|
// the front. It's faster than sorting all the moves in advance when there
|
2016-01-16 14:34:29 -07:00
|
|
|
// are few moves, e.g., the possible captures.
|
Retire FORCE_INLINE
No speed regression on my machine (i7-3770k, gcc 4.9.1, linux 3.16):
stat test master diff
mean 2,482,415 2,474,987 7,906
stdev 4,603 5,644 2,497
speedup 0.32%
P(speedup>0) 100.0%
Fishtest 9+0.03:
ELO: 0.26 +-1.8 (95%) LOS: 61.2%
Total: 60000 W: 12437 L: 12392 D: 35171
No functional change.
Resolves #334
2015-04-15 14:21:45 -06:00
|
|
|
Move pick_best(ExtMove* begin, ExtMove* 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));
|
2015-02-01 05:29:27 -07:00
|
|
|
return *begin;
|
2011-07-14 05:12:49 -06:00
|
|
|
}
|
2015-02-01 02:59:01 -07:00
|
|
|
|
2014-11-01 14:35:10 -06:00
|
|
|
} // namespace
|
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
|
2013-12-04 23:18:12 -07:00
|
|
|
/// to help it to return the (presumably) good moves first, to decide which
|
2008-08-31 23:59:13 -06:00
|
|
|
/// moves to return (in the quiescence search, for instance, we only want to
|
2016-01-16 14:34:29 -07:00
|
|
|
/// search captures, promotions, and some checks) and how important good move
|
2013-12-04 23:18:12 -07:00
|
|
|
/// ordering is at the current node.
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2016-04-17 08:14:07 -06:00
|
|
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, Search::Stack* s)
|
|
|
|
: pos(p), ss(s), depth(d) {
|
2009-08-31 06:28:11 -06:00
|
|
|
|
2011-01-23 14:59:05 -07:00
|
|
|
assert(d > DEPTH_ZERO);
|
|
|
|
|
2016-04-17 08:14:07 -06:00
|
|
|
Square prevSq = to_sq((ss-1)->currentMove);
|
|
|
|
countermove = pos.this_thread()->counterMoves[pos.piece_on(prevSq)][prevSq];
|
|
|
|
|
2015-07-19 03:25:14 -06:00
|
|
|
stage = pos.checkers() ? EVASION : MAIN_SEARCH;
|
|
|
|
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
2016-09-10 13:37:36 -06:00
|
|
|
stage += (ttMove == MOVE_NONE);
|
2011-01-23 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2016-04-17 08:14:07 -06:00
|
|
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, Square s)
|
|
|
|
: pos(p) {
|
2011-01-23 14:59:05 -07:00
|
|
|
|
|
|
|
assert(d <= DEPTH_ZERO);
|
|
|
|
|
2014-04-06 02:50:27 -06:00
|
|
|
if (pos.checkers())
|
2013-07-21 01:54:56 -06:00
|
|
|
stage = EVASION;
|
2012-01-21 05:43:24 -07:00
|
|
|
|
2012-01-22 03:57:42 -07:00
|
|
|
else if (d > DEPTH_QS_NO_CHECKS)
|
2015-06-04 04:25:49 -06:00
|
|
|
stage = QSEARCH_WITH_CHECKS;
|
2012-01-21 05:43:24 -07:00
|
|
|
|
2012-01-22 03:57:42 -07:00
|
|
|
else if (d > DEPTH_QS_RECAPTURES)
|
2016-09-15 00:38:20 -06:00
|
|
|
stage = QSEARCH_NO_CHECKS;
|
2008-11-15 05:00:56 -07:00
|
|
|
|
2011-06-12 00:25:51 -06:00
|
|
|
else
|
|
|
|
{
|
2016-09-15 00:38:20 -06:00
|
|
|
stage = QSEARCH_RECAPTURES;
|
2014-04-06 02:50:27 -06:00
|
|
|
recaptureSquare = s;
|
2016-09-10 13:37:36 -06:00
|
|
|
return;
|
2011-06-12 00:25:51 -06:00
|
|
|
}
|
2010-01-29 08:47:04 -07:00
|
|
|
|
2015-07-19 03:25:14 -06:00
|
|
|
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
2016-09-10 13:37:36 -06:00
|
|
|
stage += (ttMove == MOVE_NONE);
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2016-04-17 08:14:07 -06:00
|
|
|
MovePicker::MovePicker(const Position& p, Move ttm, Value th)
|
|
|
|
: pos(p), threshold(th) {
|
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
|
|
|
|
2014-02-15 14:17:58 -07:00
|
|
|
stage = PROBCUT;
|
2011-05-21 10:17:11 -06:00
|
|
|
|
2016-12-22 08:02:32 -07:00
|
|
|
// In ProbCut we generate captures with SEE higher than or equal to the given threshold
|
2015-07-19 03:25:14 -06:00
|
|
|
ttMove = ttm
|
|
|
|
&& pos.pseudo_legal(ttm)
|
|
|
|
&& pos.capture(ttm)
|
2016-12-22 08:02:32 -07:00
|
|
|
&& pos.see_ge(ttm, threshold)? ttm : MOVE_NONE;
|
2011-05-21 10:17:11 -06:00
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
stage += (ttMove == MOVE_NONE);
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2008-10-25 08:28:24 -06:00
|
|
|
|
2015-07-19 03:25:14 -06:00
|
|
|
/// score() assigns a numerical value to each move in a move list. The moves with
|
2014-03-23 01:52:42 -06:00
|
|
|
/// highest values will be picked first.
|
2013-02-03 01:52:39 -07:00
|
|
|
template<>
|
|
|
|
void MovePicker::score<CAPTURES>() {
|
2015-07-19 03:25:14 -06:00
|
|
|
// Winning and equal captures in the main search are ordered by MVV, preferring
|
2015-10-18 20:17:37 -06:00
|
|
|
// captures near our home rank. Surprisingly, this appears to perform slightly
|
2016-01-16 14:34:29 -07:00
|
|
|
// better than SEE-based move ordering: exchanging big pieces before capturing
|
2015-07-19 03:25:14 -06:00
|
|
|
// a hanging piece probably helps to reduce the subtree size.
|
2016-01-16 14:34:29 -07:00
|
|
|
// In the main search we want to push captures with negative SEE values to the
|
2013-12-02 11:04:09 -07:00
|
|
|
// badCaptures[] array, but instead of doing it now we delay until the move
|
2015-07-19 03:25:14 -06:00
|
|
|
// has been picked up, saving some SEE calls in case we get a cutoff.
|
2015-05-01 18:36:39 -06:00
|
|
|
for (auto& m : *this)
|
|
|
|
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
2015-06-24 21:15:09 -06:00
|
|
|
- Value(200 * relative_rank(pos.side_to_move(), to_sq(m)));
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2013-02-03 01:52:39 -07:00
|
|
|
template<>
|
|
|
|
void MovePicker::score<QUIETS>() {
|
2015-03-15 00:39:10 -06:00
|
|
|
|
2017-01-10 00:47:56 -07:00
|
|
|
const HistoryStats& history = pos.this_thread()->history;
|
2016-04-17 08:14:07 -06:00
|
|
|
|
2017-03-14 22:00:03 -06:00
|
|
|
const CounterMoveStats& cmh = *(ss-1)->counterMoves;
|
|
|
|
const CounterMoveStats& fmh = *(ss-2)->counterMoves;
|
|
|
|
const CounterMoveStats& fm2 = *(ss-4)->counterMoves;
|
2016-04-17 08:14:07 -06:00
|
|
|
|
2016-07-25 07:53:18 -06:00
|
|
|
Color c = pos.side_to_move();
|
|
|
|
|
2015-01-31 11:53:19 -07:00
|
|
|
for (auto& m : *this)
|
2017-03-14 22:00:03 -06:00
|
|
|
m.value = cmh[pos.moved_piece(m)][to_sq(m)]
|
|
|
|
+ fmh[pos.moved_piece(m)][to_sq(m)]
|
|
|
|
+ fm2[pos.moved_piece(m)][to_sq(m)]
|
2017-01-10 00:47:56 -07:00
|
|
|
+ history.get(c, m);
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2013-02-03 01:52:39 -07:00
|
|
|
template<>
|
|
|
|
void MovePicker::score<EVASIONS>() {
|
2017-01-09 03:57:34 -07:00
|
|
|
// Try captures ordered by MVV/LVA, then non-captures ordered by stats heuristics
|
2017-01-10 00:47:56 -07:00
|
|
|
const HistoryStats& history = pos.this_thread()->history;
|
2016-07-25 07:53:18 -06:00
|
|
|
Color c = pos.side_to_move();
|
2009-08-29 01:02:30 -06:00
|
|
|
|
2015-01-31 11:53:19 -07:00
|
|
|
for (auto& m : *this)
|
2016-10-05 16:00:27 -06:00
|
|
|
if (pos.capture(m))
|
2015-01-31 11:53:19 -07:00
|
|
|
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
2017-01-10 00:47:56 -07:00
|
|
|
- Value(type_of(pos.moved_piece(m))) + HistoryStats::Max;
|
2009-10-31 03:51:04 -06:00
|
|
|
else
|
2017-01-10 00:47:56 -07:00
|
|
|
m.value = history.get(c, m);
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-21 15:32:48 -07:00
|
|
|
|
2013-02-03 01:52:39 -07:00
|
|
|
/// next_move() is the most important method of the MovePicker class. It returns
|
2013-12-02 15:47:38 -07:00
|
|
|
/// a new pseudo legal move every time it is called, until there are no more moves
|
2014-03-23 01:52:42 -06:00
|
|
|
/// left. It picks the move with the biggest value from a list of generated moves
|
2014-01-26 15:09:22 -07:00
|
|
|
/// taking care not to return the ttMove if it has already been searched.
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
|
2017-03-18 16:41:55 -06:00
|
|
|
Move MovePicker::next_move(bool skipQuiets) {
|
2008-10-16 06:25:56 -06:00
|
|
|
|
2009-08-30 02:42:55 -06:00
|
|
|
Move move;
|
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
switch (stage) {
|
2010-02-05 10:17:52 -07:00
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
case MAIN_SEARCH: case EVASION: case QSEARCH_WITH_CHECKS:
|
2016-09-15 00:38:20 -06:00
|
|
|
case QSEARCH_NO_CHECKS: case PROBCUT:
|
2016-09-10 13:37:36 -06:00
|
|
|
++stage;
|
|
|
|
return ttMove;
|
2010-02-05 10:17:52 -07:00
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
case CAPTURES_INIT:
|
2016-09-10 13:37:36 -06:00
|
|
|
endBadCaptures = cur = moves;
|
|
|
|
endMoves = generate<CAPTURES>(pos, cur);
|
|
|
|
score<CAPTURES>();
|
|
|
|
++stage;
|
2011-04-16 04:24:30 -06:00
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
case GOOD_CAPTURES:
|
|
|
|
while (cur < endMoves)
|
|
|
|
{
|
2015-02-01 02:59:01 -07:00
|
|
|
move = pick_best(cur++, endMoves);
|
2011-05-25 14:36:16 -06:00
|
|
|
if (move != ttMove)
|
2011-04-16 04:24:30 -06:00
|
|
|
{
|
2016-10-06 11:55:10 -06:00
|
|
|
if (pos.see_ge(move, VALUE_ZERO))
|
2009-08-27 01:12:51 -06:00
|
|
|
return move;
|
2009-08-30 02:42:55 -06:00
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
// Losing capture, move it to the beginning of the array
|
|
|
|
*endBadCaptures++ = move;
|
2011-04-16 04:24:30 -06:00
|
|
|
}
|
2016-09-10 13:37:36 -06:00
|
|
|
}
|
2011-04-16 04:24:30 -06:00
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
++stage;
|
|
|
|
move = ss->killers[0]; // First killer move
|
2016-09-10 13:37:36 -06:00
|
|
|
if ( move != MOVE_NONE
|
|
|
|
&& move != ttMove
|
|
|
|
&& pos.pseudo_legal(move)
|
|
|
|
&& !pos.capture(move))
|
|
|
|
return move;
|
|
|
|
|
|
|
|
case KILLERS:
|
|
|
|
++stage;
|
|
|
|
move = ss->killers[1]; // Second killer move
|
|
|
|
if ( move != MOVE_NONE
|
|
|
|
&& move != ttMove
|
|
|
|
&& pos.pseudo_legal(move)
|
|
|
|
&& !pos.capture(move))
|
|
|
|
return move;
|
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
case COUNTERMOVE:
|
2016-09-10 13:37:36 -06:00
|
|
|
++stage;
|
|
|
|
move = countermove;
|
|
|
|
if ( move != MOVE_NONE
|
|
|
|
&& move != ttMove
|
|
|
|
&& move != ss->killers[0]
|
|
|
|
&& move != ss->killers[1]
|
|
|
|
&& pos.pseudo_legal(move)
|
|
|
|
&& !pos.capture(move))
|
|
|
|
return move;
|
|
|
|
|
|
|
|
case QUIET_INIT:
|
|
|
|
cur = endBadCaptures;
|
|
|
|
endMoves = generate<QUIETS>(pos, cur);
|
|
|
|
score<QUIETS>();
|
2017-04-20 12:15:48 -06:00
|
|
|
|
2017-04-23 09:37:55 -06:00
|
|
|
partial_insertion_sort(cur, endMoves, -4000 * depth / ONE_PLY);
|
2016-09-10 13:37:36 -06:00
|
|
|
++stage;
|
2011-04-16 04:24:30 -06:00
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
case QUIET:
|
2017-03-18 16:41:55 -06:00
|
|
|
while ( cur < endMoves
|
|
|
|
&& (!skipQuiets || cur->value >= VALUE_ZERO))
|
2016-09-10 13:37:36 -06:00
|
|
|
{
|
2015-02-01 02:59:01 -07:00
|
|
|
move = *cur++;
|
2017-03-18 16:41:55 -06:00
|
|
|
|
2011-05-25 14:36:16 -06:00
|
|
|
if ( move != ttMove
|
2016-09-10 13:37:36 -06:00
|
|
|
&& move != ss->killers[0]
|
|
|
|
&& move != ss->killers[1]
|
|
|
|
&& move != countermove)
|
2009-08-30 02:42:55 -06:00
|
|
|
return move;
|
2016-09-10 13:37:36 -06:00
|
|
|
}
|
|
|
|
++stage;
|
|
|
|
cur = moves; // Point to beginning of bad captures
|
2009-08-30 02:42:55 -06:00
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
case BAD_CAPTURES:
|
|
|
|
if (cur < endBadCaptures)
|
|
|
|
return *cur++;
|
|
|
|
break;
|
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
case EVASIONS_INIT:
|
2016-09-10 13:37:36 -06:00
|
|
|
cur = moves;
|
|
|
|
endMoves = generate<EVASIONS>(pos, cur);
|
2016-10-16 07:20:05 -06:00
|
|
|
score<EVASIONS>();
|
2016-09-10 13:37:36 -06:00
|
|
|
++stage;
|
2009-10-20 04:38:20 -06:00
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
case ALL_EVASIONS:
|
2016-09-10 13:37:36 -06:00
|
|
|
while (cur < endMoves)
|
|
|
|
{
|
2015-02-01 02:59:01 -07:00
|
|
|
move = pick_best(cur++, endMoves);
|
2011-05-25 14:36:16 -06:00
|
|
|
if (move != ttMove)
|
2011-04-16 04:24:30 -06:00
|
|
|
return move;
|
2016-09-10 13:37:36 -06:00
|
|
|
}
|
2016-09-15 00:38:20 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROBCUT_INIT:
|
2016-09-10 13:37:36 -06:00
|
|
|
cur = moves;
|
2016-09-15 00:38:20 -06:00
|
|
|
endMoves = generate<CAPTURES>(pos, cur);
|
|
|
|
score<CAPTURES>();
|
2016-09-10 13:37:36 -06:00
|
|
|
++stage;
|
2009-08-26 07:33:17 -06:00
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
case PROBCUT_CAPTURES:
|
2016-09-10 13:37:36 -06:00
|
|
|
while (cur < endMoves)
|
|
|
|
{
|
2016-09-15 00:38:20 -06:00
|
|
|
move = pick_best(cur++, endMoves);
|
|
|
|
if ( move != ttMove
|
2016-12-22 08:02:32 -07:00
|
|
|
&& pos.see_ge(move, threshold))
|
2016-09-10 13:37:36 -06:00
|
|
|
return move;
|
|
|
|
}
|
|
|
|
break;
|
2012-01-21 15:32:48 -07:00
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
case QCAPTURES_1_INIT: case QCAPTURES_2_INIT:
|
2016-09-10 13:37:36 -06:00
|
|
|
cur = moves;
|
|
|
|
endMoves = generate<CAPTURES>(pos, cur);
|
|
|
|
score<CAPTURES>();
|
|
|
|
++stage;
|
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
case QCAPTURES_1: case QCAPTURES_2:
|
2016-09-10 13:37:36 -06:00
|
|
|
while (cur < endMoves)
|
|
|
|
{
|
2015-02-01 02:59:01 -07:00
|
|
|
move = pick_best(cur++, endMoves);
|
2016-09-15 00:38:20 -06:00
|
|
|
if (move != ttMove)
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
if (stage == QCAPTURES_2)
|
|
|
|
break;
|
|
|
|
cur = moves;
|
|
|
|
endMoves = generate<QUIET_CHECKS>(pos, cur);
|
|
|
|
++stage;
|
|
|
|
|
|
|
|
case QCHECKS:
|
|
|
|
while (cur < endMoves)
|
|
|
|
{
|
|
|
|
move = cur++->move;
|
|
|
|
if (move != ttMove)
|
2011-06-12 00:25:51 -06:00
|
|
|
return move;
|
2016-09-10 13:37:36 -06:00
|
|
|
}
|
|
|
|
break;
|
2009-08-26 07:33:17 -06:00
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
case QSEARCH_RECAPTURES:
|
2016-09-10 13:37:36 -06:00
|
|
|
cur = moves;
|
|
|
|
endMoves = generate<CAPTURES>(pos, cur);
|
|
|
|
score<CAPTURES>();
|
|
|
|
++stage;
|
2011-04-16 04:24:30 -06:00
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
case QRECAPTURES:
|
2016-09-10 13:37:36 -06:00
|
|
|
while (cur < endMoves)
|
|
|
|
{
|
|
|
|
move = pick_best(cur++, endMoves);
|
2016-09-15 00:38:20 -06:00
|
|
|
if (to_sq(move) == recaptureSquare)
|
2016-09-10 13:37:36 -06:00
|
|
|
return move;
|
2008-10-25 08:28:24 -06:00
|
|
|
}
|
2016-09-10 13:37:36 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(false);
|
2009-08-27 01:12:51 -06:00
|
|
|
}
|
2016-09-10 13:37:36 -06:00
|
|
|
|
|
|
|
return MOVE_NONE;
|
2009-08-27 01:12:51 -06:00
|
|
|
}
|