]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Halve king eval margin
[stockfish] / src / evaluate.cpp
index f18968ceb86ed5960c01acdd44084ca9256a476d..207892f4dea1fce081a588dcbab770b8c3aab18e 100644 (file)
@@ -391,7 +391,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
       {
           // Check for KBP vs KB with only a single pawn that is almost
           // certainly a draw or at least two pawns.
-          bool one_pawn = (pos.piece_count(WHITE, PAWN) + pos.piece_count(BLACK, PAWN) == 1);
+          bool one_pawn = (pos.count<PAWN>(WHITE) + pos.count<PAWN>(BLACK) == 1);
           sf = one_pawn ? ScaleFactor(8) : ScaleFactor(32);
       }
       else
@@ -440,8 +440,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
     ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us);
 
     // Init king safety tables only if we are going to use them
-    if (   pos.piece_count(Us, QUEEN)
-        && pos.non_pawn_material(Us) > QueenValueMg + PawnValueMg)
+    if (pos.count<QUEEN>(Us) && pos.non_pawn_material(Us) > QueenValueMg + PawnValueMg)
     {
         ei.kingRing[Them] = b | shift_bb<Down>(b);
         b &= ei.attackedBy[Us][PAWN];
@@ -488,7 +487,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
     Score score = SCORE_ZERO;
 
     const Color Them = (Us == WHITE ? BLACK : WHITE);
-    const Square* pl = pos.piece_list(Us, Piece);
+    const Square* pl = pos.list<Piece>(Us);
 
     ei.attackedBy[Us][Piece] = 0;
 
@@ -510,7 +509,9 @@ Value do_evaluate(const Position& pos, Value& margin) {
                 ei.kingAdjacentZoneAttacksCount[Us] += popcount<Max15>(bb);
         }
 
-        int mob = popcount<Piece == QUEEN ? Full : Max15>(b & mobilityArea);
+        int mob = Piece != QUEEN ? popcount<Max15>(b & mobilityArea)
+                                 : popcount<Full >(b & mobilityArea);
+
         mobility += MobilityBonus[Piece][mob];
 
         // Decrease score if we are attacked by an enemy pawn. Remaining part
@@ -531,7 +532,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
 
         // Bishop and knight outposts squares
         if (    (Piece == BISHOP || Piece == KNIGHT)
-            && !(pos.pieces(Them, PAWN) & attack_span_mask(Us, s)))
+            && !(pos.pieces(Them, PAWN) & pawn_attack_span(Us, s)))
             score += evaluate_outposts<Piece, Us>(pos, ei, s);
 
         if (  (Piece == ROOK || Piece == QUEEN)
@@ -542,8 +543,8 @@ Value do_evaluate(const Position& pos, Value& margin) {
                 && relative_rank(Us, pos.king_square(Them)) == RANK_8)
                 score += Piece == ROOK ? RookOn7th : QueenOn7th;
 
-            // Major piece attacking enemy pawns on the same rank
-            Bitboard pawns = pos.pieces(Them, PAWN) & rank_bb(s);
+            // Major piece attacking enemy pawns on the same rank/file
+            Bitboard pawns = pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s];
             if (pawns)
                 score += popcount<Max15>(pawns) * (Piece == ROOK ? RookOnPawn : QueenOnPawn);
         }
@@ -555,7 +556,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
             if (ei.pi->semiopen(Us, file_of(s)))
                 score += ei.pi->semiopen(Them, file_of(s)) ? RookOpenFile : RookSemiopenFile;
 
-            if (mob > 6 || ei.pi->semiopen(Us, file_of(s)))
+            if (mob > 3 || ei.pi->semiopen(Us, file_of(s)))
                 continue;
 
             Square ksq = pos.king_square(Us);
@@ -766,7 +767,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
         // be very big, and so capturing a single attacking piece can therefore
         // result in a score change far bigger than the value of the captured piece.
         score -= KingDanger[Us == Search::RootColor][attackUnits];
-        margins[Us] += mg_value(KingDanger[Us == Search::RootColor][attackUnits]);
+        margins[Us] += mg_value(KingDanger[Us == Search::RootColor][attackUnits]) / 2;
     }
 
     if (Trace)
@@ -822,7 +823,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
                 // If there is an enemy rook or queen attacking the pawn from behind,
                 // add all X-ray attacks by the rook or queen. Otherwise consider only
                 // the squares in the pawn's path attacked or occupied by the enemy.
-                if (   (forward_bb(Them, s) & pos.pieces(Them, ROOK, QUEEN))
+                if (    unlikely(forward_bb(Them, s) & pos.pieces(Them, ROOK, QUEEN))
                     && (forward_bb(Them, s) & pos.pieces(Them, ROOK, QUEEN) & pos.attacks_from<ROOK>(s)))
                     unsafeSquares = squaresToQueen;
                 else
@@ -991,7 +992,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
             // black pawns: a4, b4 white: b2 then pawn in b4 is giving support.
             if (!opposed)
             {
-                b2 = supporters & in_front_bb(winnerSide, blockSq + pawn_push(winnerSide));
+                b2 = supporters & in_front_bb(winnerSide, rank_of(blockSq + pawn_push(winnerSide)));
 
                 while (b2) // This while-loop could be replaced with LSB/MSB (depending on color)
                 {
@@ -1001,7 +1002,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
             }
 
             // Check pawns that can be sacrificed against the blocking pawn
-            b2 = attack_span_mask(winnerSide, blockSq) & candidates & ~(1ULL << s);
+            b2 = pawn_attack_span(winnerSide, blockSq) & candidates & ~(1ULL << s);
 
             while (b2) // This while-loop could be replaced with LSB/MSB (depending on color)
             {
@@ -1143,7 +1144,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
 
     stream.str("");
     stream << std::showpoint << std::showpos << std::fixed << std::setprecision(2);
-    memset(scores, 0, 2 * (TOTAL + 1) * sizeof(Score));
+    std::memset(scores, 0, 2 * (TOTAL + 1) * sizeof(Score));
 
     Value margin;
     do_evaluate<true>(pos, margin);