mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-20 17:16:33 +08:00
Tidy up in movepick.cpp
Some formattng after recent changes. No functional change.
This commit is contained in:
@@ -67,27 +67,20 @@ namespace {
|
|||||||
/// search captures, promotions and some checks) and how important good move
|
/// search captures, promotions and some checks) and how important good move
|
||||||
/// ordering is at the current node.
|
/// ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h, const CounterMovesHistoryStats& cmh,
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
|
||||||
Move cm, Search::Stack* s) : pos(p), history(h), counterMovesHistory(cmh), depth(d) {
|
const CounterMovesHistoryStats& cmh, Move cm, Search::Stack* s)
|
||||||
|
: pos(p), history(h), counterMovesHistory(cmh), ss(s), countermove(cm), depth(d) {
|
||||||
|
|
||||||
assert(d > DEPTH_ZERO);
|
assert(d > DEPTH_ZERO);
|
||||||
|
|
||||||
endBadCaptures = moves + MAX_MOVES - 1;
|
stage = pos.checkers() ? EVASION : MAIN_SEARCH;
|
||||||
countermove = cm;
|
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||||
ss = s;
|
|
||||||
|
|
||||||
if (pos.checkers())
|
|
||||||
stage = EVASION;
|
|
||||||
|
|
||||||
else
|
|
||||||
stage = MAIN_SEARCH;
|
|
||||||
|
|
||||||
ttMove = (ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE);
|
|
||||||
endMoves += (ttMove != MOVE_NONE);
|
endMoves += (ttMove != MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h, const CounterMovesHistoryStats& cmh,
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
|
||||||
Square s) : pos(p), history(h), counterMovesHistory(cmh) {
|
const CounterMovesHistoryStats& cmh, Square s)
|
||||||
|
: pos(p), history(h), counterMovesHistory(cmh) {
|
||||||
|
|
||||||
assert(d <= DEPTH_ZERO);
|
assert(d <= DEPTH_ZERO);
|
||||||
|
|
||||||
@@ -107,46 +100,39 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats&
|
|||||||
ttm = MOVE_NONE;
|
ttm = MOVE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ttMove = (ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE);
|
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
|
||||||
endMoves += (ttMove != MOVE_NONE);
|
endMoves += (ttMove != MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, const CounterMovesHistoryStats& cmh, PieceType pt)
|
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h,
|
||||||
: pos(p), history(h), counterMovesHistory(cmh) {
|
const CounterMovesHistoryStats& cmh, Value th)
|
||||||
|
: pos(p), history(h), counterMovesHistory(cmh), threshold(th) {
|
||||||
|
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
stage = PROBCUT;
|
stage = PROBCUT;
|
||||||
|
|
||||||
// In ProbCut we generate only captures that are better than the parent's
|
// In ProbCut we generate captures with SEE higher than the given threshold
|
||||||
// captured piece.
|
ttMove = ttm
|
||||||
captureThreshold = PieceValue[MG][pt];
|
&& pos.pseudo_legal(ttm)
|
||||||
ttMove = (ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE);
|
&& pos.capture(ttm)
|
||||||
|
&& pos.see(ttm) > threshold ? ttm : MOVE_NONE;
|
||||||
if (ttMove && (!pos.capture(ttMove) || pos.see(ttMove) <= captureThreshold))
|
|
||||||
ttMove = MOVE_NONE;
|
|
||||||
|
|
||||||
endMoves += (ttMove != MOVE_NONE);
|
endMoves += (ttMove != MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// score() assign a numerical value to each move in a move list. The moves with
|
/// score() assigns a numerical value to each move in a move list. The moves with
|
||||||
/// highest values will be picked first.
|
/// highest values will be picked first.
|
||||||
template<>
|
template<>
|
||||||
void MovePicker::score<CAPTURES>() {
|
void MovePicker::score<CAPTURES>() {
|
||||||
// Winning and equal captures in the main search are ordered by MVV.
|
// Winning and equal captures in the main search are ordered by MVV, preferring
|
||||||
// Suprisingly, this appears to perform slightly better than SEE based
|
// captures near our home rank. Suprisingly, this appears to perform slightly
|
||||||
// move ordering. The reason is probably that in a position with a winning
|
// better than SEE based move ordering: exchanging big pieces before capturing
|
||||||
// capture, capturing a valuable (but sufficiently defended) piece
|
// a hanging piece probably helps to reduce the subtree size.
|
||||||
// first usually doesn't hurt. The opponent will have to recapture, and
|
|
||||||
// the hanging piece will still be hanging (except in the unusual cases
|
|
||||||
// where it is possible to recapture with the hanging piece). Exchanging
|
|
||||||
// big pieces before capturing a hanging piece probably helps to reduce
|
|
||||||
// the subtree size.
|
|
||||||
// In main search we want to push captures with negative SEE values to the
|
// In main search we want to push captures with negative SEE values to the
|
||||||
// badCaptures[] array, but instead of doing it now we delay until the move
|
// badCaptures[] array, but instead of doing it now we delay until the move
|
||||||
// has been picked up in pick_move_from_list(). This way we save some SEE
|
// has been picked up, saving some SEE calls in case we get a cutoff.
|
||||||
// calls in case we get a cutoff.
|
|
||||||
for (auto& m : *this)
|
for (auto& m : *this)
|
||||||
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
||||||
- Value(200 * relative_rank(pos.side_to_move(), to_sq(m)));
|
- Value(200 * relative_rank(pos.side_to_move(), to_sq(m)));
|
||||||
@@ -165,9 +151,9 @@ void MovePicker::score<QUIETS>() {
|
|||||||
|
|
||||||
template<>
|
template<>
|
||||||
void MovePicker::score<EVASIONS>() {
|
void MovePicker::score<EVASIONS>() {
|
||||||
// Try good captures ordered by MVV/LVA, then non-captures if destination square
|
// Try winning and equal captures captures ordered by MVV/LVA, then non-captures
|
||||||
// is not under attack, ordered by history value, then bad-captures and quiet
|
// ordered by history value, then bad-captures and quiet moves with a negative
|
||||||
// moves with a negative SEE. This last group is ordered by the SEE value.
|
// SEE ordered by SEE value.
|
||||||
Value see;
|
Value see;
|
||||||
|
|
||||||
for (auto& m : *this)
|
for (auto& m : *this)
|
||||||
@@ -187,6 +173,8 @@ void MovePicker::score<EVASIONS>() {
|
|||||||
|
|
||||||
void MovePicker::generate_next_stage() {
|
void MovePicker::generate_next_stage() {
|
||||||
|
|
||||||
|
assert(stage != STOP);
|
||||||
|
|
||||||
cur = moves;
|
cur = moves;
|
||||||
|
|
||||||
switch (++stage) {
|
switch (++stage) {
|
||||||
@@ -198,17 +186,11 @@ void MovePicker::generate_next_stage() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case KILLERS:
|
case KILLERS:
|
||||||
cur = killers;
|
|
||||||
endMoves = cur + 2;
|
|
||||||
|
|
||||||
killers[0] = ss->killers[0];
|
killers[0] = ss->killers[0];
|
||||||
killers[1] = ss->killers[1];
|
killers[1] = ss->killers[1];
|
||||||
killers[2].move = MOVE_NONE;
|
killers[2] = countermove;
|
||||||
|
cur = killers;
|
||||||
// Be sure countermoves are different from killers
|
endMoves = cur + 2 + (countermove != killers[0] && countermove != killers[1]);
|
||||||
if ( countermove != killers[0]
|
|
||||||
&& countermove != killers[1])
|
|
||||||
*endMoves++ = countermove;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GOOD_QUIETS:
|
case GOOD_QUIETS:
|
||||||
@@ -226,7 +208,7 @@ void MovePicker::generate_next_stage() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case BAD_CAPTURES:
|
case BAD_CAPTURES:
|
||||||
// Just pick them in reverse order to get MVV/LVA ordering
|
// Just pick them in reverse order to get correct ordering
|
||||||
cur = moves + MAX_MOVES - 1;
|
cur = moves + MAX_MOVES - 1;
|
||||||
endMoves = endBadCaptures;
|
endMoves = endBadCaptures;
|
||||||
break;
|
break;
|
||||||
@@ -242,12 +224,8 @@ void MovePicker::generate_next_stage() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case EVASION: case QSEARCH_WITH_CHECKS: case QSEARCH_WITHOUT_CHECKS:
|
case EVASION: case QSEARCH_WITH_CHECKS: case QSEARCH_WITHOUT_CHECKS:
|
||||||
case PROBCUT: case RECAPTURE:
|
case PROBCUT: case RECAPTURE: case STOP:
|
||||||
stage = STOP;
|
stage = STOP;
|
||||||
/* Fall through */
|
|
||||||
|
|
||||||
case STOP:
|
|
||||||
endMoves = cur + 1; // Avoid another generate_next_stage() call
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -267,7 +245,7 @@ Move MovePicker::next_move<false>() {
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
while (cur == endMoves)
|
while (cur == endMoves && stage != STOP)
|
||||||
generate_next_stage();
|
generate_next_stage();
|
||||||
|
|
||||||
switch (stage) {
|
switch (stage) {
|
||||||
@@ -318,7 +296,7 @@ Move MovePicker::next_move<false>() {
|
|||||||
|
|
||||||
case PROBCUT_CAPTURES:
|
case PROBCUT_CAPTURES:
|
||||||
move = pick_best(cur++, endMoves);
|
move = pick_best(cur++, endMoves);
|
||||||
if (move != ttMove && pos.see(move) > captureThreshold)
|
if (move != ttMove && pos.see(move) > threshold)
|
||||||
return move;
|
return move;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public:
|
|||||||
MovePicker& operator=(const MovePicker&) = delete;
|
MovePicker& operator=(const MovePicker&) = delete;
|
||||||
|
|
||||||
MovePicker(const Position&, Move, Depth, const HistoryStats&, const CounterMovesHistoryStats&, Square);
|
MovePicker(const Position&, Move, Depth, const HistoryStats&, const CounterMovesHistoryStats&, Square);
|
||||||
MovePicker(const Position&, Move, const HistoryStats&, const CounterMovesHistoryStats&, PieceType);
|
MovePicker(const Position&, Move, const HistoryStats&, const CounterMovesHistoryStats&, Value);
|
||||||
MovePicker(const Position&, Move, Depth, const HistoryStats&, const CounterMovesHistoryStats&, Move, Search::Stack*);
|
MovePicker(const Position&, Move, Depth, const HistoryStats&, const CounterMovesHistoryStats&, Move, Search::Stack*);
|
||||||
|
|
||||||
template<bool SpNode> Move next_move();
|
template<bool SpNode> Move next_move();
|
||||||
@@ -99,9 +99,9 @@ private:
|
|||||||
Move ttMove;
|
Move ttMove;
|
||||||
ExtMove killers[3];
|
ExtMove killers[3];
|
||||||
Square recaptureSquare;
|
Square recaptureSquare;
|
||||||
Value captureThreshold;
|
Value threshold;
|
||||||
int stage;
|
int stage;
|
||||||
ExtMove *endQuiets, *endBadCaptures;
|
ExtMove *endQuiets, *endBadCaptures = moves + MAX_MOVES - 1;
|
||||||
ExtMove moves[MAX_MOVES], *cur = moves, *endMoves = moves;
|
ExtMove moves[MAX_MOVES], *cur = moves, *endMoves = moves;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -749,7 +749,7 @@ namespace {
|
|||||||
assert((ss-1)->currentMove != MOVE_NONE);
|
assert((ss-1)->currentMove != MOVE_NONE);
|
||||||
assert((ss-1)->currentMove != MOVE_NULL);
|
assert((ss-1)->currentMove != MOVE_NULL);
|
||||||
|
|
||||||
MovePicker mp(pos, ttMove, History, CounterMovesHistory, pos.captured_piece_type());
|
MovePicker mp(pos, ttMove, History, CounterMovesHistory, PieceValue[MG][pos.captured_piece_type()]);
|
||||||
CheckInfo ci(pos);
|
CheckInfo ci(pos);
|
||||||
|
|
||||||
while ((move = mp.next_move<false>()) != MOVE_NONE)
|
while ((move = mp.next_move<false>()) != MOVE_NONE)
|
||||||
|
|||||||
Reference in New Issue
Block a user