Merge official-stockfish/master
authorFabian Fichter <ianfab@users.noreply.github.com>
Sun, 9 Aug 2020 12:45:16 +0000 (14:45 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sun, 9 Aug 2020 12:45:16 +0000 (14:45 +0200)
No functional change.

1  2 
src/evaluate.cpp
src/pawns.cpp
src/position.cpp
src/position.h
src/search.cpp

@@@ -1178,19 -815,16 +1178,20 @@@ namespace 
      initialize<WHITE>();
      initialize<BLACK>();
  
 -    // Pieces evaluated first (also populates attackedBy, attackedBy2).
 -    // Note that the order of evaluation of the terms is left unspecified
 -    score +=  pieces<WHITE, KNIGHT>() - pieces<BLACK, KNIGHT>()
 -            + pieces<WHITE, BISHOP>() - pieces<BLACK, BISHOP>()
 -            + pieces<WHITE, ROOK  >() - pieces<BLACK, ROOK  >()
 -            + pieces<WHITE, QUEEN >() - pieces<BLACK, QUEEN >();
 +    // Pieces should be evaluated first (populate attack tables).
 +    // For unused piece types, we still need to set attack bitboard to zero.
 +    for (PieceType pt = KNIGHT; pt < KING; ++pt)
 +        if (pt != SHOGI_PAWN)
 +            score += pieces<WHITE>(pt) - pieces<BLACK>(pt);
 +
 +    // Evaluate pieces in hand once attack tables are complete
 +    if (pos.piece_drops() || pos.seirawan_gating())
 +        for (PieceType pt = PAWN; pt < KING; ++pt)
 +            score += hand<WHITE>(pt) - hand<BLACK>(pt);
  
 -    score += mobility[WHITE] - mobility[BLACK];
 +    score += (mobility[WHITE] - mobility[BLACK]) * (1 + pos.captures_to_hand() + pos.must_capture() + pos.check_counting());
  
+     // More complex interactions that require fully populated attack bitboards
      score +=  king<   WHITE>() - king<   BLACK>()
              + threats<WHITE>() - threats<BLACK>()
              + passed< WHITE>() - passed< BLACK>()
diff --cc src/pawns.cpp
@@@ -97,16 -96,16 +96,16 @@@ namespace 
  
          // Flag the pawn
          opposed    = theirPawns & forward_file_bb(Us, s);
 -        blocked    = theirPawns & (s + Up);
 +        blocked    = is_ok(s + Up) ? theirPawns & (s + Up) : Bitboard(0);
          stoppers   = theirPawns & passed_pawn_span(Us, s);
 -        lever      = theirPawns & PawnAttacks[Us][s];
 -        leverPush  = theirPawns & PawnAttacks[Us][s + Up];
 -        doubled    = ourPawns   & (s - Up);
 +        lever      = theirPawns & PseudoAttacks[Us][PAWN][s];
 +        leverPush  = relative_rank(Them, s, pos.max_rank()) > RANK_1 ? theirPawns & PseudoAttacks[Us][PAWN][s + Up] : Bitboard(0);
 +        doubled    = r > RANK_1 ? ourPawns & (s - Up) : Bitboard(0);
          neighbours = ourPawns   & adjacent_files_bb(s);
          phalanx    = neighbours & rank_bb(s);
 -        support    = neighbours & rank_bb(s - Up);
 +        support    = r > RANK_1 ? neighbours & rank_bb(s - Up) : Bitboard(0);
  
-         e->blockedCount[Us] += blocked || more_than_one(leverPush);
+         e->blockedCount += blocked || more_than_one(leverPush);
  
          // A pawn is backward when it is behind all pawns of the same color on
          // the adjacent files and cannot safely advance.
@@@ -477,11 -302,11 +477,11 @@@ void Position::set_castling_right(Colo
    castlingRightsMask[rfrom] |= cr;
    castlingRookSquare[cr] = rfrom;
  
 -  Square kto = relative_square(c, cr & KING_SIDE ? SQ_G1 : SQ_C1);
 -  Square rto = relative_square(c, cr & KING_SIDE ? SQ_F1 : SQ_D1);
 +  Square kto = make_square(cr & KING_SIDE ? castling_kingside_file() : castling_queenside_file(), castling_rank(c));
 +  Square rto = kto + (cr & KING_SIDE ? WEST : EAST);
  
    castlingPath[cr] =   (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto)
-                     & ~(square_bb(kfrom) | rfrom);
+                     & ~(kfrom | rfrom);
  }
  
  
diff --cc src/position.h
Simple merge
diff --cc src/search.cpp
@@@ -1254,8 -1170,7 +1254,8 @@@ moves_loop: // When in check, search st
                || moveCountPruning
                || ss->staticEval + PieceValue[EG][pos.captured_piece()] <= alpha
                || cutNode
-               || thisThread->ttHitAverage < 375 * ttHitAverageResolution * ttHitAverageWindow / 1024)
 -              || thisThread->ttHitAverage < 375 * TtHitAverageResolution * TtHitAverageWindow / 1024))
++              || thisThread->ttHitAverage < 375 * TtHitAverageResolution * TtHitAverageWindow / 1024)
 +          && !(pos.must_capture() && MoveList<CAPTURES>(pos).size()))
        {
            Depth r = reduction(improving, depth, moveCount);