From: Fabian Fichter Date: Sat, 4 May 2019 13:33:28 +0000 (+0200) Subject: Merge official-stockfish/master X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=10af434baa26a7823453b0d804f465f14d367a6f;p=fairystockfish.git Merge official-stockfish/master No functional change. --- 10af434baa26a7823453b0d804f465f14d367a6f diff --cc src/bitboard.cpp index 4e0194f,281579c..094f4c1 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@@ -28,20 -27,11 +28,14 @@@ 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 index 06cdaad,4e0267f..27870c3 --- a/src/bitboard.h +++ b/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 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); } diff --cc src/evaluate.cpp index 7bda6e5,5750d82..8bd9ed9 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@@ -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(Us)) { File kf = file_of(pos.square(Us)); if ((kf < FILE_E) == (file_of(s) < kf)) @@@ -855,21 -710,14 +855,21 @@@ // 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(behind); - behind |= shift(shift(behind)); + behind |= shift(behind); + if (pawnsOnly) + { + safe = behind & ~attackedBy[Them][ALL_PIECES]; + behind = 0; + } + int bonus = popcount(safe) + popcount(behind & safe); int weight = pos.count(Us) - (16 - pos.count()) / 4; @@@ -1007,11 -773,10 +1007,10 @@@ 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(strongSide), sf); diff --cc src/pawns.cpp index cd4c92d,0a88c9f..5c1e5ee --- a/src/pawns.cpp +++ b/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(theirPawns) & (FileABB | FileHBB) & BlockRanks & ksq) ? - Value(374) : Value(5); + Value safety = (shift(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); diff --cc src/position.cpp index 12ee530,8c6dc80..c016f1d --- a/src/position.cpp +++ b/src/position.cpp @@@ -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 index eb12b47,a3fb16b..1774397 --- a/src/position.h +++ b/src/position.h @@@ -160,9 -94,8 +160,9 @@@ public template int count(Color c) const; template int count() const; template const Square* squares(Color c) const; + const Square* squares(Color c, PieceType pt) const; template 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 {