- {}, {},
- { S(-75,-76), S(-56,-54), S(- 9,-26), S( -2,-10), S( 6, 5), S( 15, 11), // Knights
- S( 22, 26), S( 30, 28), S( 36, 29) },
- { S(-48,-58), S(-21,-19), S( 16, -2), S( 26, 12), S( 37, 22), S( 51, 42), // Bishops
- S( 54, 54), S( 63, 58), S( 65, 63), S( 71, 70), S( 79, 74), S( 81, 86),
- S( 92, 90), S( 97, 94) },
- { S(-56,-78), S(-25,-18), S(-11, 26), S( -5, 55), S( -4, 70), S( -1, 81), // Rooks
- S( 8,109), S( 14,120), S( 21,128), S( 23,143), S( 31,154), S( 32,160),
- S( 43,165), S( 49,168), S( 59,169) },
- { S(-40,-35), S(-25,-12), S( 2, 7), S( 4, 19), S( 14, 37), S( 24, 55), // Queens
- S( 25, 62), S( 40, 76), S( 43, 79), S( 47, 87), S( 54, 94), S( 56,102),
- S( 60,111), S( 70,116), S( 72,118), S( 73,122), S( 75,128), S( 77,130),
- S( 85,133), S( 94,136), S( 99,140), S(108,157), S(112,158), S(113,161),
- S(118,174), S(119,177), S(123,191), S(128,199) }
+ { S(-75,-76), S(-57,-54), S( -9,-28), S( -2,-10), S( 6, 5), S( 14, 12), // Knights
+ S( 22, 26), S( 29, 29), S( 36, 29) },
+ { S(-48,-59), S(-20,-23), S( 16, -3), S( 26, 13), S( 38, 24), S( 51, 42), // Bishops
+ S( 55, 54), S( 63, 57), S( 63, 65), S( 68, 73), S( 81, 78), S( 81, 86),
+ S( 91, 88), S( 98, 97) },
+ { S(-58,-76), S(-27,-18), S(-15, 28), S(-10, 55), S( -5, 69), S( -2, 82), // Rooks
+ S( 9,112), S( 16,118), S( 30,132), S( 29,142), S( 32,155), S( 38,165),
+ S( 46,166), S( 48,169), S( 58,171) },
+ { S(-39,-36), S(-21,-15), S( 3, 8), S( 3, 18), S( 14, 34), S( 22, 54), // Queens
+ S( 28, 61), S( 41, 73), S( 43, 79), S( 48, 92), S( 56, 94), S( 60,104),
+ S( 60,113), S( 66,120), S( 67,123), S( 70,126), S( 71,133), S( 73,136),
+ S( 79,140), S( 88,143), S( 88,148), S( 99,166), S(102,170), S(102,175),
+ S(106,184), S(109,191), S(113,206), S(116,212) }
- const Score RookOnFile[2] = { S(20, 7), S(45, 20) };
-
- // ThreatBySafePawn[PieceType] contains bonuses according to which piece
- // type is attacked by a pawn which is protected or is not attacked.
- const Score ThreatBySafePawn[PIECE_TYPE_NB] = {
- S(0, 0), S(0, 0), S(176, 139), S(131, 127), S(217, 218), S(203, 215) };
-
- // Threat[by minor/by rook][attacked PieceType] contains
- // bonuses according to which piece type attacks which one.
- // Attacks on lesser pieces which are pawn-defended are not considered.
- const Score Threat[][PIECE_TYPE_NB] = {
- { S(0, 0), S(0, 33), S(45, 43), S(46, 47), S(72,107), S(48,118) }, // by Minor
- { S(0, 0), S(0, 25), S(40, 62), S(40, 59), S( 0, 34), S(35, 48) } // by Rook
+ const Score RookOnFile[] = { S(20, 7), S(45, 20) };
+
+ // ThreatByMinor/ByRook[attacked PieceType] contains bonuses according to
+ // which piece type attacks which one. Attacks on lesser pieces which are
+ // pawn-defended are not considered.
+ const Score ThreatByMinor[PIECE_TYPE_NB] = {
+ S(0, 0), S(0, 33), S(45, 43), S(46, 47), S(72, 107), S(48, 118)
+ };
+
+ const Score ThreatByRook[PIECE_TYPE_NB] = {
+ S(0, 0), S(0, 25), S(40, 62), S(40, 59), S(0, 34), S(35, 48)
- const Score MinorBehindPawn = S(16, 0);
- 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 ThreatByHangingPawn = S(71, 61);
- const Score LooseEnemies = S( 0, 25);
- const Score Hanging = S(48, 27);
- const Score ThreatByPawnPush = S(38, 22);
- const Score Unstoppable = S( 0, 20);
-
- // 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 MinorBehindPawn = S( 16, 0);
+ const Score BishopPawns = S( 8, 12);
+ const Score LongRangedBishop = S( 22, 0);
+ const Score RookOnPawn = S( 8, 24);
+ const Score TrappedRook = S( 92, 0);
+ const Score WeakQueen = S( 50, 10);
+ const Score OtherCheck = S( 10, 10);
+ const Score CloseEnemies = S( 7, 0);
+ const Score PawnlessFlank = S( 20, 80);
+ const Score ThreatByHangingPawn = S( 71, 61);
+ const Score ThreatBySafePawn = S(192,175);
+ const Score ThreatByRank = S( 16, 3);
+ const Score Hanging = S( 48, 27);
+ const Score WeakUnopposedPawn = S( 5, 25);
+ const Score ThreatByPawnPush = S( 38, 22);
+ const Score ThreatByAttackOnQueen = S( 38, 22);
+ const Score HinderPassedPawn = S( 7, 0);
+ const Score TrappedBishopA1H1 = S( 50, 50);
- // attacked and undefended squares around our king and the quality of
- // the pawn shelter (current 'score' value).
- attackUnits = std::min(72, ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them])
- + 9 * ei.kingAdjacentZoneAttacksCount[Them]
- + 27 * popcount(undefended)
- + 11 * !!ei.pinnedPieces[Us]
- - 64 * !pos.count<QUEEN>(Them)
- - mg_value(score) / 8;
-
- // Analyse the enemy's safe queen contact checks. Firstly, find the
- // undefended squares around the king reachable by the enemy queen...
- b = undefended & ei.attackedBy[Them][QUEEN] & ~pos.pieces(Them);
- if (b)
- {
- // ...and then remove squares not supported by another enemy piece
- b &= ei.attackedBy[Them][PAWN] | ei.attackedBy[Them][KNIGHT]
- | ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][ROOK]
- | ei.attackedBy[Them][KING];
+ // attacked and weak squares around our king, the absence of queen and
+ // the quality of the pawn shelter (current 'score' value).
+ kingDanger = kingAttackersCount[Them] * kingAttackersWeight[Them]
+ + 102 * kingAdjacentZoneAttacksCount[Them]
+ + 191 * popcount(kingRing[Us] & weak)
+ + 143 * bool(pos.pinned_pieces(Us))
+ - 848 * !pos.count<QUEEN>(Them)
+ - 9 * mg_value(score) / 8
+ + 40;
+
+ // Analyse the safe enemy's checks which are possible on next move
+ safe = ~pos.pieces(Them);
+ safe &= ~attackedBy[Us][ALL_PIECES] | (weak & attackedBy2[Them]);
+
+ b1 = pos.attacks_from< ROOK>(ksq);
+ b2 = pos.attacks_from<BISHOP>(ksq);
- // Evaluate space for both sides, only during opening
- if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >= 12222)
- score += evaluate_space<WHITE>(pos, ei)
- - evaluate_space<BLACK>(pos, ei);
-
- // Evaluate position potential for the winning side
- score += evaluate_initiative(pos, ei.pi->pawn_asymmetry(), eg_value(score));
-
- // Evaluate scale factor for the winning side
- ScaleFactor sf = evaluate_scale_factor(pos, ei, eg_value(score));
-
- // Interpolate between a middlegame and a (scaled by 'sf') endgame score
- Value v = mg_value(score) * int(ei.me->game_phase())
- + eg_value(score) * int(PHASE_MIDGAME - ei.me->game_phase()) * sf / SCALE_FACTOR_NORMAL;
-
- v /= int(PHASE_MIDGAME);
-
- // In case of tracing add all remaining individual evaluation terms
- if (DoTrace)
- {
- Trace::add(MATERIAL, pos.psq_score());
- Trace::add(IMBALANCE, ei.me->imbalance());
- Trace::add(PAWN, ei.pi->pawns_score());
- Trace::add(MOBILITY, mobility[WHITE], mobility[BLACK]);
- Trace::add(SPACE, evaluate_space<WHITE>(pos, ei)
- , evaluate_space<BLACK>(pos, ei));
- Trace::add(TOTAL, score);
+ return (pos.side_to_move() == WHITE ? v : -v) + Eval::Tempo; // Side to move point of view