mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Avoid constructing an empty tuple in qsearch
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.
This commit is contained in:
parent
5ea327d924
commit
002bf4d8db
5 changed files with 34 additions and 27 deletions
|
@ -39,6 +39,7 @@ const std::string pretty(Bitboard b);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Bitboard AllSquares = ~Bitboard(0);
|
||||||
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
||||||
|
|
||||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
const Bitboard FileABB = 0x0101010101010101ULL;
|
||||||
|
|
|
@ -216,10 +216,6 @@ namespace {
|
||||||
const Score Hanging = S( 48, 27);
|
const Score Hanging = S( 48, 27);
|
||||||
const Score ThreatByPawnPush = S( 38, 22);
|
const Score ThreatByPawnPush = S( 38, 22);
|
||||||
const Score HinderPassedPawn = S( 7, 0);
|
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);
|
||||||
|
|
||||||
#undef S
|
#undef S
|
||||||
|
@ -412,11 +408,11 @@ namespace {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Square Up = (Us == WHITE ? NORTH : SOUTH);
|
const Square Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
const Bitboard Camp = (Us == WHITE ? ~Bitboard(0) ^ Rank6BB ^ Rank7BB ^ Rank8BB
|
const Bitboard Camp = (Us == WHITE ? AllSquares ^ Rank6BB ^ Rank7BB ^ Rank8BB
|
||||||
: ~Bitboard(0) ^ Rank1BB ^ Rank2BB ^ Rank3BB);
|
: 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;
|
int kingDanger;
|
||||||
|
|
||||||
// King shelter and enemy pawns storm
|
// King shelter and enemy pawns storm
|
||||||
|
@ -431,8 +427,10 @@ namespace {
|
||||||
& ~attackedBy2[Us];
|
& ~attackedBy2[Us];
|
||||||
|
|
||||||
// ... and those which are not defended at all in the larger king ring
|
// ... and those which are not defended at all in the larger king ring
|
||||||
b = attackedBy[Them][ALL_PIECES] & ~attackedBy[Us][ALL_PIECES]
|
undefended = attackedBy[Them][ALL_PIECES]
|
||||||
& kingRing[Us] & ~pos.pieces(Them);
|
& ~attackedBy[Us][ALL_PIECES]
|
||||||
|
& kingRing[Us]
|
||||||
|
& ~pos.pieces(Them);
|
||||||
|
|
||||||
// Initialize the 'kingDanger' variable, which will be transformed
|
// Initialize the 'kingDanger' variable, which will be transformed
|
||||||
// later into a king danger score. The initial value is based on the
|
// later into a king danger score. The initial value is based on the
|
||||||
|
@ -442,7 +440,7 @@ namespace {
|
||||||
kingDanger = kingAttackersCount[Them] * kingAttackersWeight[Them]
|
kingDanger = kingAttackersCount[Them] * kingAttackersWeight[Them]
|
||||||
+ 102 * kingAdjacentZoneAttacksCount[Them]
|
+ 102 * kingAdjacentZoneAttacksCount[Them]
|
||||||
+ 201 * popcount(kingOnlyDefended)
|
+ 201 * popcount(kingOnlyDefended)
|
||||||
+ 143 * (popcount(b) + !!pos.pinned_pieces(Us))
|
+ 143 * (popcount(undefended) + !!pos.pinned_pieces(Us))
|
||||||
- 848 * !pos.count<QUEEN>(Them)
|
- 848 * !pos.count<QUEEN>(Them)
|
||||||
- 9 * mg_value(score) / 8
|
- 9 * mg_value(score) / 8
|
||||||
+ 40;
|
+ 40;
|
||||||
|
|
|
@ -66,6 +66,7 @@ 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 constructor for the main search
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
||||||
const PieceToHistory** ch, Move cm, Move* killers_p)
|
const PieceToHistory** ch, Move cm, Move* killers_p)
|
||||||
: pos(p), mainHistory(mh), contHistory(ch), countermove(cm),
|
: pos(p), mainHistory(mh), contHistory(ch), countermove(cm),
|
||||||
|
@ -78,9 +79,9 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist
|
||||||
stage += (ttMove == MOVE_NONE);
|
stage += (ttMove == MOVE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
/// MovePicker constructor for quiescence search
|
||||||
const PieceToHistory** ch, Square s)
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, Square s)
|
||||||
: pos(p), mainHistory(mh), contHistory(ch) {
|
: pos(p), mainHistory(mh) {
|
||||||
|
|
||||||
assert(d <= DEPTH_ZERO);
|
assert(d <= DEPTH_ZERO);
|
||||||
|
|
||||||
|
@ -104,14 +105,14 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist
|
||||||
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)
|
MovePicker::MovePicker(const Position& p, Move ttm, Value th)
|
||||||
: pos(p), threshold(th) {
|
: pos(p), threshold(th) {
|
||||||
|
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
stage = PROBCUT;
|
stage = PROBCUT;
|
||||||
|
|
||||||
// In ProbCut we generate captures with SEE higher than or equal to the given threshold
|
|
||||||
ttMove = ttm
|
ttMove = ttm
|
||||||
&& pos.pseudo_legal(ttm)
|
&& pos.pseudo_legal(ttm)
|
||||||
&& pos.capture(ttm)
|
&& pos.capture(ttm)
|
||||||
|
@ -123,23 +124,31 @@ MovePicker::MovePicker(const Position& p, Move ttm, Value th)
|
||||||
/// score() assigns a numerical value to each move in a list, used for sorting.
|
/// score() assigns a numerical value to each move in a list, used for sorting.
|
||||||
/// Captures are ordered by Most Valuable Victim (MVV), preferring captures
|
/// Captures are ordered by Most Valuable Victim (MVV), preferring captures
|
||||||
/// near our home rank. Quiets are ordered using the histories.
|
/// near our home rank. Quiets are ordered using the histories.
|
||||||
template<GenType T>
|
template<GenType Type>
|
||||||
void MovePicker::score() {
|
void MovePicker::score() {
|
||||||
|
|
||||||
|
static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");
|
||||||
|
|
||||||
for (auto& m : *this)
|
for (auto& m : *this)
|
||||||
if (T == CAPTURES || (T == EVASIONS && pos.capture(m)))
|
if (Type == CAPTURES)
|
||||||
m.value = PieceValue[MG][pos.piece_on(to_sq(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)));
|
||||||
: Value(200 * relative_rank(pos.side_to_move(), to_sq(m))));
|
|
||||||
else if (T == QUIETS)
|
else if (Type == QUIETS)
|
||||||
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
||||||
+ (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
+ (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
||||||
+ (*contHistory[1])[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)];
|
+ (*contHistory[3])[pos.moved_piece(m)][to_sq(m)];
|
||||||
|
|
||||||
else // Quiet evasions
|
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);
|
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
|
||||||
/// a new pseudo legal move every time it is called, until there are no more moves
|
/// a new pseudo legal move every time it is called, until there are no more moves
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
MovePicker(const MovePicker&) = delete;
|
MovePicker(const MovePicker&) = delete;
|
||||||
MovePicker& operator=(const MovePicker&) = delete;
|
MovePicker& operator=(const MovePicker&) = delete;
|
||||||
MovePicker(const Position&, Move, Value);
|
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*);
|
MovePicker(const Position&, Move, Depth, const ButterflyHistory*, const PieceToHistory**, Move, Move*);
|
||||||
Move next_move(bool skipQuiets = false);
|
Move next_move(bool skipQuiets = false);
|
||||||
|
|
||||||
|
|
|
@ -1246,8 +1246,7 @@ moves_loop: // When in check search starts from here
|
||||||
// to search the moves. Because the depth is <= 0 here, only captures,
|
// to search the moves. Because the depth is <= 0 here, only captures,
|
||||||
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
|
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
|
||||||
// be generated.
|
// be generated.
|
||||||
const PieceToHistory* contHist[4] = {};
|
MovePicker mp(pos, ttMove, depth, &pos.this_thread()->mainHistory, to_sq((ss-1)->currentMove));
|
||||||
MovePicker mp(pos, ttMove, depth, &pos.this_thread()->mainHistory, contHist, to_sq((ss-1)->currentMove));
|
|
||||||
|
|
||||||
// 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 ((move = mp.next_move()) != MOVE_NONE)
|
while ((move = mp.next_move()) != MOVE_NONE)
|
||||||
|
|
Loading…
Add table
Reference in a new issue