X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=f1eb71ec30e11affe1d17496f35ef47288a5a770;hp=9739a0018ab24861f5fea5d811cd3bd2ad2b3823;hb=09efbf915e8f09dbca94efbc087fcb5568c5d099;hpb=d30994ecd54bf96db88016fb6d92ff2c4614bc2e diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 9739a001..f1eb71ec 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -183,9 +183,11 @@ namespace { const Score BishopPawns = S( 8, 12); const Score RookOnPawn = S( 8, 24); const Score TrappedRook = S(92, 0); - const Score Checked = S(20, 20); + const Score SafeCheck = S(20, 20); + 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); @@ -209,10 +211,10 @@ namespace { // Penalties for enemy's safe checks const int QueenContactCheck = 89; - const int QueenCheck = 52; - const int RookCheck = 45; - const int BishopCheck = 5; - const int KnightCheck = 17; + const int QueenCheck = 62; + const int RookCheck = 57; + const int BishopCheck = 48; + const int KnightCheck = 78; // eval_init() initializes king and attack bitboards for a given color @@ -234,7 +236,7 @@ namespace { { ei.kingRing[Them] = b | shift_bb(b); b &= ei.attackedBy[Us][PAWN]; - ei.kingAttackersCount[Us] = b ? popcount(b) : 0; + ei.kingAttackersCount[Us] = popcount(b); ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = 0; } else @@ -276,9 +278,7 @@ namespace { { ei.kingAttackersCount[Us]++; ei.kingAttackersWeight[Us] += KingAttackWeights[Pt]; - bb = b & ei.attackedBy[Them][KING]; - if (bb) - ei.kingAdjacentZoneAttacksCount[Us] += popcount(bb); + ei.kingAdjacentZoneAttacksCount[Us] += popcount(b & ei.attackedBy[Them][KING]); } if (Pt == QUEEN) @@ -331,11 +331,7 @@ namespace { { // Bonus for aligning with enemy pawns on the same rank/file if (relative_rank(Us, s) >= RANK_5) - { - Bitboard alignedPawns = pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s]; - if (alignedPawns) - score += RookOnPawn * popcount(alignedPawns); - } + score += RookOnPawn * popcount(pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s]); // Bonus when on an open or semi-open file if (ei.pi->semiopen_file(Us, file_of(s))) @@ -352,6 +348,13 @@ namespace { score -= (TrappedRook - make_score(mob * 22, 0)) * (1 + !pos.can_castle(Us)); } } + + if (Pt == QUEEN) + { + // Penalty if any relative pin or discovered attack against the queen + if (pos.slider_blockers(pos.pieces(), pos.pieces(Them, ROOK, BISHOP), s)) + score -= WeakQueen; + } } if (DoTrace) @@ -372,9 +375,10 @@ namespace { template Score evaluate_king(const Position& pos, const EvalInfo& ei) { - const Color Them = (Us == WHITE ? BLACK : WHITE); + const Color Them = (Us == WHITE ? BLACK : WHITE); + const Square Up = (Us == WHITE ? DELTA_N : DELTA_S); - Bitboard undefended, b, b1, b2, safe; + Bitboard undefended, b, b1, b2, safe, other; int attackUnits; const Square ksq = pos.square(Us); @@ -402,8 +406,8 @@ namespace { // the pawn shelter (current 'score' value). attackUnits = std::min(72, ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them]) + 9 * ei.kingAdjacentZoneAttacksCount[Them] - + 27 * popcount(undefended) - + 11 * (popcount(b) + !!ei.pinnedPieces[Us]) + + 21 * popcount(undefended) + + 12 * (popcount(b) + !!ei.pinnedPieces[Us]) - 64 * !pos.count(Them) - mg_value(score) / 8; @@ -417,31 +421,45 @@ namespace { | ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][ROOK] | ei.attackedBy[Them][KING]; - if (b) - attackUnits += QueenContactCheck * popcount(b); + attackUnits += QueenContactCheck * popcount(b); } - // Analyse the enemy's safe distance checks for sliders and knights - safe = ~(ei.attackedBy[Us][ALL_PIECES] | pos.pieces(Them)); + // Analyse the safe enemy's checks which are possible on next move... + safe = ~(ei.attackedBy[Us][ALL_PIECES] | pos.pieces(Them)); + + // ... and some other potential checks, only requiring the square to be + // safe from pawn-attacks, and not being occupied by a blocked pawn. + other = ~( ei.attackedBy[Us][PAWN] + | (pos.pieces(Them, PAWN) & shift_bb(pos.pieces(PAWN)))); - b1 = pos.attacks_from(ksq) & safe; - b2 = pos.attacks_from(ksq) & safe; + b1 = pos.attacks_from(ksq); + b2 = pos.attacks_from(ksq); // Enemy queen safe checks - if ((b1 | b2) & ei.attackedBy[Them][QUEEN]) - attackUnits += QueenCheck, score -= Checked; + if ((b1 | b2) & ei.attackedBy[Them][QUEEN] & safe) + attackUnits += QueenCheck, score -= SafeCheck; + + // Enemy rooks safe and other checks + if (b1 & ei.attackedBy[Them][ROOK] & safe) + attackUnits += RookCheck, score -= SafeCheck; - // Enemy rooks safe checks - if (b1 & ei.attackedBy[Them][ROOK]) - attackUnits += RookCheck, score -= Checked; + else if (b1 & ei.attackedBy[Them][ROOK] & other) + score -= OtherCheck; - // Enemy bishops safe checks - if (b2 & ei.attackedBy[Them][BISHOP]) - attackUnits += BishopCheck, score -= Checked; + // Enemy bishops safe and other checks + if (b2 & ei.attackedBy[Them][BISHOP] & safe) + attackUnits += BishopCheck, score -= SafeCheck; - // Enemy knights safe checks - if (pos.attacks_from(ksq) & ei.attackedBy[Them][KNIGHT] & safe) - attackUnits += KnightCheck, score -= Checked; + else if (b2 & ei.attackedBy[Them][BISHOP] & other) + score -= OtherCheck; + + // Enemy knights safe and other checks + b = pos.attacks_from(ksq) & ei.attackedBy[Them][KNIGHT]; + if (b & safe) + attackUnits += KnightCheck, score -= SafeCheck; + + else if (b & other) + score -= OtherCheck; // Finally, extract the king danger score from the KingDanger[] // array and subtract the score from the evaluation. @@ -514,9 +532,7 @@ namespace { while (b) score += Threat[Rook ][type_of(pos.piece_on(pop_lsb(&b)))]; - b = weak & ~ei.attackedBy[Them][ALL_PIECES]; - if (b) - score += Hanging * popcount(b); + score += Hanging * popcount(weak & ~ei.attackedBy[Them][ALL_PIECES]); b = weak & ei.attackedBy[Us][KING]; if (b) @@ -535,8 +551,7 @@ namespace { & pos.pieces(Them) & ~ei.attackedBy[Us][PAWN]; - if (b) - score += ThreatByPawnPush * popcount(b); + score += ThreatByPawnPush * popcount(b); if (DoTrace) Trace::add(THREAT, Us, score); @@ -707,7 +722,7 @@ namespace { // Endgame with opposite-colored bishops, but also other pieces. Still // a bit drawish, but not as drawish as with only the two bishops. else - sf = ScaleFactor(46 * sf / SCALE_FACTOR_NORMAL); + sf = ScaleFactor(46); } // Endings where weaker side can place his king in front of the opponent's // pawns are drawish.