Merge branch 'master' of https://github.com/official-stockfish/Stockfish
authorFabian Fichter <ianfab@users.noreply.github.com>
Tue, 16 Apr 2019 20:28:45 +0000 (22:28 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Tue, 16 Apr 2019 20:28:45 +0000 (22:28 +0200)
bench: 3359419

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

@@@ -396,15 -354,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 (pe->semiopen_file(Us, file_of(s)))
-                 score += RookOnFile[bool(pe->semiopen_file(Them, file_of(s)))];
+             if (pos.semiopen_file(Us, file_of(s)))
+                 score += RookOnFile[bool(pos.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];
  
-     if (pawnsOnly)
-         safe = pos.pieces(Us, PAWN) & ~attackedBy[Them][ALL_PIECES];
      // 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));
  
++    if (pawnsOnly)
++    {
++        safe = behind & ~attackedBy[Them][ALL_PIECES];
++        behind = 0;
++    }
++
      int bonus = popcount(safe) + popcount(behind & safe);
      int weight =  pos.count<ALL_PIECES>(Us)
-                 - 2 * popcount(pe->semiopenFiles[WHITE] & pe->semiopenFiles[BLACK]);
+                - (16 - pos.count<PAWN>()) / 4;
  
      Score score = make_score(bonus * weight * weight / 16, 0);
  
diff --cc src/pawns.cpp
@@@ -89,9 -88,8 +88,8 @@@ namespace 
          assert(pos.piece_on(s) == make_piece(Us, PAWN));
  
          File f = file_of(s);
 -        Rank r = relative_rank(Us, s);
 +        Rank r = relative_rank(Us, s, pos.max_rank());
  
-         e->semiopenFiles[Us]   &= ~(1 << f);
          e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
  
          // Flag the pawn
              score -= Doubled;
      }
  
 +    // Double pawn evaluation if there are no non-pawn pieces
 +    if (pos.count<ALL_PIECES>(Us) == pos.count<PAWN>(Us))
 +        score = score * 2;
 +
 +    const Square* pl_shogi = pos.squares<SHOGI_PAWN>(Us);
 +
 +    ourPawns   = pos.pieces(Us,   SHOGI_PAWN);
 +    theirPawns = pos.pieces(Them, SHOGI_PAWN);
 +
 +    // Loop through all shogi pawns of the current color and score each one
 +    while ((s = *pl_shogi++) != SQ_NONE)
 +    {
 +        assert(pos.piece_on(s) == make_piece(Us, SHOGI_PAWN));
 +
 +        File f = file_of(s);
 +
-         e->semiopenFiles[Us] &= ~(1 << f);
 +        neighbours = ourPawns   & adjacent_files_bb(f);
 +
 +        if (!neighbours)
 +            score -= Isolated / 2;
 +    }
 +
      return score;
    }
  
diff --cc src/position.h
@@@ -160,8 -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;
  
    // Castling
    int castling_rights(Color c) const;
@@@ -668,6 -261,10 +669,10 @@@ inline Square Position::ep_square() con
    return st->epSquare;
  }
  
+ inline int Position::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 {
    return st->castlingRights & cr;
  }