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