mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 09:39:36 +00:00
parent
d01b66ae8f
commit
a6d6a2c2fa
4 changed files with 36 additions and 34 deletions
|
@ -740,11 +740,10 @@ namespace {
|
||||||
|
|
||||||
int kingDistance = distance<File>(pos.square<KING>(WHITE), pos.square<KING>(BLACK))
|
int kingDistance = distance<File>(pos.square<KING>(WHITE), pos.square<KING>(BLACK))
|
||||||
- distance<Rank>(pos.square<KING>(WHITE), pos.square<KING>(BLACK));
|
- distance<Rank>(pos.square<KING>(WHITE), pos.square<KING>(BLACK));
|
||||||
int pawns = pos.count<PAWN>();
|
|
||||||
bool bothFlanks = (pos.pieces(PAWN) & QueenSide) && (pos.pieces(PAWN) & KingSide);
|
bool bothFlanks = (pos.pieces(PAWN) & QueenSide) && (pos.pieces(PAWN) & KingSide);
|
||||||
|
|
||||||
// Compute the initiative bonus for the attacking side
|
// Compute the initiative bonus for the attacking side
|
||||||
int initiative = 8 * (asymmetry + kingDistance - 17) + 12 * pawns + 16 * bothFlanks;
|
int initiative = 8 * (asymmetry + kingDistance - 17) + 12 * pos.count<PAWN>() + 16 * bothFlanks;
|
||||||
|
|
||||||
// Now apply the bonus: note that we find the attacking side by extracting
|
// Now apply the bonus: note that we find the attacking side by extracting
|
||||||
// the sign of the endgame value, and that we carefully cap the bonus so
|
// the sign of the endgame value, and that we carefully cap the bonus so
|
||||||
|
|
|
@ -142,16 +142,16 @@ void MovePicker::score<QUIETS>() {
|
||||||
|
|
||||||
const HistoryStats& history = pos.this_thread()->history;
|
const HistoryStats& history = pos.this_thread()->history;
|
||||||
|
|
||||||
const CounterMoveStats* cmh = (ss-1)->counterMoves;
|
const CounterMoveStats& cmh = *(ss-1)->counterMoves;
|
||||||
const CounterMoveStats* fmh = (ss-2)->counterMoves;
|
const CounterMoveStats& fmh = *(ss-2)->counterMoves;
|
||||||
const CounterMoveStats* fmh2 = (ss-4)->counterMoves;
|
const CounterMoveStats& fm2 = *(ss-4)->counterMoves;
|
||||||
|
|
||||||
Color c = pos.side_to_move();
|
Color c = pos.side_to_move();
|
||||||
|
|
||||||
for (auto& m : *this)
|
for (auto& m : *this)
|
||||||
m.value = (*cmh)[pos.moved_piece(m)][to_sq(m)]
|
m.value = cmh[pos.moved_piece(m)][to_sq(m)]
|
||||||
+ (*fmh)[pos.moved_piece(m)][to_sq(m)]
|
+ fmh[pos.moved_piece(m)][to_sq(m)]
|
||||||
+ (*fmh2)[pos.moved_piece(m)][to_sq(m)]
|
+ fm2[pos.moved_piece(m)][to_sq(m)]
|
||||||
+ history.get(c, m);
|
+ history.get(c, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,10 @@ namespace {
|
||||||
// Different node types, used as a template parameter
|
// Different node types, used as a template parameter
|
||||||
enum NodeType { NonPV, PV };
|
enum NodeType { NonPV, PV };
|
||||||
|
|
||||||
|
// Sizes and phases of the skip-blocks, used for distributing search depths across the threads
|
||||||
|
const int skipSize[] = { 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 };
|
||||||
|
const int skipPhase[] = { 0, 1, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||||
|
|
||||||
// Razoring and futility margin based on depth
|
// Razoring and futility margin based on depth
|
||||||
const int razor_margin[4] = { 483, 570, 603, 554 };
|
const int razor_margin[4] = { 483, 570, 603, 554 };
|
||||||
Value futility_margin(Depth d) { return Value(150 * d / ONE_PLY); }
|
Value futility_margin(Depth d) { return Value(150 * d / ONE_PLY); }
|
||||||
|
@ -308,13 +312,10 @@ void MainThread::search() {
|
||||||
std::cout << sync_endl;
|
std::cout << sync_endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sizes and phases of the skip-blocks, used for distributing search depths across the threads.
|
|
||||||
static int skipsize[20] = {1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
|
|
||||||
static int phase [20] = {0, 1, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7};
|
|
||||||
|
|
||||||
// Thread::search() is the main iterative deepening loop. It calls search()
|
/// Thread::search() is the main iterative deepening loop. It calls search()
|
||||||
// repeatedly with increasing depth until the allocated thinking time has been
|
/// repeatedly with increasing depth until the allocated thinking time has been
|
||||||
// consumed, the user stops the search, or the maximum search depth is reached.
|
/// consumed, the user stops the search, or the maximum search depth is reached.
|
||||||
|
|
||||||
void Thread::search() {
|
void Thread::search() {
|
||||||
|
|
||||||
|
@ -324,8 +325,8 @@ void Thread::search() {
|
||||||
MainThread* mainThread = (this == Threads.main() ? Threads.main() : nullptr);
|
MainThread* mainThread = (this == Threads.main() ? Threads.main() : nullptr);
|
||||||
|
|
||||||
std::memset(ss-4, 0, 7 * sizeof(Stack));
|
std::memset(ss-4, 0, 7 * sizeof(Stack));
|
||||||
for(int i = -4; i < 0; i++)
|
for(int i = 4; i > 0; i--)
|
||||||
(ss+i)->counterMoves = &this->counterMoveHistory[NO_PIECE][0]; // use as sentinel.
|
(ss-i)->counterMoves = &this->counterMoveHistory[NO_PIECE][0]; // Use as sentinel
|
||||||
|
|
||||||
bestValue = delta = alpha = -VALUE_INFINITE;
|
bestValue = delta = alpha = -VALUE_INFINITE;
|
||||||
beta = VALUE_INFINITE;
|
beta = VALUE_INFINITE;
|
||||||
|
@ -350,16 +351,18 @@ void Thread::search() {
|
||||||
|
|
||||||
multiPV = std::min(multiPV, rootMoves.size());
|
multiPV = std::min(multiPV, rootMoves.size());
|
||||||
|
|
||||||
int hIdx = (idx - 1) % 20; // helper index, cycle after 20 threads
|
|
||||||
|
|
||||||
// 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 += ONE_PLY) < DEPTH_MAX
|
while ( (rootDepth += ONE_PLY) < DEPTH_MAX
|
||||||
&& !Signals.stop
|
&& !Signals.stop
|
||||||
&& (!Limits.depth || Threads.main()->rootDepth / ONE_PLY <= Limits.depth))
|
&& (!Limits.depth || Threads.main()->rootDepth / ONE_PLY <= Limits.depth))
|
||||||
{
|
{
|
||||||
// skip half of the plies in blocks depending on game ply and helper index.
|
// Distribute search depths across the threads
|
||||||
if (idx && ((rootDepth / ONE_PLY + rootPos.game_ply() + phase[hIdx]) / skipsize[hIdx]) % 2)
|
if (idx)
|
||||||
|
{
|
||||||
|
int i = (idx - 1) % 20;
|
||||||
|
if (((rootDepth / ONE_PLY + rootPos.game_ply() + skipPhase[i]) / skipSize[i]) % 2)
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Age out PV variability metric
|
// Age out PV variability metric
|
||||||
if (mainThread)
|
if (mainThread)
|
||||||
|
@ -806,12 +809,12 @@ namespace {
|
||||||
|
|
||||||
moves_loop: // When in check search starts from here
|
moves_loop: // When in check search starts from here
|
||||||
|
|
||||||
const CounterMoveStats* cmh = (ss-1)->counterMoves;
|
const CounterMoveStats& cmh = *(ss-1)->counterMoves;
|
||||||
const CounterMoveStats* fmh = (ss-2)->counterMoves;
|
const CounterMoveStats& fmh = *(ss-2)->counterMoves;
|
||||||
const CounterMoveStats* fmh2 = (ss-4)->counterMoves;
|
const CounterMoveStats& fm2 = *(ss-4)->counterMoves;
|
||||||
const bool cm_ok = is_ok((ss-1)->currentMove);
|
const bool cm_ok = is_ok((ss-1)->currentMove);
|
||||||
const bool fm_ok = is_ok((ss-2)->currentMove);
|
const bool fm_ok = is_ok((ss-2)->currentMove);
|
||||||
const bool fm2_ok = is_ok((ss-4)->currentMove);
|
const bool f2_ok = is_ok((ss-4)->currentMove);
|
||||||
|
|
||||||
MovePicker mp(pos, ttMove, depth, ss);
|
MovePicker mp(pos, ttMove, depth, ss);
|
||||||
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
|
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
|
||||||
|
@ -911,9 +914,9 @@ moves_loop: // When in check search starts from here
|
||||||
|
|
||||||
// Countermoves based pruning
|
// Countermoves based pruning
|
||||||
if ( lmrDepth < 3
|
if ( lmrDepth < 3
|
||||||
&& (((*cmh )[moved_piece][to_sq(move)] < VALUE_ZERO) || !cm_ok)
|
&& ((cmh[moved_piece][to_sq(move)] < VALUE_ZERO) || !cm_ok)
|
||||||
&& (((*fmh )[moved_piece][to_sq(move)] < VALUE_ZERO) || !fm_ok)
|
&& ((fmh[moved_piece][to_sq(move)] < VALUE_ZERO) || !fm_ok)
|
||||||
&& (((*fmh2)[moved_piece][to_sq(move)] < VALUE_ZERO) || !fm2_ok || (cm_ok && fm_ok)))
|
&& ((fm2[moved_piece][to_sq(move)] < VALUE_ZERO) || !f2_ok || (cm_ok && fm_ok)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Futility pruning: parent node
|
// Futility pruning: parent node
|
||||||
|
@ -973,9 +976,9 @@ moves_loop: // When in check search starts from here
|
||||||
&& !pos.see_ge(make_move(to_sq(move), from_sq(move)), VALUE_ZERO))
|
&& !pos.see_ge(make_move(to_sq(move), from_sq(move)), VALUE_ZERO))
|
||||||
r -= 2 * ONE_PLY;
|
r -= 2 * ONE_PLY;
|
||||||
|
|
||||||
ss->history = (*cmh )[moved_piece][to_sq(move)]
|
ss->history = cmh[moved_piece][to_sq(move)]
|
||||||
+ (*fmh )[moved_piece][to_sq(move)]
|
+ fmh[moved_piece][to_sq(move)]
|
||||||
+ (*fmh2)[moved_piece][to_sq(move)]
|
+ fm2[moved_piece][to_sq(move)]
|
||||||
+ thisThread->history.get(~pos.side_to_move(), move)
|
+ thisThread->history.get(~pos.side_to_move(), move)
|
||||||
- 4000; // Correction factor
|
- 4000; // Correction factor
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue