Merge official-stockfish/master
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 22 Mar 2019 20:35:36 +0000 (21:35 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 22 Mar 2019 20:35:36 +0000 (21:35 +0100)
bench: 3456069

1  2 
src/bitboard.cpp
src/bitboard.h
src/evaluate.cpp
src/search.cpp

  uint8_t PopCnt16[1 << 16];
  int8_t SquareDistance[SQUARE_NB][SQUARE_NB];
  
 +Bitboard BoardSizeBB[FILE_NB][RANK_NB];
  Bitboard SquareBB[SQUARE_NB];
  Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
  Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
  Bitboard LineBB[SQUARE_NB][SQUARE_NB];
 -Bitboard DistanceRingBB[SQUARE_NB][8];
 -Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
 -Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
 +Bitboard DistanceRingBB[SQUARE_NB][FILE_NB];
- Bitboard ForwardFileBB[COLOR_NB][SQUARE_NB];
- Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
- Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
 +Bitboard PseudoAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
 +Bitboard PseudoMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
 +Bitboard LeaperAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
 +Bitboard LeaperMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
  
  Magic RookMagics[SQUARE_NB];
  Magic BishopMagics[SQUARE_NB];
@@@ -368,32 -82,14 +363,18 @@@ void Bitboards::init() 
    for (unsigned i = 0; i < (1 << 16); ++i)
        PopCnt16[i] = (uint8_t) popcount16(i);
  
 -  for (Square s = SQ_A1; s <= SQ_H8; ++s)
 -      SquareBB[s] = (1ULL << s);
 +  for (Square s = SQ_A1; s <= SQ_MAX; ++s)
 +      SquareBB[s] = make_bitboard(s);
  
-   for (File f = FILE_A; f <= FILE_MAX; ++f)
-       FileBB[f] = f > FILE_A ? FileBB[f - 1] << 1 : FileABB;
-   for (Rank r = RANK_1; r <= RANK_MAX; ++r)
-       RankBB[r] = r > RANK_1 ? RankBB[r - 1] << FILE_NB : Rank1BB;
 -  for (Rank r = RANK_1; r < RANK_8; ++r)
 +  for (Rank r = RANK_1; r < RANK_MAX; ++r)
-       ForwardRanksBB[WHITE][r] = ~(ForwardRanksBB[BLACK][r + 1] = ForwardRanksBB[BLACK][r] | RankBB[r]);
-   for (Color c = WHITE; c <= BLACK; ++c)
-       for (Square s = SQ_A1; s <= SQ_MAX; ++s)
-       {
-           ForwardFileBB [c][s] = ForwardRanksBB[c][rank_of(s)] & FileBB[file_of(s)];
-           PawnAttackSpan[c][s] = ForwardRanksBB[c][rank_of(s)] & adjacent_files_bb(file_of(s));
-           PassedPawnMask[c][s] = ForwardFileBB [c][s] | PawnAttackSpan[c][s];
-       }
+       ForwardRanksBB[WHITE][r] = ~(ForwardRanksBB[BLACK][r + 1] = ForwardRanksBB[BLACK][r] | rank_bb(r));
  
 -  for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
 -      for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
 +  for (File f = FILE_A; f <= FILE_MAX; ++f)
 +      for (Rank r = RANK_1; r <= RANK_MAX; ++r)
-           BoardSizeBB[f][r] = ForwardFileBB[BLACK][make_square(f, r)] | SquareBB[make_square(f, r)] | (f > FILE_A ? BoardSizeBB[f - 1][r] : 0);
++          BoardSizeBB[f][r] = forward_file_bb(BLACK, make_square(f, r)) | SquareBB[make_square(f, r)] | (f > FILE_A ? BoardSizeBB[f - 1][r] : 0);
 +
 +  for (Square s1 = SQ_A1; s1 <= SQ_MAX; ++s1)
 +      for (Square s2 = SQ_A1; s2 <= SQ_MAX; ++s2)
            if (s1 != s2)
            {
                SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
diff --cc src/bitboard.h
@@@ -89,25 -62,14 +89,20 @@@ constexpr Bitboard Rank10BB = Rank1BB <
  
  extern int8_t SquareDistance[SQUARE_NB][SQUARE_NB];
  
 +extern Bitboard BoardSizeBB[FILE_NB][RANK_NB];
  extern Bitboard SquareBB[SQUARE_NB];
  extern Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
  extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
  extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
 -extern Bitboard DistanceRingBB[SQUARE_NB][8];
 -extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
 -extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
 -
 +extern Bitboard DistanceRingBB[SQUARE_NB][FILE_NB];
- extern Bitboard ForwardFileBB[COLOR_NB][SQUARE_NB];
- extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
- extern Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
 +extern Bitboard PseudoAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
 +extern Bitboard PseudoMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
 +extern Bitboard LeaperAttacks[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
 +extern Bitboard LeaperMoves[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
 +
 +#ifdef LARGEBOARDS
 +int popcount(Bitboard b); // required for 128 bit pext
 +#endif
  
  /// Magic holds all magic bitboards relevant data for a single square
  struct Magic {
@@@ -562,14 -480,15 +562,15 @@@ namespace 
      unsafeChecks &= mobilityArea[Them];
  
      kingDanger +=        kingAttackersCount[Them] * kingAttackersWeight[Them]
-                     + 69  * kingAttacksCount[Them] * (1 + 2 * !!pos.max_check_count())
-                     + 185 * popcount(kingRing[Us] & weak) * (1 + pos.captures_to_hand() + !!pos.max_check_count())
-                     + 150 * popcount(pos.blockers_for_king(Us) | unsafeChecks)
-                     +       tropism * tropism / 4
-                     - 873 * !(pos.count<QUEEN>(Them) || pos.captures_to_hand()) / (1 + !!pos.max_check_count())
-                     -   6 * mg_value(score) / 8
-                     +       mg_value(mobility[Them] - mobility[Us])
-                     -   30;
 -                 +  69 * kingAttacksCount[Them]
 -                 + 185 * popcount(kingRing[Us] & weak)
++                 + 69  * kingAttacksCount[Them] * (1 + 2 * !!pos.max_check_count())
++                 + 185 * popcount(kingRing[Us] & weak) * (1 + pos.captures_to_hand() + !!pos.max_check_count())
+                  - 100 * bool(attackedBy[Us][KNIGHT] & attackedBy[Us][KING])
+                  + 150 * popcount(pos.blockers_for_king(Us) | unsafeChecks)
+                  +   5 * tropism * tropism / 16
 -                 - 873 * !pos.count<QUEEN>(Them)
++                 - 873 * !(pos.count<QUEEN>(Them) || pos.captures_to_hand()) / (1 + !!pos.max_check_count())
+                  -   6 * mg_value(score) / 8
+                  +       mg_value(mobility[Them] - mobility[Us])
+                  -   25;
  
      // Transform the kingDanger units into a Score, and subtract it from the evaluation
      if (kingDanger > 0)
diff --cc src/search.cpp
@@@ -971,15 -953,13 +971,17 @@@ moves_loop: // When in check, search st
            else if (cutNode && singularBeta > beta)
                return beta;
        }
-       else if (    givesCheck // Check extension (~2 Elo)
-                &&  pos.see_ge(move))
+       // Check extension (~2 Elo)
+       else if (    givesCheck
+                && (pos.blockers_for_king(~us) & from_sq(move) || pos.see_ge(move)))
            extension = ONE_PLY;
 +      else if (    pos.must_capture() // Capture extension (all moves are captures)
 +               &&  pos.capture(move)
 +               &&  MoveList<CAPTURES>(pos).size() == 1)
 +          extension = ONE_PLY;
  
-       // Extension if castling
+       // Castling extension
        else if (type_of(move) == CASTLING)
            extension = ONE_PLY;