1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Sync with master

bench: 7031649
This commit is contained in:
Marco Costalba 2016-05-29 15:39:47 +02:00
commit 15dce36035
5 changed files with 46 additions and 37 deletions

View file

@ -187,6 +187,7 @@ namespace {
const Score OtherCheck = S(10, 10);
const Score ThreatByHangingPawn = S(71, 61);
const Score LooseEnemies = S( 0, 25);
const Score WeakQueen = S(35, 0);
const Score Hanging = S(48, 27);
const Score ThreatByPawnPush = S(38, 22);
const Score Unstoppable = S( 0, 20);
@ -488,6 +489,13 @@ namespace {
& ~(ei.attackedBy[Us][ALL_PIECES] | ei.attackedBy[Them][ALL_PIECES]))
score += LooseEnemies;
// Bonus for pin or discovered attack on the opponent queen
if ( pos.count<QUEEN>(Them) == 1
&& pos.slider_blockers(pos.pieces(),
pos.pieces(Us, ROOK, BISHOP),
pos.square<QUEEN>(Them)))
score += WeakQueen;
// Non-pawn enemies attacked by a pawn
weak = (pos.pieces(Them) ^ pos.pieces(Them, PAWN)) & ei.attackedBy[Us][PAWN];

View file

@ -124,7 +124,7 @@ namespace {
opposed = theirPawns & forward_bb(Us, s);
stoppers = theirPawns & passed_pawn_mask(Us, s);
lever = theirPawns & pawnAttacksBB[s];
doubled = ourPawns & forward_bb(Us, s);
doubled = ourPawns & (s + Up);
neighbours = ourPawns & adjacent_files_bb(f);
phalanx = neighbours & rank_bb(s);
supported = neighbours & rank_bb(s - Up);
@ -150,7 +150,7 @@ namespace {
// Passed pawns will be properly scored in evaluation because we need
// full attack info to evaluate them. Only the frontmost passed
// pawn on each file is considered a true passed pawn.
if (!(stoppers | doubled))
if (!(stoppers | doubled)) // FIXME this is just doubled by adjacent pawn
e->passedPawns[Us] |= s;
// Score this pawn
@ -167,7 +167,7 @@ namespace {
score += Connected[opposed][!!phalanx][more_than_one(supported)][relative_rank(Us, s)];
if (doubled)
score -= Doubled / distance<Rank>(s, frontmost_sq(Us, doubled));
score -= Doubled;
if (lever)
score += Lever[relative_rank(Us, s)];

View file

@ -454,28 +454,27 @@ Phase Position::game_phase() const {
}
/// Position::check_blockers() returns a bitboard of all the pieces with color
/// 'c' that are blocking check on the king with color 'kingColor'. A piece
/// blocks a check if removing that piece from the board would result in a
/// position where the king is in check. A check blocking piece can be either a
/// pinned or a discovered check piece, according if its color 'c' is the same
/// or the opposite of 'kingColor'.
/// Position::slider_blockers() returns a bitboard of all the pieces in 'target' that
/// are blocking attacks on the square 's' from 'sliders'. A piece blocks a slider
/// if removing that piece from the board would result in a position where square 's'
/// is attacked. For example, a king-attack blocking piece can be either a pinned or
/// a discovered check piece, according if its color is the opposite or the same of
/// the color of the slider.
Bitboard Position::check_blockers(Color c, Color kingColor) const {
Bitboard Position::slider_blockers(Bitboard target, Bitboard sliders, Square s) const {
Bitboard b, pinners, result = 0;
Square ksq = square<KING>(kingColor);
// Pinners are sliders that give check when a pinned piece is removed
pinners = ( (pieces( ROOK, QUEEN) & PseudoAttacks[ROOK ][ksq])
| (pieces(BISHOP, QUEEN) & PseudoAttacks[BISHOP][ksq])) & pieces(~kingColor);
// Pinners are sliders that attack 's' when a pinned piece is removed
pinners = ( (PseudoAttacks[ROOK ][s] & pieces(QUEEN, ROOK))
| (PseudoAttacks[BISHOP][s] & pieces(QUEEN, BISHOP))) & sliders;
while (pinners)
{
b = between_bb(ksq, pop_lsb(&pinners)) & pieces();
b = between_bb(s, pop_lsb(&pinners)) & pieces();
if (!more_than_one(b))
result |= b & pieces(c);
result |= b & target;
}
return result;
}

View file

@ -132,6 +132,7 @@ public:
Bitboard attacks_from(Piece pc, Square s) const;
template<PieceType> Bitboard attacks_from(Square s) const;
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
Bitboard slider_blockers(Bitboard target, Bitboard sliders, Square s) const;
// Properties of moves
bool legal(Move m, Bitboard pinned) const;
@ -187,7 +188,6 @@ private:
void set_state(StateInfo* si) const;
// Other helpers
Bitboard check_blockers(Color c, Color kingColor) const;
void put_piece(Color c, PieceType pt, Square s);
void remove_piece(Color c, PieceType pt, Square s);
void move_piece(Color c, PieceType pt, Square from, Square to);
@ -312,11 +312,11 @@ inline Bitboard Position::checkers() const {
}
inline Bitboard Position::discovered_check_candidates() const {
return check_blockers(sideToMove, ~sideToMove);
return slider_blockers(pieces(sideToMove), pieces(sideToMove), square<KING>(~sideToMove));
}
inline Bitboard Position::pinned_pieces(Color c) const {
return check_blockers(c, c);
return slider_blockers(pieces(c), pieces(~c), square<KING>(c));
}
inline bool Position::pawn_passed(Color c, Square s) const {

View file

@ -541,18 +541,18 @@ void Thread::search() {
// Stop the search if only one legal move is available, or if all
// of the available time has been used, or if we matched an easyMove
// from the previous search and just did a fast verification.
const bool F[] = { !mainThread->failedLow,
bestValue >= mainThread->previousScore };
const int F[] = { mainThread->failedLow,
bestValue - mainThread->previousScore };
int improvingFactor = 640 - 160*F[0] - 126*F[1] - 124*F[0]*F[1];
int improvingFactor = std::max(229, std::min(715, 357 + 119 * F[0] - 6 * F[1]));
double unstablePvFactor = 1 + mainThread->bestMoveChanges;
bool doEasyMove = rootMoves[0].pv[0] == easyMove
&& mainThread->bestMoveChanges < 0.03
&& Time.elapsed() > Time.optimum() * 25 / 204;
&& Time.elapsed() > Time.optimum() * 5 / 42;
if ( rootMoves.size() == 1
|| Time.elapsed() > Time.optimum() * unstablePvFactor * improvingFactor / 634
|| Time.elapsed() > Time.optimum() * unstablePvFactor * improvingFactor / 628
|| (mainThread->easyMovePlayed = doEasyMove))
{
// If we are allowed to ponder do not stop the search now but
@ -609,6 +609,7 @@ namespace {
Value bestValue, value, ttValue, eval, nullValue, futilityValue;
bool ttHit, inCheck, givesCheck, singularExtensionNode, improving;
bool captureOrPromotion, doFullDepthSearch;
Piece moved_piece;
int moveCount, quietCount;
// Step 1. Initialize node
@ -865,7 +866,9 @@ namespace {
moves_loop: // When in check search starts from here
Square prevSq = to_sq((ss-1)->currentMove);
const CounterMoveStats& cmh = CounterMoveHistory[pos.piece_on(prevSq)][prevSq];
const CounterMoveStats* cmh = (ss-1)->counterMoves;
const CounterMoveStats* fmh = (ss-2)->counterMoves;
const CounterMoveStats* fmh2 = (ss-4)->counterMoves;
MovePicker mp(pos, ttMove, depth, ss);
CheckInfo ci(pos);
@ -911,6 +914,7 @@ moves_loop: // When in check search starts from here
extension = DEPTH_ZERO;
captureOrPromotion = pos.capture_or_promotion(move);
moved_piece = pos.moved_piece(move);
givesCheck = type_of(move) == NORMAL && !ci.dcCandidates
? ci.checkSquares[type_of(pos.piece_on(from_sq(move)))] & to_sq(move)
@ -957,11 +961,12 @@ moves_loop: // When in check search starts from here
&& moveCount >= FutilityMoveCounts[improving][depth])
continue;
// History based pruning
// Countermoves based pruning
if ( depth <= 4 * ONE_PLY
&& move != ss->killers[0]
&& thisThread->history[pos.moved_piece(move)][to_sq(move)] < VALUE_ZERO
&& cmh[pos.moved_piece(move)][to_sq(move)] < VALUE_ZERO)
&& (!cmh || (*cmh )[moved_piece][to_sq(move)] < VALUE_ZERO)
&& (!fmh || (*fmh )[moved_piece][to_sq(move)] < VALUE_ZERO)
&& (!fmh2 || (*fmh2)[moved_piece][to_sq(move)] < VALUE_ZERO || (cmh && fmh)))
continue;
predictedDepth = std::max(newDepth - reduction<PvNode>(improving, depth, moveCount), DEPTH_ZERO);
@ -994,7 +999,7 @@ moves_loop: // When in check search starts from here
}
ss->currentMove = move;
ss->counterMoves = &CounterMoveHistory[pos.moved_piece(move)][to_sq(move)];
ss->counterMoves = &CounterMoveHistory[moved_piece][to_sq(move)];
// Step 14. Make the move
pos.do_move(move, st, givesCheck);
@ -1006,20 +1011,17 @@ moves_loop: // When in check search starts from here
&& !captureOrPromotion)
{
Depth r = reduction<PvNode>(improving, depth, moveCount);
Value hValue = thisThread->history[pos.piece_on(to_sq(move))][to_sq(move)];
Value cmhValue = cmh[pos.piece_on(to_sq(move))][to_sq(move)];
const CounterMoveStats* fm = (ss - 2)->counterMoves;
const CounterMoveStats* fm2 = (ss - 4)->counterMoves;
Value fmValue = (fm ? (*fm)[pos.piece_on(to_sq(move))][to_sq(move)] : VALUE_ZERO);
Value fm2Value = (fm2 ? (*fm2)[pos.piece_on(to_sq(move))][to_sq(move)] : VALUE_ZERO);
Value val = thisThread->history[moved_piece][to_sq(move)]
+ (cmh ? (*cmh )[moved_piece][to_sq(move)] : VALUE_ZERO)
+ (fmh ? (*fmh )[moved_piece][to_sq(move)] : VALUE_ZERO)
+ (fmh2 ? (*fmh2)[moved_piece][to_sq(move)] : VALUE_ZERO);
// Increase reduction for cut nodes
if (!PvNode && cutNode)
r += ONE_PLY;
// Decrease/increase reduction for moves with a good/bad history
int rHist = (hValue + cmhValue + fmValue + fm2Value - 10000) / 20000;
int rHist = (val - 10000) / 20000;
r = std::max(DEPTH_ZERO, r - rHist * ONE_PLY);
// Decrease reduction for moves that escape a capture. Filter out