Avoid constructing, passing as a parameter and binding a useless empty tuple of pointers in the qsearch move picker constructor.
Also reformat the scoring function in movepicker.cpp and do some cleaning in evaluate.cpp while there.
No functional change.
+const Bitboard AllSquares = ~Bitboard(0);
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
const Bitboard FileABB = 0x0101010101010101ULL;
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
const Bitboard FileABB = 0x0101010101010101ULL;
const Score Hanging = S( 48, 27);
const Score ThreatByPawnPush = S( 38, 22);
const Score HinderPassedPawn = S( 7, 0);
const Score Hanging = S( 48, 27);
const Score ThreatByPawnPush = S( 38, 22);
const Score HinderPassedPawn = S( 7, 0);
-
- // Penalty for a bishop on a1/h1 (a8/h8 for black) which is trapped by
- // a friendly pawn on b2/g2 (b7/g7 for black). This can obviously only
- // happen in Chess960 games.
- const Score TrappedBishopA1H1 = S(50, 50);
+ const Score TrappedBishopA1H1 = S( 50, 50);
const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square Up = (Us == WHITE ? NORTH : SOUTH);
const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square Up = (Us == WHITE ? NORTH : SOUTH);
- const Bitboard Camp = (Us == WHITE ? ~Bitboard(0) ^ Rank6BB ^ Rank7BB ^ Rank8BB
- : ~Bitboard(0) ^ Rank1BB ^ Rank2BB ^ Rank3BB);
+ const Bitboard Camp = (Us == WHITE ? AllSquares ^ Rank6BB ^ Rank7BB ^ Rank8BB
+ : AllSquares ^ Rank1BB ^ Rank2BB ^ Rank3BB);
const Square ksq = pos.square<KING>(Us);
const Square ksq = pos.square<KING>(Us);
- Bitboard kingOnlyDefended, b, b1, b2, safe, other;
+ Bitboard kingOnlyDefended, undefended, b, b1, b2, safe, other;
int kingDanger;
// King shelter and enemy pawns storm
int kingDanger;
// King shelter and enemy pawns storm
& ~attackedBy2[Us];
// ... and those which are not defended at all in the larger king ring
& ~attackedBy2[Us];
// ... and those which are not defended at all in the larger king ring
- b = attackedBy[Them][ALL_PIECES] & ~attackedBy[Us][ALL_PIECES]
- & kingRing[Us] & ~pos.pieces(Them);
+ undefended = attackedBy[Them][ALL_PIECES]
+ & ~attackedBy[Us][ALL_PIECES]
+ & kingRing[Us]
+ & ~pos.pieces(Them);
// Initialize the 'kingDanger' variable, which will be transformed
// later into a king danger score. The initial value is based on the
// Initialize the 'kingDanger' variable, which will be transformed
// later into a king danger score. The initial value is based on the
kingDanger = kingAttackersCount[Them] * kingAttackersWeight[Them]
+ 102 * kingAdjacentZoneAttacksCount[Them]
+ 201 * popcount(kingOnlyDefended)
kingDanger = kingAttackersCount[Them] * kingAttackersWeight[Them]
+ 102 * kingAdjacentZoneAttacksCount[Them]
+ 201 * popcount(kingOnlyDefended)
- + 143 * (popcount(b) + !!pos.pinned_pieces(Us))
+ + 143 * (popcount(undefended) + !!pos.pinned_pieces(Us))
- 848 * !pos.count<QUEEN>(Them)
- 9 * mg_value(score) / 8
+ 40;
- 848 * !pos.count<QUEEN>(Them)
- 9 * mg_value(score) / 8
+ 40;
/// search captures, promotions, and some checks) and how important good move
/// ordering is at the current node.
/// search captures, promotions, and some checks) and how important good move
/// ordering is at the current node.
+/// MovePicker constructor for the main search
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
const PieceToHistory** ch, Move cm, Move* killers_p)
: pos(p), mainHistory(mh), contHistory(ch), countermove(cm),
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
const PieceToHistory** ch, Move cm, Move* killers_p)
: pos(p), mainHistory(mh), contHistory(ch), countermove(cm),
stage += (ttMove == MOVE_NONE);
}
stage += (ttMove == MOVE_NONE);
}
-MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
- const PieceToHistory** ch, Square s)
- : pos(p), mainHistory(mh), contHistory(ch) {
+/// MovePicker constructor for quiescence search
+MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, Square s)
+ : pos(p), mainHistory(mh) {
stage += (ttMove == MOVE_NONE);
}
stage += (ttMove == MOVE_NONE);
}
+/// MovePicker constructor for ProbCut: we generate captures with SEE higher
+/// than or equal to the given threshold.
MovePicker::MovePicker(const Position& p, Move ttm, Value th)
: pos(p), threshold(th) {
assert(!pos.checkers());
stage = PROBCUT;
MovePicker::MovePicker(const Position& p, Move ttm, Value th)
: pos(p), threshold(th) {
assert(!pos.checkers());
stage = PROBCUT;
-
- // In ProbCut we generate captures with SEE higher than or equal to the given threshold
ttMove = ttm
&& pos.pseudo_legal(ttm)
&& pos.capture(ttm)
ttMove = ttm
&& pos.pseudo_legal(ttm)
&& pos.capture(ttm)
/// score() assigns a numerical value to each move in a list, used for sorting.
/// Captures are ordered by Most Valuable Victim (MVV), preferring captures
/// near our home rank. Quiets are ordered using the histories.
/// score() assigns a numerical value to each move in a list, used for sorting.
/// Captures are ordered by Most Valuable Victim (MVV), preferring captures
/// near our home rank. Quiets are ordered using the histories.
void MovePicker::score() {
void MovePicker::score() {
+ static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");
+
- if (T == CAPTURES || (T == EVASIONS && pos.capture(m)))
- m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
- - (T == EVASIONS ? Value(type_of(pos.moved_piece(m)))
- : Value(200 * relative_rank(pos.side_to_move(), to_sq(m))));
- else if (T == QUIETS)
+ if (Type == CAPTURES)
+ m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
+ - Value(200 * relative_rank(pos.side_to_move(), to_sq(m)));
+
+ else if (Type == QUIETS)
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
+ (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
+ (*contHistory[1])[pos.moved_piece(m)][to_sq(m)]
+ (*contHistory[3])[pos.moved_piece(m)][to_sq(m)];
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
+ (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
+ (*contHistory[1])[pos.moved_piece(m)][to_sq(m)]
+ (*contHistory[3])[pos.moved_piece(m)][to_sq(m)];
- else // Quiet evasions
- m.value = (*mainHistory)[pos.side_to_move()][from_to(m)] - (1 << 28);
+ else // Type == EVASIONS
+ {
+ if (pos.capture(m))
+ m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
+ - Value(type_of(pos.moved_piece(m)));
+ else
+ m.value = (*mainHistory)[pos.side_to_move()][from_to(m)] - (1 << 28);
+ }
}
/// next_move() is the most important method of the MovePicker class. It returns
}
/// next_move() is the most important method of the MovePicker class. It returns
MovePicker(const MovePicker&) = delete;
MovePicker& operator=(const MovePicker&) = delete;
MovePicker(const Position&, Move, Value);
MovePicker(const MovePicker&) = delete;
MovePicker& operator=(const MovePicker&) = delete;
MovePicker(const Position&, Move, Value);
- MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const PieceToHistory**, Square);
+ MovePicker(const Position&, Move, Depth, const ButterflyHistory*, Square);
MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const PieceToHistory**, Move, Move*);
Move next_move(bool skipQuiets = false);
MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const PieceToHistory**, Move, Move*);
Move next_move(bool skipQuiets = false);
// to search the moves. Because the depth is <= 0 here, only captures,
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
// be generated.
// to search the moves. Because the depth is <= 0 here, only captures,
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
// be generated.
- const PieceToHistory* contHist[4] = {};
- MovePicker mp(pos, ttMove, depth, &pos.this_thread()->mainHistory, contHist, to_sq((ss-1)->currentMove));
+ MovePicker mp(pos, ttMove, depth, &pos.this_thread()->mainHistory, to_sq((ss-1)->currentMove));
// Loop through the moves until no moves remain or a beta cutoff occurs
while ((move = mp.next_move()) != MOVE_NONE)
// Loop through the moves until no moves remain or a beta cutoff occurs
while ((move = mp.next_move()) != MOVE_NONE)