From: Fabian Fichter Date: Fri, 15 Mar 2019 10:39:42 +0000 (+0100) Subject: Merge official-stockfish/master X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=b6f4f0a84455ad349964ce504bde5de2be4ad3df;p=fairystockfish.git Merge official-stockfish/master bench: 3633478 --- b6f4f0a84455ad349964ce504bde5de2be4ad3df diff --cc src/bitboard.cpp index 1d01585,105d201..e4c369c --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@@ -24,9 -24,8 +24,9 @@@ #include "misc.h" uint8_t PopCnt16[1 << 16]; - int SquareDistance[SQUARE_NB][SQUARE_NB]; + int8_t SquareDistance[SQUARE_NB][SQUARE_NB]; +Bitboard BoardSizeBB[FILE_NB][RANK_NB]; Bitboard SquareBB[SQUARE_NB]; Bitboard FileBB[FILE_NB]; Bitboard RankBB[RANK_NB]; @@@ -369,26 -87,23 +368,23 @@@ 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_H; ++f) + 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_8; ++r) - RankBB[r] = r > RANK_1 ? RankBB[r - 1] << 8 : Rank1BB; + for (Rank r = RANK_1; r <= RANK_MAX; ++r) + RankBB[r] = r > RANK_1 ? RankBB[r - 1] << FILE_NB : Rank1BB; - for (File f = FILE_A; f <= FILE_MAX; ++f) - AdjacentFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_MAX ? FileBB[f + 1] : 0); - - 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_H8; ++s) + 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)] & AdjacentFilesBB[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]; } diff --cc src/bitboard.h index 88be5a1,b64c92e..32c6082 --- a/src/bitboard.h +++ b/src/bitboard.h @@@ -62,34 -50,18 +62,34 @@@ constexpr Bitboard FileEBB = FileABB < constexpr Bitboard FileFBB = FileABB << 5; constexpr Bitboard FileGBB = FileABB << 6; constexpr Bitboard FileHBB = FileABB << 7; +#ifdef LARGEBOARDS +constexpr Bitboard FileIBB = FileABB << 8; +constexpr Bitboard FileJBB = FileABB << 9; +constexpr Bitboard FileKBB = FileABB << 10; +constexpr Bitboard FileLBB = FileABB << 11; +#endif + +#ifdef LARGEBOARDS +constexpr Bitboard Rank1BB = 0xFFF; +#else constexpr Bitboard Rank1BB = 0xFF; -constexpr Bitboard Rank2BB = Rank1BB << (8 * 1); -constexpr Bitboard Rank3BB = Rank1BB << (8 * 2); -constexpr Bitboard Rank4BB = Rank1BB << (8 * 3); -constexpr Bitboard Rank5BB = Rank1BB << (8 * 4); -constexpr Bitboard Rank6BB = Rank1BB << (8 * 5); -constexpr Bitboard Rank7BB = Rank1BB << (8 * 6); -constexpr Bitboard Rank8BB = Rank1BB << (8 * 7); +#endif +constexpr Bitboard Rank2BB = Rank1BB << (FILE_NB * 1); +constexpr Bitboard Rank3BB = Rank1BB << (FILE_NB * 2); +constexpr Bitboard Rank4BB = Rank1BB << (FILE_NB * 3); +constexpr Bitboard Rank5BB = Rank1BB << (FILE_NB * 4); +constexpr Bitboard Rank6BB = Rank1BB << (FILE_NB * 5); +constexpr Bitboard Rank7BB = Rank1BB << (FILE_NB * 6); +constexpr Bitboard Rank8BB = Rank1BB << (FILE_NB * 7); +#ifdef LARGEBOARDS +constexpr Bitboard Rank9BB = Rank1BB << (FILE_NB * 8); +constexpr Bitboard Rank10BB = Rank1BB << (FILE_NB * 9); +#endif - extern int SquareDistance[SQUARE_NB][SQUARE_NB]; + extern int8_t SquareDistance[SQUARE_NB][SQUARE_NB]; +extern Bitboard BoardSizeBB[FILE_NB][RANK_NB]; extern Bitboard SquareBB[SQUARE_NB]; extern Bitboard FileBB[FILE_NB]; extern Bitboard RankBB[RANK_NB]; diff --cc src/evaluate.cpp index 2dcec8c,6bacb4e..25a83fe --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@@ -840,30 -698,24 +840,30 @@@ namespace template template Score Evaluation::space() const { - if (pos.non_pawn_material() < SpaceThreshold) + bool pawnsOnly = !(pos.pieces(Us) ^ pos.pieces(Us, PAWN)); + + if (pos.non_pawn_material() < SpaceThreshold && !pos.captures_to_hand() && !pawnsOnly) return SCORE_ZERO; - constexpr Color Them = (Us == WHITE ? BLACK : WHITE); + constexpr Color Them = (Us == WHITE ? BLACK : WHITE); + constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH); constexpr Bitboard SpaceMask = Us == WHITE ? CenterFiles & (Rank2BB | Rank3BB | Rank4BB) : CenterFiles & (Rank7BB | Rank6BB | Rank5BB); // 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 |= (Us == WHITE ? behind >> NORTH : behind << NORTH); - behind |= (Us == WHITE ? behind >> (2 * NORTH) : behind << (2 * NORTH)); - + behind |= shift(behind); + behind |= shift(shift(behind)); int bonus = popcount(safe) + popcount(behind & safe); int weight = pos.count(Us) diff --cc src/position.cpp index dd5f36a,812eabc..0923ea7 --- a/src/position.cpp +++ b/src/position.cpp @@@ -664,18 -498,10 +664,19 @@@ Bitboard Position::slider_blockers(Bitb Bitboard blockers = 0; pinners = 0; + if (s == SQ_NONE || !sliders) + return blockers; + - // Snipers are sliders that attack 's' when a piece is removed + // Snipers are sliders that attack 's' when a piece and other snipers are removed - Bitboard snipers = ( (PseudoAttacks[ ROOK][s] & pieces(QUEEN, ROOK)) - | (PseudoAttacks[BISHOP][s] & pieces(QUEEN, BISHOP))) & sliders; + Bitboard snipers = 0; + + for (PieceType pt : piece_types()) + { + Bitboard b = sliders & (PseudoAttacks[~c][pt][s] ^ LeaperAttacks[~c][pt][s]) & pieces(c, pt); + if (b) + snipers |= b & ~attacks_from(~c, pt, s); + } + Bitboard occupancy = pieces() & ~snipers; while (snipers) { diff --cc src/search.cpp index f681ba8,99985fd..e20a623 --- a/src/search.cpp +++ b/src/search.cpp @@@ -763,9 -755,9 +760,9 @@@ namespace ss->staticEval = eval = pureStaticEval + bonus; } else - ss->staticEval = eval = pureStaticEval = -(ss-1)->staticEval + 2 * Eval::Tempo; + ss->staticEval = eval = pureStaticEval = -(ss-1)->staticEval + 2 * Eval::tempo_value(pos); - tte->save(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, pureStaticEval); + tte->save(posKey, VALUE_NONE, pvHit, BOUND_NONE, DEPTH_NONE, MOVE_NONE, pureStaticEval); } // Step 7. Razoring (~2 Elo) @@@ -1057,12 -1040,8 +1066,8 @@@ moves_loop: // When in check, search st if ((ss-1)->moveCount > 15) r -= ONE_PLY; - if (!captureOrPromotion) + if (!captureOrPromotion && !(pos.must_capture() && MoveList(pos).size())) { - // Decrease reduction for exact PV nodes (~0 Elo) - if (pvExact) - r -= ONE_PLY; - // Increase reduction if ttMove is a capture (~0 Elo) if (ttCapture) r += ONE_PLY; @@@ -1454,9 -1425,9 +1460,9 @@@ // All legal moves have been searched. A special case: If we're in check // and no legal moves were found, it is checkmate. if (inCheck && bestValue == -VALUE_INFINITE) - return mated_in(ss->ply); // Plies to mate from the root + return pos.checkmate_value(ss->ply); // Plies to mate from the root - tte->save(posKey, value_to_tt(bestValue, ss->ply), + tte->save(posKey, value_to_tt(bestValue, ss->ply), pvHit, bestValue >= beta ? BOUND_LOWER : PvNode && bestValue > oldAlpha ? BOUND_EXACT : BOUND_UPPER, ttDepth, bestMove, ss->staticEval); diff --cc src/tt.h index a81a819,8b98dbd..1ff460d --- a/src/tt.h +++ b/src/tt.h @@@ -24,13 -24,14 +24,14 @@@ #include "misc.h" #include "types.h" -/// TTEntry struct is the 10 bytes transposition table entry, defined as below: +/// TTEntry struct is the 12 bytes transposition table entry, defined as below: /// +/// move 32 bit /// key 16 bit -/// move 16 bit /// value 16 bit /// eval value 16 bit - /// generation 6 bit + /// generation 5 bit + /// PvNode 1 bit /// bound type 2 bit /// depth 8 bit diff --cc src/uci.cpp index 9300ca4,739cf34..b4f0d97 --- a/src/uci.cpp +++ b/src/uci.cpp @@@ -206,26 -207,21 +206,24 @@@ void UCI::loop(int argc, char* argv[]) token.clear(); // Avoid a stale if getline() returns empty or blank line is >> skipws >> token; - // The GUI sends 'ponderhit' to tell us the user has played the expected move. - // So 'ponderhit' will be sent if we were told to ponder on the same move the - // user has played. We should continue searching but switch from pondering to - // normal search. In case Threads.stopOnPonderhit is set we are waiting for - // 'ponderhit' to stop the search, for instance if max search depth is reached. if ( token == "quit" - || token == "stop" - || (token == "ponderhit" && Threads.stopOnPonderhit)) + || token == "stop") Threads.stop = true; + // The GUI sends 'ponderhit' to tell us the user has played the expected move. + // So 'ponderhit' will be sent if we were told to ponder on the same move the + // user has played. We should continue searching but switch from pondering to + // normal search. else if (token == "ponderhit") - Threads.ponder = false; // Switch to normal search + Threads.main()->ponder = false; // Switch to normal search - else if (token == "uci") + else if (token == "uci" || token == "usi") + { + Options["Protocol"] = token; sync_cout << "id name " << engine_info(true) << "\n" << Options - << "\nuciok" << sync_endl; + << "\n" << token << "ok" << sync_endl; + } else if (token == "setoption") setoption(is); else if (token == "go") go(pos, is, states);