mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Sync with master
Verified against master with 4-men and partially 5-men tables.
This commit is contained in:
commit
8bedb19690
9 changed files with 71 additions and 67 deletions
|
@ -309,7 +309,7 @@ endif
|
|||
ifeq ($(pext),yes)
|
||||
CXXFLAGS += -DUSE_PEXT
|
||||
ifeq ($(comp),$(filter $(comp),gcc clang mingw))
|
||||
CXXFLAGS += -mbmi -mbmi2
|
||||
CXXFLAGS += -mbmi2
|
||||
endif
|
||||
endif
|
||||
|
||||
|
|
|
@ -268,13 +268,9 @@ inline int popcount(Bitboard b) {
|
|||
union { Bitboard bb; uint16_t u[4]; } v = { b };
|
||||
return PopCnt16[v.u[0]] + PopCnt16[v.u[1]] + PopCnt16[v.u[2]] + PopCnt16[v.u[3]];
|
||||
|
||||
#elif defined(_MSC_VER) && defined(__INTEL_COMPILER)
|
||||
#elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
||||
|
||||
return _mm_popcnt_u64(b);
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
return (int)__popcnt64(b);
|
||||
return (int)_mm_popcnt_u64(b);
|
||||
|
||||
#else // Assumed gcc or compatible compiler
|
||||
|
||||
|
|
|
@ -183,7 +183,8 @@ namespace {
|
|||
const Score BishopPawns = S( 8, 12);
|
||||
const Score RookOnPawn = S( 8, 24);
|
||||
const Score TrappedRook = S(92, 0);
|
||||
const Score Checked = S(20, 20);
|
||||
const Score SafeCheck = S(20, 20);
|
||||
const Score OtherCheck = S(10, 10);
|
||||
const Score ThreatByHangingPawn = S(71, 61);
|
||||
const Score LooseEnemies = S( 0, 25);
|
||||
const Score Hanging = S(48, 27);
|
||||
|
@ -366,9 +367,10 @@ namespace {
|
|||
template<Color Us, bool DoTrace>
|
||||
Score evaluate_king(const Position& pos, const EvalInfo& ei) {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S);
|
||||
|
||||
Bitboard undefended, b, b1, b2, safe;
|
||||
Bitboard undefended, b, b1, b2, safe, other;
|
||||
int attackUnits;
|
||||
const Square ksq = pos.square<KING>(Us);
|
||||
|
||||
|
@ -414,27 +416,42 @@ namespace {
|
|||
attackUnits += QueenContactCheck * popcount(b);
|
||||
}
|
||||
|
||||
// Analyse the enemy's safe distance checks for sliders and knights
|
||||
safe = ~(ei.attackedBy[Us][ALL_PIECES] | pos.pieces(Them));
|
||||
// Analyse the safe enemy's checks which are possible on next move...
|
||||
safe = ~(ei.attackedBy[Us][ALL_PIECES] | pos.pieces(Them));
|
||||
|
||||
b1 = pos.attacks_from<ROOK >(ksq) & safe;
|
||||
b2 = pos.attacks_from<BISHOP>(ksq) & safe;
|
||||
// ... and some other potential checks, only requiring the square to be
|
||||
// safe from pawn-attacks, and not being occupied by a blocked pawn.
|
||||
other = ~( ei.attackedBy[Us][PAWN]
|
||||
| (pos.pieces(Them, PAWN) & shift_bb<Up>(pos.pieces(PAWN))));
|
||||
|
||||
b1 = pos.attacks_from<ROOK >(ksq);
|
||||
b2 = pos.attacks_from<BISHOP>(ksq);
|
||||
|
||||
// Enemy queen safe checks
|
||||
if ((b1 | b2) & ei.attackedBy[Them][QUEEN])
|
||||
attackUnits += QueenCheck, score -= Checked;
|
||||
if ((b1 | b2) & ei.attackedBy[Them][QUEEN] & safe)
|
||||
attackUnits += QueenCheck, score -= SafeCheck;
|
||||
|
||||
// Enemy rooks safe checks
|
||||
if (b1 & ei.attackedBy[Them][ROOK])
|
||||
attackUnits += RookCheck, score -= Checked;
|
||||
// Enemy rooks safe and other checks
|
||||
if (b1 & ei.attackedBy[Them][ROOK] & safe)
|
||||
attackUnits += RookCheck, score -= SafeCheck;
|
||||
|
||||
// Enemy bishops safe checks
|
||||
if (b2 & ei.attackedBy[Them][BISHOP])
|
||||
attackUnits += BishopCheck, score -= Checked;
|
||||
else if (b1 & ei.attackedBy[Them][ROOK] & other)
|
||||
score -= OtherCheck;
|
||||
|
||||
// Enemy knights safe checks
|
||||
if (pos.attacks_from<KNIGHT>(ksq) & ei.attackedBy[Them][KNIGHT] & safe)
|
||||
attackUnits += KnightCheck, score -= Checked;
|
||||
// Enemy bishops safe and other checks
|
||||
if (b2 & ei.attackedBy[Them][BISHOP] & safe)
|
||||
attackUnits += BishopCheck, score -= SafeCheck;
|
||||
|
||||
else if (b2 & ei.attackedBy[Them][BISHOP] & other)
|
||||
score -= OtherCheck;
|
||||
|
||||
// Enemy knights safe and other checks
|
||||
b = pos.attacks_from<KNIGHT>(ksq) & ei.attackedBy[Them][KNIGHT];
|
||||
if (b & safe)
|
||||
attackUnits += KnightCheck, score -= SafeCheck;
|
||||
|
||||
else if (b & other)
|
||||
score -= OtherCheck;
|
||||
|
||||
// Finally, extract the king danger score from the KingDanger[]
|
||||
// array and subtract the score from the evaluation.
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
namespace {
|
||||
|
||||
enum Stages {
|
||||
MAIN_SEARCH, GOOD_CAPTURES, KILLERS, GOOD_QUIETS, BAD_QUIETS, BAD_CAPTURES,
|
||||
MAIN_SEARCH, GOOD_CAPTURES, KILLERS, QUIET, BAD_CAPTURES,
|
||||
EVASION, ALL_EVASIONS,
|
||||
QSEARCH_WITH_CHECKS, QCAPTURES_1, CHECKS,
|
||||
QSEARCH_WITHOUT_CHECKS, QCAPTURES_2,
|
||||
|
@ -199,17 +199,15 @@ void MovePicker::generate_next_stage() {
|
|||
endMoves = cur + 2 + (countermove != killers[0] && countermove != killers[1]);
|
||||
break;
|
||||
|
||||
case GOOD_QUIETS:
|
||||
endQuiets = endMoves = generate<QUIETS>(pos, moves);
|
||||
case QUIET:
|
||||
endMoves = generate<QUIETS>(pos, moves);
|
||||
score<QUIETS>();
|
||||
endMoves = std::partition(cur, endMoves, [](const ExtMove& m) { return m.value > VALUE_ZERO; });
|
||||
insertion_sort(cur, endMoves);
|
||||
break;
|
||||
|
||||
case BAD_QUIETS:
|
||||
cur = endMoves;
|
||||
endMoves = endQuiets;
|
||||
if (depth >= 3 * ONE_PLY)
|
||||
if (depth < 3 * ONE_PLY)
|
||||
{
|
||||
ExtMove* goodQuiet = std::partition(cur, endMoves, [](const ExtMove& m)
|
||||
{ return m.value > VALUE_ZERO; });
|
||||
insertion_sort(cur, goodQuiet);
|
||||
} else
|
||||
insertion_sort(cur, endMoves);
|
||||
break;
|
||||
|
||||
|
@ -282,7 +280,7 @@ Move MovePicker::next_move() {
|
|||
return move;
|
||||
break;
|
||||
|
||||
case GOOD_QUIETS: case BAD_QUIETS:
|
||||
case QUIET:
|
||||
move = *cur++;
|
||||
if ( move != ttMove
|
||||
&& move != killers[0]
|
||||
|
|
|
@ -100,7 +100,7 @@ private:
|
|||
Square recaptureSquare;
|
||||
Value threshold;
|
||||
int stage;
|
||||
ExtMove *endQuiets, *endBadCaptures = moves + MAX_MOVES - 1;
|
||||
ExtMove* endBadCaptures = moves + MAX_MOVES - 1;
|
||||
ExtMove moves[MAX_MOVES], *cur = moves, *endMoves = moves;
|
||||
};
|
||||
|
||||
|
|
|
@ -31,12 +31,8 @@ namespace {
|
|||
#define V Value
|
||||
#define S(mg, eg) make_score(mg, eg)
|
||||
|
||||
// Isolated pawn penalty by opposed flag and file
|
||||
const Score Isolated[2][FILE_NB] = {
|
||||
{ S(31, 36), S(45, 41), S(50, 41), S(50, 41),
|
||||
S(50, 41), S(50, 41), S(45, 41), S(31, 36) },
|
||||
{ S(21, 24), S(30, 28), S(33, 28), S(33, 28),
|
||||
S(33, 28), S(33, 28), S(30, 28), S(21, 24) } };
|
||||
// Isolated pawn penalty by opposed flag
|
||||
const Score Isolated[2] = { S(45, 40), S(30, 27) };
|
||||
|
||||
// Backward pawn penalty by opposed flag
|
||||
const Score Backward[2] = { S(56, 33), S(41, 19) };
|
||||
|
@ -48,10 +44,8 @@ namespace {
|
|||
// Connected pawn bonus by opposed, phalanx, twice supported and rank
|
||||
Score Connected[2][2][2][RANK_NB];
|
||||
|
||||
// Doubled pawn penalty by file
|
||||
const Score Doubled[FILE_NB] = {
|
||||
S(11, 34), S(17, 38), S(19, 38), S(19, 38),
|
||||
S(19, 38), S(19, 38), S(17, 38), S(11, 34) };
|
||||
// Doubled pawn penalty
|
||||
const Score Doubled = S(18,38);
|
||||
|
||||
// Lever bonus by rank
|
||||
const Score Lever[RANK_NB] = {
|
||||
|
@ -149,7 +143,7 @@ namespace {
|
|||
// either there is a stopper in the way on this rank, or there is a
|
||||
// stopper on adjacent file which controls the way to that rank.
|
||||
backward = (b | shift_bb<Up>(b & adjacent_files_bb(f))) & stoppers;
|
||||
|
||||
|
||||
assert(!backward || !(pawn_attack_span(Them, s + Up) & neighbours));
|
||||
}
|
||||
|
||||
|
@ -161,7 +155,7 @@ namespace {
|
|||
|
||||
// Score this pawn
|
||||
if (!neighbours)
|
||||
score -= Isolated[opposed][f];
|
||||
score -= Isolated[opposed];
|
||||
|
||||
else if (backward)
|
||||
score -= Backward[opposed];
|
||||
|
@ -173,7 +167,7 @@ namespace {
|
|||
score += Connected[opposed][!!phalanx][more_than_one(supported)][relative_rank(Us, s)];
|
||||
|
||||
if (doubled)
|
||||
score -= Doubled[f] / distance<Rank>(s, frontmost_sq(Us, doubled));
|
||||
score -= Doubled / distance<Rank>(s, frontmost_sq(Us, doubled));
|
||||
|
||||
if (lever)
|
||||
score += Lever[relative_rank(Us, s)];
|
||||
|
|
13
src/psqt.cpp
13
src/psqt.cpp
|
@ -38,13 +38,12 @@ const Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
|||
{ },
|
||||
{ // Pawn
|
||||
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) },
|
||||
{ S(-19, 5), S( 1,-4), S( 7, 8), S( 3,-2) },
|
||||
{ S(-26,-6), S( -7,-5), S( 19, 5), S(24, 4) },
|
||||
{ S(-25, 1), S(-14, 3), S( 20,-8), S(35,-3) },
|
||||
{ S(-14, 6), S( 0, 9), S( 3, 7), S(21,-6) },
|
||||
{ S(-14, 6), S(-13,-5), S( -6, 2), S(-2, 4) },
|
||||
{ S(-12, 1), S( 15,-9), S( -8, 1), S(-4,18) },
|
||||
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) }
|
||||
{ S(-16, 7), S( 1,-4), S( 7, 8), S( 3,-2) },
|
||||
{ S(-23,-4), S( -7,-5), S( 19, 5), S(24, 4) },
|
||||
{ S(-22, 3), S(-14, 3), S( 20,-8), S(35,-3) },
|
||||
{ S(-11, 8), S( 0, 9), S( 3, 7), S(21,-6) },
|
||||
{ S(-11, 8), S(-13,-5), S( -6, 2), S(-2, 4) },
|
||||
{ S( -9, 3), S( 15,-9), S( -8, 1), S(-4,18) }
|
||||
},
|
||||
{ // Knight
|
||||
{ S(-143, -97), S(-96,-82), S(-80,-46), S(-73,-14) },
|
||||
|
|
|
@ -350,6 +350,7 @@ void MainThread::search() {
|
|||
Thread* bestThread = this;
|
||||
if ( !this->easyMovePlayed
|
||||
&& Options["MultiPV"] == 1
|
||||
&& !Limits.depth
|
||||
&& !Skill(Options["Skill Level"]).enabled()
|
||||
&& rootMoves[0].pv[0] != MOVE_NONE)
|
||||
{
|
||||
|
@ -411,7 +412,7 @@ void Thread::search() {
|
|||
multiPV = std::min(multiPV, rootMoves.size());
|
||||
|
||||
// Iterative deepening loop until requested to stop or the target depth is reached.
|
||||
while (++rootDepth < DEPTH_MAX && !Signals.stop && (!Limits.depth || rootDepth <= Limits.depth))
|
||||
while (++rootDepth < DEPTH_MAX && !Signals.stop && (!Limits.depth || Threads.main()->rootDepth <= Limits.depth))
|
||||
{
|
||||
// Set up the new depths for the helper threads skipping on average every
|
||||
// 2nd ply (using a half-density matrix).
|
||||
|
@ -506,7 +507,7 @@ void Thread::search() {
|
|||
std::stable_sort(rootMoves.begin(), rootMoves.begin() + PVIdx + 1);
|
||||
|
||||
if (!mainThread)
|
||||
break;
|
||||
continue;
|
||||
|
||||
if (Signals.stop)
|
||||
sync_cout << "info nodes " << Threads.nodes_searched()
|
||||
|
@ -1012,13 +1013,12 @@ moves_loop: // When in check search starts from here
|
|||
Value fmValue = (fm ? (*fm)[pos.piece_on(to_sq(move))][to_sq(move)] : VALUE_ZERO);
|
||||
Value fm2Value = (fm2 ? (*fm2)[pos.piece_on(to_sq(move))][to_sq(move)] : VALUE_ZERO);
|
||||
|
||||
// Increase reduction for cut nodes and moves with a bad history
|
||||
if ( (!PvNode && cutNode)
|
||||
|| (hValue < VALUE_ZERO && cmhValue <= VALUE_ZERO))
|
||||
// Increase reduction for cut nodes
|
||||
if (!PvNode && cutNode)
|
||||
r += ONE_PLY;
|
||||
|
||||
// Decrease/increase reduction for moves with a good/bad history
|
||||
int rHist = (hValue + cmhValue + fmValue + fm2Value) / 20000;
|
||||
int rHist = (hValue + cmhValue + fmValue + fm2Value - 10000) / 20000;
|
||||
r = std::max(DEPTH_ZERO, r - rHist * ONE_PLY);
|
||||
|
||||
// Decrease reduction for moves that escape a capture. Filter out
|
||||
|
|
|
@ -60,12 +60,12 @@
|
|||
/// _WIN64 Building on Windows 64 bit
|
||||
|
||||
#if defined(_WIN64) && defined(_MSC_VER) // No Makefile used
|
||||
# include <intrin.h> // MSVC popcnt and bsfq instrinsics
|
||||
# include <intrin.h> // Microsoft header for _BitScanForward64()
|
||||
# define IS_64BIT
|
||||
#endif
|
||||
|
||||
#if defined(USE_POPCNT) && defined(__INTEL_COMPILER) && defined(_MSC_VER)
|
||||
# include <nmmintrin.h> // Intel header for _mm_popcnt_u64() intrinsic
|
||||
#if defined(USE_POPCNT) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
|
||||
# include <nmmintrin.h> // Intel and Microsoft header for _mm_popcnt_u64()
|
||||
#endif
|
||||
|
||||
#if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
|
||||
|
|
Loading…
Add table
Reference in a new issue