Merge official-stockfish/master
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 4 May 2019 13:33:28 +0000 (15:33 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 4 May 2019 13:33:28 +0000 (15:33 +0200)
No functional change.

12 files changed:
1  2 
src/bitbase.cpp
src/bitboard.cpp
src/bitboard.h
src/evaluate.cpp
src/misc.cpp
src/pawns.cpp
src/position.cpp
src/position.h
src/search.cpp
src/thread.cpp
src/timeman.cpp
src/ucioption.cpp

diff --cc src/bitbase.cpp
Simple merge
  uint8_t PopCnt16[1 << 16];
  uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
  
+ Bitboard SquareBB[SQUARE_NB];
  Bitboard LineBB[SQUARE_NB][SQUARE_NB];
 -Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
 -Bitboard PawnAttacks[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];
- Bitboard SquareBB[SQUARE_NB];
 +Bitboard BoardSizeBB[FILE_NB][RANK_NB];
  
- Bitboard KingFlank[FILE_NB] = {
-   QueenSide ^ FileDBB, QueenSide, QueenSide,
-   CenterFiles, CenterFiles,
-   KingSide, KingSide, KingSide ^ FileEBB
- };
  Magic RookMagics[SQUARE_NB];
  Magic BishopMagics[SQUARE_NB];
  
diff --cc src/bitboard.h
@@@ -95,18 -74,11 +101,18 @@@ constexpr Bitboard KingFlank[FILE_NB] 
  extern uint8_t PopCnt16[1 << 16];
  extern uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
  
+ extern Bitboard SquareBB[SQUARE_NB];
  extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
 -extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
 -extern Bitboard PawnAttacks[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];
- extern Bitboard KingFlank[FILE_NB];
 +extern Bitboard SquareBB[SQUARE_NB];
 +extern Bitboard BoardSizeBB[FILE_NB][RANK_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 {
@@@ -202,22 -152,12 +208,24 @@@ constexpr Bitboard make_bitboard(Squar
  
  template<Direction D>
  constexpr Bitboard shift(Bitboard b) {
 -  return  D == NORTH      ?  b             << 8 : D == SOUTH      ?  b             >> 8
 -        : D == NORTH+NORTH?  b             <<16 : D == SOUTH+SOUTH?  b             >>16
 -        : D == EAST       ? (b & ~FileHBB) << 1 : D == WEST       ? (b & ~FileABB) >> 1
 -        : D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == NORTH_WEST ? (b & ~FileABB) << 7
 -        : D == SOUTH_EAST ? (b & ~FileHBB) >> 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
 -        : 0;
 +  return  D == NORTH      ?  b                       << NORTH      : D == SOUTH      ?  b             >> NORTH
++        : D == NORTH+NORTH?  b                       <<(2 * NORTH) : D == SOUTH+SOUTH?  b             >> (2 * NORTH)
 +        : D == EAST       ? (b & ~file_bb(FILE_MAX)) << EAST       : D == WEST       ? (b & ~FileABB) >> EAST
 +        : D == NORTH_EAST ? (b & ~file_bb(FILE_MAX)) << NORTH_EAST : D == NORTH_WEST ? (b & ~FileABB) << NORTH_WEST
 +        : D == SOUTH_EAST ? (b & ~file_bb(FILE_MAX)) >> NORTH_WEST : D == SOUTH_WEST ? (b & ~FileABB) >> NORTH_EAST
 +        : Bitboard(0);
 +}
 +
 +
 +/// shift() moves a bitboard one step along direction D (mainly for pawns)
 +
 +constexpr Bitboard shift(Direction D, Bitboard b) {
 +  return  D == NORTH      ?  b                       << NORTH      : D == SOUTH      ?  b             >> NORTH
++        : D == NORTH+NORTH?  b                       <<(2 * NORTH) : D == SOUTH+SOUTH?  b             >> (2 * NORTH)
 +        : D == EAST       ? (b & ~file_bb(FILE_MAX)) << EAST       : D == WEST       ? (b & ~FileABB) >> EAST
 +        : D == NORTH_EAST ? (b & ~file_bb(FILE_MAX)) << NORTH_EAST : D == NORTH_WEST ? (b & ~FileABB) << NORTH_WEST
 +        : D == SOUTH_EAST ? (b & ~file_bb(FILE_MAX)) >> NORTH_WEST : D == SOUTH_WEST ? (b & ~FileABB) >> NORTH_EAST
 +        : Bitboard(0);
  }
  
  
@@@ -396,15 -353,15 +396,15 @@@ namespace 
          if (Pt == ROOK)
          {
              // Bonus for aligning rook with enemy pawns on the same rank/file
 -            if (relative_rank(Us, s) >= RANK_5)
 -                score += RookOnPawn * popcount(pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s]);
 +            if (relative_rank(Us, s, pos.max_rank()) >= RANK_5)
 +                score += RookOnPawn * popcount(pos.pieces(Them, PAWN) & PseudoAttacks[Us][ROOK][s]);
  
              // Bonus for rook on an open or semi-open file
-             if (pos.semiopen_file(Us, file_of(s)))
-                 score += RookOnFile[bool(pos.semiopen_file(Them, file_of(s)))];
+             if (pos.is_semiopen_file(Us, file_of(s)))
+                 score += RookOnFile[bool(pos.is_semiopen_file(Them, file_of(s)))];
  
              // Penalty when trapped by the king, even more if the king cannot castle
 -            else if (mob <= 3)
 +            else if (mob <= 3 && pos.count<KING>(Us))
              {
                  File kf = file_of(pos.square<KING>(Us));
                  if ((kf < FILE_E) == (file_of(s) < kf))
  
      // Find the available squares for our pieces inside the area defined by SpaceMask
      Bitboard safe =   SpaceMask
 -                   & ~pos.pieces(Us, PAWN)
 -                   & ~attackedBy[Them][PAWN];
 +                   & ~pos.pieces(Us, PAWN, SHOGI_PAWN)
 +                   & ~attackedBy[Them][PAWN]
 +                   & ~attackedBy[Them][SHOGI_PAWN];
  
      // Find all squares which are at most three squares behind some friendly pawn
 -    Bitboard behind = pos.pieces(Us, PAWN);
 +    Bitboard behind = pos.pieces(Us, PAWN, SHOGI_PAWN);
      behind |= shift<Down>(behind);
-     behind |= shift<Down>(shift<Down>(behind));
+     behind |= shift<Down+Down>(behind);
  
 +    if (pawnsOnly)
 +    {
 +        safe = behind & ~attackedBy[Them][ALL_PIECES];
 +        behind = 0;
 +    }
 +
      int bonus = popcount(safe) + popcount(behind & safe);
      int weight =  pos.count<ALL_PIECES>(Us)
                 - (16 - pos.count<PAWN>()) / 4;
      int sf = me->scale_factor(pos, strongSide);
  
      // If scale is not already specific, scale down the endgame via general heuristics
 -    if (sf == SCALE_FACTOR_NORMAL)
 +    if (sf == SCALE_FACTOR_NORMAL && !pos.captures_to_hand())
      {
          if (   pos.opposite_bishops()
-             && pos.non_pawn_material(WHITE) == BishopValueMg
-             && pos.non_pawn_material(BLACK) == BishopValueMg)
+             && pos.non_pawn_material() == 2 * BishopValueMg)
              sf = 16 + 4 * pe->passed_count();
          else
              sf = std::min(40 + (pos.opposite_bishops() ? 2 : 7) * pos.count<PAWN>(strongSide), sf);
diff --cc src/misc.cpp
Simple merge
diff --cc src/pawns.cpp
@@@ -200,16 -176,16 +201,16 @@@ Value Entry::evaluate_shelter(const Pos
  
    constexpr Color     Them = (Us == WHITE ? BLACK : WHITE);
    constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
-   Bitboard  BlockRanks = rank_bb(relative_rank(Us, RANK_1, pos.max_rank())) | rank_bb(relative_rank(Us, RANK_2, pos.max_rank()));
 -  constexpr Bitboard BlockSquares =  (Rank1BB | Rank2BB | Rank7BB | Rank8BB)
 -                                   & (FileABB | FileHBB);
++  Bitboard  BlockSquares = (rank_bb(relative_rank(Us, RANK_1, pos.max_rank())) | rank_bb(relative_rank(Us, RANK_2, pos.max_rank())))
++                          & (FileABB | file_bb(pos.max_file()));
  
 -  Bitboard b = pos.pieces(PAWN) & ~forward_ranks_bb(Them, ksq);
 +  Bitboard b = pos.pieces(PAWN, SHOGI_PAWN) & ~forward_ranks_bb(Them, ksq);
    Bitboard ourPawns = b & pos.pieces(Us);
    Bitboard theirPawns = b & pos.pieces(Them);
  
-   Value safety = (shift<Down>(theirPawns) & (FileABB | FileHBB) & BlockRanks & ksq) ?
-                  Value(374) : Value(5);
+   Value safety = (shift<Down>(theirPawns) & BlockSquares & ksq) ? Value(374) : Value(5);
  
 -  File center = clamp(file_of(ksq), FILE_B, FILE_G);
 +  File center = clamp(file_of(ksq), FILE_B, File(pos.max_file() - 1));
    for (File f = File(center - 1); f <= File(center + 1); ++f)
    {
        b = ourPawns & file_bb(f);
@@@ -456,12 -338,11 +457,12 @@@ void Position::set_castling_right(Colo
    castlingRightsMask[rfrom] |= cr;
    castlingRookSquare[cr] = rfrom;
  
 -  Square kto = relative_square(c, cs == KING_SIDE ? SQ_G1 : SQ_C1);
 -  Square rto = relative_square(c, cs == KING_SIDE ? SQ_F1 : SQ_D1);
 +  Square kto = make_square(cs == KING_SIDE ? castling_kingside_file() : castling_queenside_file(),
 +                           relative_rank(c, RANK_1, max_rank()));
 +  Square rto = kto + (cs == KING_SIDE ? WEST : EAST);
  
-   castlingPath[cr] = (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto)
-                    & ~(square_bb(kfrom) | rfrom);
+   castlingPath[cr] =   (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto)
+                     & ~(square_bb(kfrom) | rfrom);
  }
  
  
@@@ -1191,11 -859,7 +1192,10 @@@ void Position::do_move(Move m, StateInf
        }
  
        // Update pawn hash key and prefetch access to pawnsTable
 -      st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
 +      if (type_of(m) == DROP)
 +          st->pawnKey ^= Zobrist::psq[pc][to];
 +      else
 +          st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
-       prefetch2(thisThread->pawnsTable[st->pawnKey]);
  
        // Reset rule 50 draw counter
        st->rule50 = 0;
diff --cc src/position.h
@@@ -160,9 -94,8 +160,9 @@@ public
    template<PieceType Pt> int count(Color c) const;
    template<PieceType Pt> int count() const;
    template<PieceType Pt> const Square* squares(Color c) const;
 +  const Square* squares(Color c, PieceType pt) const;
    template<PieceType Pt> Square square(Color c) const;
-   int semiopen_file(Color c, File f) const;
+   bool is_semiopen_file(Color c, File f) const;
  
    // Castling
    int castling_rights(Color c) const;
@@@ -670,8 -262,8 +670,8 @@@ inline Square Position::ep_square() con
    return st->epSquare;
  }
  
- inline int Position::semiopen_file(Color c, File f) const {
+ inline bool Position::is_semiopen_file(Color c, File f) const {
 -  return !(pieces(c, PAWN) & file_bb(f));
 +  return !(pieces(c, PAWN, SHOGI_PAWN) & file_bb(f));
  }
  
  inline bool Position::can_castle(CastlingRight cr) const {
@@@ -729,7 -321,7 +729,7 @@@ inline bool Position::pawn_passed(Colo
  
  inline bool Position::advanced_pawn_push(Move m) const {
    return   type_of(moved_piece(m)) == PAWN
-         && relative_rank(sideToMove, from_sq(m), max_rank()) > (max_rank() + 1) / 2 - 1;
 -        && relative_rank(sideToMove, to_sq(m)) > RANK_5;
++        && relative_rank(sideToMove, to_sq(m), max_rank()) > (max_rank() + 1) / 2;
  }
  
  inline int Position::pawns_on_same_color_squares(Color c, Square s) const {
diff --cc src/search.cpp
Simple merge
diff --cc src/thread.cpp
Simple merge
diff --cc src/timeman.cpp
Simple merge
Simple merge