2008-08-31 23:59:13 -06:00
|
|
|
/*
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
|
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
2016-01-02 02:43:25 -07:00
|
|
|
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
|
|
Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is free software: you can redistribute it and/or modify
|
2008-08-31 23:59:13 -06:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2008-09-03 15:33:49 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is distributed in the hope that it will be useful,
|
2008-08-31 23:59:13 -06:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2008-09-03 15:33:49 -06:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-12-12 09:55:20 -07:00
|
|
|
#include <algorithm>
|
2008-08-31 23:59:13 -06:00
|
|
|
#include <cassert>
|
2010-01-19 03:48:22 -07:00
|
|
|
#include <cmath>
|
2014-12-30 02:31:50 -07:00
|
|
|
#include <cstring> // For std::memset
|
2011-12-25 01:04:28 -07:00
|
|
|
#include <iostream>
|
2008-08-31 23:59:13 -06:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "evaluate.h"
|
2014-12-08 00:23:09 -07:00
|
|
|
#include "misc.h"
|
2009-06-11 07:11:08 -06:00
|
|
|
#include "movegen.h"
|
2008-08-31 23:59:13 -06:00
|
|
|
#include "movepick.h"
|
2016-09-17 00:19:06 -06:00
|
|
|
#include "position.h"
|
2008-08-31 23:59:13 -06:00
|
|
|
#include "search.h"
|
2010-07-11 10:23:50 -06:00
|
|
|
#include "timeman.h"
|
2008-08-31 23:59:13 -06:00
|
|
|
#include "thread.h"
|
|
|
|
#include "tt.h"
|
2014-10-26 00:09:19 -06:00
|
|
|
#include "uci.h"
|
2015-01-18 00:05:05 -07:00
|
|
|
#include "syzygy/tbprobe.h"
|
2014-11-25 16:45:28 -07:00
|
|
|
|
2011-11-26 04:07:35 -07:00
|
|
|
namespace Search {
|
|
|
|
|
Use atomics instead of volatile
Rely on well defined behaviour for message passing, instead of volatile. Three
versions have been tested, to make sure this wouldn't cause a slowdown on any
platform.
v1: Sequentially consistent atomics
No mesurable regression, despite the extra memory barriers on x86. Even with 15
threads and extreme time pressure, both acting as a magnifying glass:
threads=15, tc=2+0.02
ELO: 2.59 +-3.4 (95%) LOS: 93.3%
Total: 18132 W: 4113 L: 3978 D: 10041
threads=7, tc=2+0.02
ELO: -1.64 +-3.6 (95%) LOS: 18.8%
Total: 16914 W: 4053 L: 4133 D: 8728
v2: Acquire/Release semantics
This version generates no extra barriers for x86 (on the hot path). As expected,
no regression either, under the same conditions:
threads=15, tc=2+0.02
ELO: 2.85 +-3.3 (95%) LOS: 95.4%
Total: 19661 W: 4640 L: 4479 D: 10542
threads=7, tc=2+0.02
ELO: 0.23 +-3.5 (95%) LOS: 55.1%
Total: 18108 W: 4326 L: 4314 D: 9468
As suggested by Joona, another test at LTC:
threads=15, tc=20+0.05
ELO: 0.64 +-2.6 (95%) LOS: 68.3%
Total: 20000 W: 3053 L: 3016 D: 13931
v3: Final version: SeqCst/Relaxed
threads=15, tc=10+0.1
ELO: 0.87 +-3.9 (95%) LOS: 67.1%
Total: 9541 W: 1478 L: 1454 D: 6609
Resolves #474
2015-10-24 15:50:51 -06:00
|
|
|
SignalsType Signals;
|
2011-11-26 04:07:35 -07:00
|
|
|
LimitsType Limits;
|
2014-11-30 04:14:14 -07:00
|
|
|
}
|
|
|
|
|
2015-01-18 00:05:05 -07:00
|
|
|
namespace Tablebases {
|
|
|
|
|
|
|
|
int Cardinality;
|
|
|
|
uint64_t Hits;
|
|
|
|
bool RootInTB;
|
|
|
|
bool UseRule50;
|
|
|
|
Depth ProbeDepth;
|
|
|
|
Value Score;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace TB = Tablebases;
|
|
|
|
|
2011-12-04 03:46:31 -07:00
|
|
|
using std::string;
|
2012-03-06 02:09:37 -07:00
|
|
|
using Eval::evaluate;
|
2011-12-04 03:46:31 -07:00
|
|
|
using namespace Search;
|
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
namespace {
|
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
// Different node types, used as a template parameter
|
2016-01-18 15:20:16 -07:00
|
|
|
enum NodeType { NonPV, PV };
|
2010-11-08 01:44:28 -07:00
|
|
|
|
2015-01-31 02:43:47 -07:00
|
|
|
// Razoring and futility margin based on depth
|
2015-10-23 23:27:24 -06:00
|
|
|
const int razor_margin[4] = { 483, 570, 603, 554 };
|
2016-08-19 04:17:38 -06:00
|
|
|
Value futility_margin(Depth d) { return Value(150 * d / ONE_PLY); }
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2015-01-31 02:43:47 -07:00
|
|
|
// Futility and reductions lookup tables, initialized at startup
|
2016-08-19 04:17:38 -06:00
|
|
|
int FutilityMoveCounts[2][16]; // [improving][depth]
|
|
|
|
int Reductions[2][2][64][64]; // [pv][improving][depth][moveNumber]
|
2010-02-25 09:27:27 -07:00
|
|
|
|
Retire FORCE_INLINE
No speed regression on my machine (i7-3770k, gcc 4.9.1, linux 3.16):
stat test master diff
mean 2,482,415 2,474,987 7,906
stdev 4,603 5,644 2,497
speedup 0.32%
P(speedup>0) 100.0%
Fishtest 9+0.03:
ELO: 0.26 +-1.8 (95%) LOS: 61.2%
Total: 60000 W: 12437 L: 12392 D: 35171
No functional change.
Resolves #334
2015-04-15 14:21:45 -06:00
|
|
|
template <bool PvNode> Depth reduction(bool i, Depth d, int mn) {
|
2016-08-19 04:17:38 -06:00
|
|
|
return Reductions[PvNode][i][std::min(d / ONE_PLY, 63)][std::min(mn, 63)] * ONE_PLY;
|
2011-04-24 01:31:47 -06:00
|
|
|
}
|
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
// Skill structure is used to implement strength limit
|
2015-01-31 02:43:47 -07:00
|
|
|
struct Skill {
|
|
|
|
Skill(int l) : level(l) {}
|
|
|
|
bool enabled() const { return level < 20; }
|
|
|
|
bool time_to_pick(Depth depth) const { return depth / ONE_PLY == 1 + level; }
|
|
|
|
Move best_move(size_t multiPV) { return best ? best : pick_best(multiPV); }
|
|
|
|
Move pick_best(size_t multiPV);
|
2010-02-07 01:53:15 -07:00
|
|
|
|
2015-01-31 02:43:47 -07:00
|
|
|
int level;
|
|
|
|
Move best = MOVE_NONE;
|
|
|
|
};
|
2010-02-07 01:53:15 -07:00
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
// EasyMoveManager structure is used to detect an 'easy move'. When the PV is
|
|
|
|
// stable across multiple search iterations, we can quickly return the best move.
|
2015-03-18 01:12:59 -06:00
|
|
|
struct EasyMoveManager {
|
2015-03-12 13:49:30 -06:00
|
|
|
|
2015-03-18 01:12:59 -06:00
|
|
|
void clear() {
|
2015-03-12 13:49:30 -06:00
|
|
|
stableCnt = 0;
|
2015-03-18 01:12:59 -06:00
|
|
|
expectedPosKey = 0;
|
|
|
|
pv[0] = pv[1] = pv[2] = MOVE_NONE;
|
2015-03-12 13:49:30 -06:00
|
|
|
}
|
|
|
|
|
2015-03-18 01:12:59 -06:00
|
|
|
Move get(Key key) const {
|
|
|
|
return expectedPosKey == key ? pv[2] : MOVE_NONE;
|
|
|
|
}
|
2015-03-12 13:49:30 -06:00
|
|
|
|
2015-03-18 01:12:59 -06:00
|
|
|
void update(Position& pos, const std::vector<Move>& newPv) {
|
|
|
|
|
|
|
|
assert(newPv.size() >= 3);
|
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
// Keep track of how many times in a row the 3rd ply remains stable
|
2015-03-18 01:12:59 -06:00
|
|
|
stableCnt = (newPv[2] == pv[2]) ? stableCnt + 1 : 0;
|
|
|
|
|
|
|
|
if (!std::equal(newPv.begin(), newPv.begin() + 3, pv))
|
|
|
|
{
|
|
|
|
std::copy(newPv.begin(), newPv.begin() + 3, pv);
|
|
|
|
|
|
|
|
StateInfo st[2];
|
2016-07-03 02:35:44 -06:00
|
|
|
pos.do_move(newPv[0], st[0], pos.gives_check(newPv[0]));
|
|
|
|
pos.do_move(newPv[1], st[1], pos.gives_check(newPv[1]));
|
2015-03-18 01:12:59 -06:00
|
|
|
expectedPosKey = pos.key();
|
|
|
|
pos.undo_move(newPv[1]);
|
|
|
|
pos.undo_move(newPv[0]);
|
2015-03-12 13:49:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int stableCnt;
|
2015-03-18 01:12:59 -06:00
|
|
|
Key expectedPosKey;
|
|
|
|
Move pv[3];
|
|
|
|
};
|
2015-03-12 13:49:30 -06:00
|
|
|
|
2016-01-30 02:33:59 -07:00
|
|
|
// Set of rows with half bits set to 1 and half to 0. It is used to allocate
|
|
|
|
// the search depths across the threads.
|
|
|
|
typedef std::vector<int> Row;
|
|
|
|
|
|
|
|
const Row HalfDensity[] = {
|
|
|
|
{0, 1},
|
|
|
|
{1, 0},
|
|
|
|
{0, 0, 1, 1},
|
|
|
|
{0, 1, 1, 0},
|
|
|
|
{1, 1, 0, 0},
|
|
|
|
{1, 0, 0, 1},
|
|
|
|
{0, 0, 0, 1, 1, 1},
|
|
|
|
{0, 0, 1, 1, 1, 0},
|
|
|
|
{0, 1, 1, 1, 0, 0},
|
|
|
|
{1, 1, 1, 0, 0, 0},
|
|
|
|
{1, 1, 0, 0, 0, 1},
|
|
|
|
{1, 0, 0, 0, 1, 1},
|
|
|
|
{0, 0, 0, 0, 1, 1, 1, 1},
|
|
|
|
{0, 0, 0, 1, 1, 1, 1, 0},
|
|
|
|
{0, 0, 1, 1, 1, 1, 0 ,0},
|
|
|
|
{0, 1, 1, 1, 1, 0, 0 ,0},
|
|
|
|
{1, 1, 1, 1, 0, 0, 0 ,0},
|
|
|
|
{1, 1, 1, 0, 0, 0, 0 ,1},
|
|
|
|
{1, 1, 0, 0, 0, 0, 1 ,1},
|
|
|
|
{1, 0, 0, 0, 0, 1, 1 ,1},
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t HalfDensitySize = std::extent<decltype(HalfDensity)>::value;
|
|
|
|
|
2015-03-18 01:12:59 -06:00
|
|
|
EasyMoveManager EasyMove;
|
2012-10-21 02:41:23 -06:00
|
|
|
Value DrawValue[COLOR_NB];
|
2009-07-01 18:54:17 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
template <NodeType NT>
|
2013-06-09 01:43:04 -06:00
|
|
|
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode);
|
2010-05-08 02:54:51 -06:00
|
|
|
|
2012-11-01 07:49:54 -06:00
|
|
|
template <NodeType NT, bool InCheck>
|
2011-12-04 03:46:31 -07:00
|
|
|
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
|
2010-10-16 03:01:45 -06:00
|
|
|
|
2010-07-15 03:00:20 -06:00
|
|
|
Value value_to_tt(Value v, int ply);
|
|
|
|
Value value_from_tt(Value v, int ply);
|
2014-11-21 01:10:52 -07:00
|
|
|
void update_pv(Move* pv, Move move, Move* childPv);
|
2016-08-26 11:47:40 -06:00
|
|
|
void update_cm_stats(Stack* ss, Piece pc, Square s, Value bonus);
|
2016-08-24 08:52:05 -06:00
|
|
|
void update_stats(const Position& pos, Stack* ss, Move move, Move* quiets, int quietsCnt, Value bonus);
|
Get rid of timer thread
Unfortunately std::condition_variable::wait_for()
is not accurate in general case and the timer thread
can wake up also after tens or even hundreds of
millisecs after time has elapsded. CPU load, process
priorities, number of concurrent threads, even from
other processes, will have effect upon it.
Even official documentation says: "This function may
block for longer than timeout_duration due to scheduling
or resource contention delays."
So retire timer and use a polling scheme based on a
local thread counter that counts search() calls and
a small trick to keep polling frequency constant,
independently from the number of threads.
Tested for no regression at very fast TC 2+0.05 th 7:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 32969 W: 6720 L: 6620 D: 19629
TC 2+0.05 th 1:
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 7765 W: 1917 L: 1765 D: 4083
And at STC TC, both single thread
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 15587 W: 3036 L: 2905 D: 9646
And with 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 8149 W: 1367 L: 1227 D: 5555
bench: 8639247
2015-11-03 03:15:14 -07:00
|
|
|
void check_time();
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-01-16 15:40:06 -07:00
|
|
|
} // namespace
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
|
2011-12-14 04:12:28 -07:00
|
|
|
/// Search::init() is called during startup to initialize various lookup tables
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-11-26 04:07:35 -07:00
|
|
|
void Search::init() {
|
2010-06-01 14:28:45 -06:00
|
|
|
|
2016-02-28 06:28:22 -07:00
|
|
|
for (int imp = 0; imp <= 1; ++imp)
|
|
|
|
for (int d = 1; d < 64; ++d)
|
|
|
|
for (int mc = 1; mc < 64; ++mc)
|
|
|
|
{
|
|
|
|
double r = log(d) * log(mc) / 2;
|
|
|
|
if (r < 0.80)
|
|
|
|
continue;
|
|
|
|
|
2016-08-19 04:17:38 -06:00
|
|
|
Reductions[NonPV][imp][d][mc] = int(std::round(r));
|
|
|
|
Reductions[PV][imp][d][mc] = std::max(Reductions[NonPV][imp][d][mc] - 1, 0);
|
2016-03-13 01:35:03 -07:00
|
|
|
|
2016-02-28 06:28:22 -07:00
|
|
|
// Increase reduction for non-PV nodes when eval is not improving
|
2016-08-19 04:17:38 -06:00
|
|
|
if (!imp && Reductions[NonPV][imp][d][mc] >= 2)
|
|
|
|
Reductions[NonPV][imp][d][mc]++;
|
2016-02-28 06:28:22 -07:00
|
|
|
}
|
2010-06-01 14:28:45 -06:00
|
|
|
|
2014-11-08 17:45:27 -07:00
|
|
|
for (int d = 0; d < 16; ++d)
|
Increase pruning if evaluation is not improving
Add an additional set of margins to movecount pruning
to be used when static evaluation is getting worse
than previous move.
Here are the margins table with changing
depth (fm0 not improving, fm1 improving):
d: 0, fm0: 3, fm1: 3
d: 1, fm0: 4, fm1: 4
d: 2, fm0: 6, fm1: 6
d: 3, fm0: 7, fm1: 10
d: 4, fm0: 11, fm1: 15
d: 5, fm0: 15, fm1: 21
d: 6, fm0: 21, fm1: 29
d: 7, fm0: 27, fm1: 37
d: 8, fm0: 35, fm1: 47
d: 9, fm0: 42, fm1: 57
d: 10, fm0: 51, fm1: 68
d: 11, fm0: 60, fm1: 81
d: 12, fm0: 70, fm1: 94
d: 13, fm0: 81, fm1: 108
d: 14, fm0: 92, fm1: 123
d: 15, fm0: 104, fm1: 139
Good at both short TC
LLR: 2.97 (-2.94,2.94)
Total: 11502 W: 2503 L: 2361 D: 6638
And long TC
LLR: 2.98 (-2.94,2.94)
Total: 7189 W: 1421 L: 1277 D: 4491
bench: 4364793
2013-07-28 17:16:25 -06:00
|
|
|
{
|
2014-10-05 05:49:18 -06:00
|
|
|
FutilityMoveCounts[0][d] = int(2.4 + 0.773 * pow(d + 0.00, 1.8));
|
|
|
|
FutilityMoveCounts[1][d] = int(2.9 + 1.045 * pow(d + 0.49, 1.8));
|
Increase pruning if evaluation is not improving
Add an additional set of margins to movecount pruning
to be used when static evaluation is getting worse
than previous move.
Here are the margins table with changing
depth (fm0 not improving, fm1 improving):
d: 0, fm0: 3, fm1: 3
d: 1, fm0: 4, fm1: 4
d: 2, fm0: 6, fm1: 6
d: 3, fm0: 7, fm1: 10
d: 4, fm0: 11, fm1: 15
d: 5, fm0: 15, fm1: 21
d: 6, fm0: 21, fm1: 29
d: 7, fm0: 27, fm1: 37
d: 8, fm0: 35, fm1: 47
d: 9, fm0: 42, fm1: 57
d: 10, fm0: 51, fm1: 68
d: 11, fm0: 60, fm1: 81
d: 12, fm0: 70, fm1: 94
d: 13, fm0: 81, fm1: 108
d: 14, fm0: 92, fm1: 123
d: 15, fm0: 104, fm1: 139
Good at both short TC
LLR: 2.97 (-2.94,2.94)
Total: 11502 W: 2503 L: 2361 D: 6638
And long TC
LLR: 2.98 (-2.94,2.94)
Total: 7189 W: 1421 L: 1277 D: 4491
bench: 4364793
2013-07-28 17:16:25 -06:00
|
|
|
}
|
2010-06-01 14:28:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
/// Search::clear() resets search state to zero, to obtain reproducible results
|
2015-05-06 05:24:00 -06:00
|
|
|
|
2015-10-25 01:30:07 -06:00
|
|
|
void Search::clear() {
|
2015-05-06 05:24:00 -06:00
|
|
|
|
2015-05-09 03:09:06 -06:00
|
|
|
TT.clear();
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
|
|
|
|
for (Thread* th : Threads)
|
|
|
|
{
|
2015-10-23 23:27:24 -06:00
|
|
|
th->history.clear();
|
|
|
|
th->counterMoves.clear();
|
2016-07-25 07:53:18 -06:00
|
|
|
th->fromTo.clear();
|
2016-08-29 01:11:20 -06:00
|
|
|
th->counterMoveHistory.clear();
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
}
|
2016-01-03 07:00:56 -07:00
|
|
|
|
2016-01-16 01:03:56 -07:00
|
|
|
Threads.main()->previousScore = VALUE_INFINITE;
|
2015-05-06 05:24:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-14 04:12:28 -07:00
|
|
|
/// Search::perft() is our utility to verify move generation. All the leaf nodes
|
2016-01-16 14:34:29 -07:00
|
|
|
/// up to the given depth are generated and counted, and the sum is returned.
|
2014-08-08 02:59:28 -06:00
|
|
|
template<bool Root>
|
|
|
|
uint64_t Search::perft(Position& pos, Depth depth) {
|
2009-11-04 03:11:04 -07:00
|
|
|
|
2012-08-19 03:20:15 -06:00
|
|
|
StateInfo st;
|
2014-08-08 02:59:28 -06:00
|
|
|
uint64_t cnt, nodes = 0;
|
2014-09-29 06:08:56 -06:00
|
|
|
const bool leaf = (depth == 2 * ONE_PLY);
|
2012-08-19 03:20:15 -06:00
|
|
|
|
2015-01-31 10:39:51 -07:00
|
|
|
for (const auto& m : MoveList<LEGAL>(pos))
|
2011-04-03 02:19:08 -06:00
|
|
|
{
|
2014-08-08 02:59:28 -06:00
|
|
|
if (Root && depth <= ONE_PLY)
|
2014-08-09 03:33:02 -06:00
|
|
|
cnt = 1, nodes++;
|
2014-08-08 02:59:28 -06:00
|
|
|
else
|
|
|
|
{
|
2016-07-03 02:35:44 -06:00
|
|
|
pos.do_move(m, st, pos.gives_check(m));
|
2014-08-08 02:59:28 -06:00
|
|
|
cnt = leaf ? MoveList<LEGAL>(pos).size() : perft<false>(pos, depth - ONE_PLY);
|
|
|
|
nodes += cnt;
|
2015-01-31 10:39:51 -07:00
|
|
|
pos.undo_move(m);
|
2014-08-08 02:59:28 -06:00
|
|
|
}
|
|
|
|
if (Root)
|
2015-01-31 10:39:51 -07:00
|
|
|
sync_cout << UCI::move(m, pos.is_chess960()) << ": " << cnt << sync_endl;
|
2011-04-03 02:19:08 -06:00
|
|
|
}
|
2014-08-08 02:59:28 -06:00
|
|
|
return nodes;
|
2009-10-01 22:09:24 -06:00
|
|
|
}
|
|
|
|
|
2015-10-25 01:30:07 -06:00
|
|
|
template uint64_t Search::perft<true>(Position&, Depth);
|
2014-08-08 02:59:28 -06:00
|
|
|
|
2009-10-01 22:09:24 -06:00
|
|
|
|
2015-11-05 00:40:23 -07:00
|
|
|
/// MainThread::search() is called by the main thread when the program receives
|
2016-01-16 14:34:29 -07:00
|
|
|
/// the UCI 'go' command. It searches from the root position and outputs the "bestmove".
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2015-11-05 00:40:23 -07:00
|
|
|
void MainThread::search() {
|
2008-08-31 23:59:13 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
Color us = rootPos.side_to_move();
|
|
|
|
Time.init(Limits, us, rootPos.game_ply());
|
2011-11-06 05:13:54 -07:00
|
|
|
|
2014-12-07 16:53:33 -07:00
|
|
|
int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns
|
Add support for playing in 'nodes as time' mode
When running more games in parallel, or simply when running a game
with a background process, due to how OS scheduling works, there is no
guarantee that the CPU resources allocated evenly between the two
players. This introduces noise in the result that leads to unreliable
result and in the worst cases can even invalidate the result. For
instance in SF test framework we avoid running from clouds virtual
machines because are a known source of very unstable CPU speed.
To overcome this issue, without requiring changes to the GUI, the idea
is to use searched nodes instead of time, and to convert time to
available nodes upfront, at the beginning of the game.
When nodestime UCI option is set at a given nodes per milliseconds
(npmsec), at the beginning of the game (and only once), the engine
reads the available time to think, sent by the GUI with 'go wtime x'
UCI command. Then it translates time in available nodes (nodes =
npmsec * x), then feeds available nodes instead of time to the time
management logic and starts the search. During the search the engine
checks the searched nodes against the available ones in such a way
that all the time management logic still fully applies, and the game
mimics a real one played on real time. When the search finishes,
before returning best move, the total available nodes are updated,
subtracting the real searched nodes. After the first move, the time
information sent by the GUI is ignored, and the engine fully relies on
the updated total available nodes to feed time management.
To avoid time losses, the speed of the engine (npms) must be set to a
value lower than real speed so that if the real TC is for instance 30
secs, and npms is half of the real speed, the game will last on
average 15 secs, so much less than the TC limit, providing for a
safety 'time buffer'.
There are 2 main limitations with this mode.
1. Engine speed should be the same for both players, and this limits
the approach to mainly parameter tuning patches.
2. Because npms is fixed while, in real engines, the speed increases
toward endgame, this introduces an artifact that is equivalent to an
altered time management. Namely it is like the time management gives
less available time than what should be in standard case.
May be the second limitation could be mitigated in a future with a
smarter 'dynamic npms' approach.
Tests shows that the standard deviation of the results with 'nodestime'
is lower than in standard TC, as is expected because now all the introduced
noise due the random speed variability of the engines during the game is
fully removed.
Original NIT idea by Michael Hoffman that shows how to play in NIT mode
without requiring changes to the GUI. This implementation goes a bit
further, the key difference is that we read TC from GUI only once upfront
instead of re-reading after every move as in Michael's implementation.
No functional change.
2015-03-22 14:15:44 -06:00
|
|
|
DrawValue[ us] = VALUE_DRAW - Value(contempt);
|
|
|
|
DrawValue[~us] = VALUE_DRAW + Value(contempt);
|
2014-03-01 04:10:42 -07:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
if (rootMoves.empty())
|
2008-10-30 04:35:44 -06:00
|
|
|
{
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
rootMoves.push_back(RootMove(MOVE_NONE));
|
2012-08-29 05:28:59 -06:00
|
|
|
sync_cout << "info depth 0 score "
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
<< UCI::value(rootPos.checkers() ? -VALUE_MATE : VALUE_DRAW)
|
2012-10-24 06:37:52 -06:00
|
|
|
<< sync_endl;
|
2012-01-14 03:45:54 -07:00
|
|
|
}
|
2014-11-10 06:46:05 -07:00
|
|
|
else
|
|
|
|
{
|
2015-01-18 00:00:50 -07:00
|
|
|
for (Thread* th : Threads)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
if (th != this)
|
2015-11-20 23:48:50 -07:00
|
|
|
th->start_searching();
|
2012-01-14 03:45:54 -07:00
|
|
|
|
2015-11-05 00:40:23 -07:00
|
|
|
Thread::search(); // Let's start searching!
|
2014-11-10 06:46:05 -07:00
|
|
|
}
|
2013-05-03 02:25:25 -06:00
|
|
|
|
Add support for playing in 'nodes as time' mode
When running more games in parallel, or simply when running a game
with a background process, due to how OS scheduling works, there is no
guarantee that the CPU resources allocated evenly between the two
players. This introduces noise in the result that leads to unreliable
result and in the worst cases can even invalidate the result. For
instance in SF test framework we avoid running from clouds virtual
machines because are a known source of very unstable CPU speed.
To overcome this issue, without requiring changes to the GUI, the idea
is to use searched nodes instead of time, and to convert time to
available nodes upfront, at the beginning of the game.
When nodestime UCI option is set at a given nodes per milliseconds
(npmsec), at the beginning of the game (and only once), the engine
reads the available time to think, sent by the GUI with 'go wtime x'
UCI command. Then it translates time in available nodes (nodes =
npmsec * x), then feeds available nodes instead of time to the time
management logic and starts the search. During the search the engine
checks the searched nodes against the available ones in such a way
that all the time management logic still fully applies, and the game
mimics a real one played on real time. When the search finishes,
before returning best move, the total available nodes are updated,
subtracting the real searched nodes. After the first move, the time
information sent by the GUI is ignored, and the engine fully relies on
the updated total available nodes to feed time management.
To avoid time losses, the speed of the engine (npms) must be set to a
value lower than real speed so that if the real TC is for instance 30
secs, and npms is half of the real speed, the game will last on
average 15 secs, so much less than the TC limit, providing for a
safety 'time buffer'.
There are 2 main limitations with this mode.
1. Engine speed should be the same for both players, and this limits
the approach to mainly parameter tuning patches.
2. Because npms is fixed while, in real engines, the speed increases
toward endgame, this introduces an artifact that is equivalent to an
altered time management. Namely it is like the time management gives
less available time than what should be in standard case.
May be the second limitation could be mitigated in a future with a
smarter 'dynamic npms' approach.
Tests shows that the standard deviation of the results with 'nodestime'
is lower than in standard TC, as is expected because now all the introduced
noise due the random speed variability of the engines during the game is
fully removed.
Original NIT idea by Michael Hoffman that shows how to play in NIT mode
without requiring changes to the GUI. This implementation goes a bit
further, the key difference is that we read TC from GUI only once upfront
instead of re-reading after every move as in Michael's implementation.
No functional change.
2015-03-22 14:15:44 -06:00
|
|
|
// When playing in 'nodes as time' mode, subtract the searched nodes from
|
2016-01-16 14:34:29 -07:00
|
|
|
// the available ones before exiting.
|
Add support for playing in 'nodes as time' mode
When running more games in parallel, or simply when running a game
with a background process, due to how OS scheduling works, there is no
guarantee that the CPU resources allocated evenly between the two
players. This introduces noise in the result that leads to unreliable
result and in the worst cases can even invalidate the result. For
instance in SF test framework we avoid running from clouds virtual
machines because are a known source of very unstable CPU speed.
To overcome this issue, without requiring changes to the GUI, the idea
is to use searched nodes instead of time, and to convert time to
available nodes upfront, at the beginning of the game.
When nodestime UCI option is set at a given nodes per milliseconds
(npmsec), at the beginning of the game (and only once), the engine
reads the available time to think, sent by the GUI with 'go wtime x'
UCI command. Then it translates time in available nodes (nodes =
npmsec * x), then feeds available nodes instead of time to the time
management logic and starts the search. During the search the engine
checks the searched nodes against the available ones in such a way
that all the time management logic still fully applies, and the game
mimics a real one played on real time. When the search finishes,
before returning best move, the total available nodes are updated,
subtracting the real searched nodes. After the first move, the time
information sent by the GUI is ignored, and the engine fully relies on
the updated total available nodes to feed time management.
To avoid time losses, the speed of the engine (npms) must be set to a
value lower than real speed so that if the real TC is for instance 30
secs, and npms is half of the real speed, the game will last on
average 15 secs, so much less than the TC limit, providing for a
safety 'time buffer'.
There are 2 main limitations with this mode.
1. Engine speed should be the same for both players, and this limits
the approach to mainly parameter tuning patches.
2. Because npms is fixed while, in real engines, the speed increases
toward endgame, this introduces an artifact that is equivalent to an
altered time management. Namely it is like the time management gives
less available time than what should be in standard case.
May be the second limitation could be mitigated in a future with a
smarter 'dynamic npms' approach.
Tests shows that the standard deviation of the results with 'nodestime'
is lower than in standard TC, as is expected because now all the introduced
noise due the random speed variability of the engines during the game is
fully removed.
Original NIT idea by Michael Hoffman that shows how to play in NIT mode
without requiring changes to the GUI. This implementation goes a bit
further, the key difference is that we read TC from GUI only once upfront
instead of re-reading after every move as in Michael's implementation.
No functional change.
2015-03-22 14:15:44 -06:00
|
|
|
if (Limits.npmsec)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
Time.availableNodes += Limits.inc[us] - Threads.nodes_searched();
|
Add support for playing in 'nodes as time' mode
When running more games in parallel, or simply when running a game
with a background process, due to how OS scheduling works, there is no
guarantee that the CPU resources allocated evenly between the two
players. This introduces noise in the result that leads to unreliable
result and in the worst cases can even invalidate the result. For
instance in SF test framework we avoid running from clouds virtual
machines because are a known source of very unstable CPU speed.
To overcome this issue, without requiring changes to the GUI, the idea
is to use searched nodes instead of time, and to convert time to
available nodes upfront, at the beginning of the game.
When nodestime UCI option is set at a given nodes per milliseconds
(npmsec), at the beginning of the game (and only once), the engine
reads the available time to think, sent by the GUI with 'go wtime x'
UCI command. Then it translates time in available nodes (nodes =
npmsec * x), then feeds available nodes instead of time to the time
management logic and starts the search. During the search the engine
checks the searched nodes against the available ones in such a way
that all the time management logic still fully applies, and the game
mimics a real one played on real time. When the search finishes,
before returning best move, the total available nodes are updated,
subtracting the real searched nodes. After the first move, the time
information sent by the GUI is ignored, and the engine fully relies on
the updated total available nodes to feed time management.
To avoid time losses, the speed of the engine (npms) must be set to a
value lower than real speed so that if the real TC is for instance 30
secs, and npms is half of the real speed, the game will last on
average 15 secs, so much less than the TC limit, providing for a
safety 'time buffer'.
There are 2 main limitations with this mode.
1. Engine speed should be the same for both players, and this limits
the approach to mainly parameter tuning patches.
2. Because npms is fixed while, in real engines, the speed increases
toward endgame, this introduces an artifact that is equivalent to an
altered time management. Namely it is like the time management gives
less available time than what should be in standard case.
May be the second limitation could be mitigated in a future with a
smarter 'dynamic npms' approach.
Tests shows that the standard deviation of the results with 'nodestime'
is lower than in standard TC, as is expected because now all the introduced
noise due the random speed variability of the engines during the game is
fully removed.
Original NIT idea by Michael Hoffman that shows how to play in NIT mode
without requiring changes to the GUI. This implementation goes a bit
further, the key difference is that we read TC from GUI only once upfront
instead of re-reading after every move as in Michael's implementation.
No functional change.
2015-03-22 14:15:44 -06:00
|
|
|
|
2013-12-02 11:04:09 -07:00
|
|
|
// When we reach the maximum depth, we can arrive here without a raise of
|
|
|
|
// Signals.stop. However, if we are pondering or in an infinite search,
|
|
|
|
// the UCI protocol states that we shouldn't print the best move before the
|
|
|
|
// GUI sends a "stop" or "ponderhit" command. We therefore simply wait here
|
|
|
|
// until the GUI sends one of those commands (which also raises Signals.stop).
|
2011-11-26 04:07:35 -07:00
|
|
|
if (!Signals.stop && (Limits.ponder || Limits.infinite))
|
2013-01-13 06:15:19 -07:00
|
|
|
{
|
|
|
|
Signals.stopOnPonderhit = true;
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
wait(Signals.stop);
|
2013-01-13 06:15:19 -07:00
|
|
|
}
|
2010-12-30 08:18:22 -07:00
|
|
|
|
2015-11-09 01:50:02 -07:00
|
|
|
// Stop the threads if not already stopped
|
|
|
|
Signals.stop = true;
|
|
|
|
|
|
|
|
// Wait until all threads have finished
|
|
|
|
for (Thread* th : Threads)
|
|
|
|
if (th != this)
|
2015-11-20 23:48:50 -07:00
|
|
|
th->wait_for_search_finished();
|
2015-11-09 01:50:02 -07:00
|
|
|
|
2015-12-23 02:07:54 -07:00
|
|
|
// Check if there are threads with a better score than main thread
|
2015-11-02 02:58:18 -07:00
|
|
|
Thread* bestThread = this;
|
2015-12-23 02:07:54 -07:00
|
|
|
if ( !this->easyMovePlayed
|
|
|
|
&& Options["MultiPV"] == 1
|
2016-04-30 02:56:00 -06:00
|
|
|
&& !Limits.depth
|
2016-04-08 09:20:47 -06:00
|
|
|
&& !Skill(Options["Skill Level"]).enabled()
|
|
|
|
&& rootMoves[0].pv[0] != MOVE_NONE)
|
2015-12-23 02:07:54 -07:00
|
|
|
{
|
2015-12-07 14:51:43 -07:00
|
|
|
for (Thread* th : Threads)
|
|
|
|
if ( th->completedDepth > bestThread->completedDepth
|
|
|
|
&& th->rootMoves[0].score > bestThread->rootMoves[0].score)
|
2015-12-23 02:07:54 -07:00
|
|
|
bestThread = th;
|
|
|
|
}
|
2015-11-02 02:58:18 -07:00
|
|
|
|
2016-01-16 01:03:56 -07:00
|
|
|
previousScore = bestThread->rootMoves[0].score;
|
2016-01-03 07:00:56 -07:00
|
|
|
|
2015-12-23 02:07:54 -07:00
|
|
|
// Send new PV when needed
|
2015-11-02 02:58:18 -07:00
|
|
|
if (bestThread != this)
|
|
|
|
sync_cout << UCI::pv(bestThread->rootPos, bestThread->completedDepth, -VALUE_INFINITE, VALUE_INFINITE) << sync_endl;
|
2014-11-23 17:53:00 -07:00
|
|
|
|
2015-11-02 02:58:18 -07:00
|
|
|
sync_cout << "bestmove " << UCI::move(bestThread->rootMoves[0].pv[0], rootPos.is_chess960());
|
|
|
|
|
|
|
|
if (bestThread->rootMoves[0].pv.size() > 1 || bestThread->rootMoves[0].extract_ponder_from_tt(rootPos))
|
|
|
|
std::cout << " ponder " << UCI::move(bestThread->rootMoves[0].pv[1], rootPos.is_chess960());
|
2014-11-23 17:53:00 -07:00
|
|
|
|
|
|
|
std::cout << sync_endl;
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// Thread::search() is the main iterative deepening loop. It calls search()
|
|
|
|
// repeatedly with increasing depth until the allocated thinking time has been
|
2016-01-16 14:34:29 -07:00
|
|
|
// consumed, the user stops the search, or the maximum search depth is reached.
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2015-11-05 00:40:23 -07:00
|
|
|
void Thread::search() {
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2016-04-17 08:14:07 -06:00
|
|
|
Stack stack[MAX_PLY+7], *ss = stack+5; // To allow referencing (ss-5) and (ss+2)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
Value bestValue, alpha, beta, delta;
|
|
|
|
Move easyMove = MOVE_NONE;
|
2015-12-23 02:07:54 -07:00
|
|
|
MainThread* mainThread = (this == Threads.main() ? Threads.main() : nullptr);
|
2008-10-30 04:35:44 -06:00
|
|
|
|
2016-04-17 08:14:07 -06:00
|
|
|
std::memset(ss-5, 0, 8 * sizeof(Stack));
|
2011-01-17 02:44:00 -07:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
bestValue = delta = alpha = -VALUE_INFINITE;
|
|
|
|
beta = VALUE_INFINITE;
|
2015-11-02 02:58:18 -07:00
|
|
|
completedDepth = DEPTH_ZERO;
|
2015-03-12 13:49:30 -06:00
|
|
|
|
2015-12-23 02:07:54 -07:00
|
|
|
if (mainThread)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
{
|
|
|
|
easyMove = EasyMove.get(rootPos.key());
|
|
|
|
EasyMove.clear();
|
2015-12-23 02:07:54 -07:00
|
|
|
mainThread->easyMovePlayed = mainThread->failedLow = false;
|
|
|
|
mainThread->bestMoveChanges = 0;
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
TT.new_search();
|
|
|
|
}
|
2013-07-03 10:58:49 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
size_t multiPV = Options["MultiPV"];
|
|
|
|
Skill skill(Options["Skill Level"]);
|
2013-07-03 10:58:49 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// When playing with strength handicap enable MultiPV search that we will
|
|
|
|
// use behind the scenes to retrieve a set of possible moves.
|
|
|
|
if (skill.enabled())
|
|
|
|
multiPV = std::max(multiPV, (size_t)4);
|
2015-03-29 01:24:17 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
multiPV = std::min(multiPV, rootMoves.size());
|
2012-10-24 04:05:20 -06:00
|
|
|
|
2016-08-19 04:17:38 -06:00
|
|
|
// Iterative deepening loop until requested to stop or the target depth is reached
|
|
|
|
while ( (rootDepth += ONE_PLY) < DEPTH_MAX
|
|
|
|
&& !Signals.stop
|
|
|
|
&& (!Limits.depth || Threads.main()->rootDepth / ONE_PLY <= Limits.depth))
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
{
|
2016-01-16 14:34:29 -07:00
|
|
|
// Set up the new depths for the helper threads skipping on average every
|
2016-01-18 02:41:24 -07:00
|
|
|
// 2nd ply (using a half-density matrix).
|
2015-12-23 02:07:54 -07:00
|
|
|
if (!mainThread)
|
Distinct iteration paths for Lazy SMP threads
STC 5+0.1, threads 7
LLR: 2.96 (-2.94,2.94) [0.00,5.00]
Total: 6026 W: 1047 L: 901 D: 4078
LTC: 20+0.2, threads 7
LLR: 2.95 (-2.94,2.94) [0.00,5.00]
Total: 19739 W: 2910 L: 2721 D: 14108
STC 5+0.1, threads 20
LLR: 2.95 (-2.94,2.94) [0.00,5.00]
Total: 2493 W: 462 L: 331 D: 1700
LTC 30+0.3, threads 20
ELO: 8.86 +-3.7 (95%) LOS: 100.0%
Total: 8000 W: 1076 L: 872 D: 6052
Bench: 8012530
Resolves #525
2015-12-18 14:55:07 -07:00
|
|
|
{
|
2016-01-30 02:33:59 -07:00
|
|
|
const Row& row = HalfDensity[(idx - 1) % HalfDensitySize];
|
2016-08-19 04:17:38 -06:00
|
|
|
if (row[(rootDepth / ONE_PLY + rootPos.game_ply()) % row.size()])
|
2016-01-18 02:41:24 -07:00
|
|
|
continue;
|
Distinct iteration paths for Lazy SMP threads
STC 5+0.1, threads 7
LLR: 2.96 (-2.94,2.94) [0.00,5.00]
Total: 6026 W: 1047 L: 901 D: 4078
LTC: 20+0.2, threads 7
LLR: 2.95 (-2.94,2.94) [0.00,5.00]
Total: 19739 W: 2910 L: 2721 D: 14108
STC 5+0.1, threads 20
LLR: 2.95 (-2.94,2.94) [0.00,5.00]
Total: 2493 W: 462 L: 331 D: 1700
LTC 30+0.3, threads 20
ELO: 8.86 +-3.7 (95%) LOS: 100.0%
Total: 8000 W: 1076 L: 872 D: 6052
Bench: 8012530
Resolves #525
2015-12-18 14:55:07 -07:00
|
|
|
}
|
2015-01-25 03:07:43 -07:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// Age out PV variability metric
|
2015-12-23 02:07:54 -07:00
|
|
|
if (mainThread)
|
|
|
|
mainThread->bestMoveChanges *= 0.505, mainThread->failedLow = false;
|
2012-10-24 04:05:20 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// Save the last iteration's scores before first PV line is searched and
|
|
|
|
// all the move scores except the (new) PV are set to -VALUE_INFINITE.
|
|
|
|
for (RootMove& rm : rootMoves)
|
|
|
|
rm.previousScore = rm.score;
|
2013-08-24 10:29:44 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// MultiPV loop. We perform a full root search for each PV line
|
|
|
|
for (PVIdx = 0; PVIdx < multiPV && !Signals.stop; ++PVIdx)
|
|
|
|
{
|
|
|
|
// Reset aspiration window starting size
|
2015-10-23 23:27:24 -06:00
|
|
|
if (rootDepth >= 5 * ONE_PLY)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
{
|
2015-10-20 20:46:06 -06:00
|
|
|
delta = Value(18);
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
alpha = std::max(rootMoves[PVIdx].previousScore - delta,-VALUE_INFINITE);
|
|
|
|
beta = std::min(rootMoves[PVIdx].previousScore + delta, VALUE_INFINITE);
|
|
|
|
}
|
2009-04-11 07:46:35 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// Start with a small aspiration window and, in the case of a fail
|
|
|
|
// high/low, re-search with a bigger window until we're not failing
|
|
|
|
// high/low anymore.
|
|
|
|
while (true)
|
|
|
|
{
|
2016-01-18 15:20:16 -07:00
|
|
|
bestValue = ::search<PV>(rootPos, ss, alpha, beta, rootDepth, false);
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
|
|
|
|
// Bring the best move to the front. It is critical that sorting
|
|
|
|
// is done with a stable algorithm because all the values but the
|
|
|
|
// first and eventually the new best one are set to -VALUE_INFINITE
|
|
|
|
// and we want to keep the same order for all the moves except the
|
|
|
|
// new PV that goes to the front. Note that in case of MultiPV
|
|
|
|
// search the already searched PV lines are preserved.
|
|
|
|
std::stable_sort(rootMoves.begin() + PVIdx, rootMoves.end());
|
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
// If search has been stopped, break immediately. Sorting and
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// writing PV back to TT is safe because RootMoves is still
|
2016-01-16 14:34:29 -07:00
|
|
|
// valid, although it refers to the previous iteration.
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
if (Signals.stop)
|
|
|
|
break;
|
2011-02-28 12:17:57 -07:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// When failing high/low give some update (without cluttering
|
|
|
|
// the UI) before a re-search.
|
2015-12-23 02:07:54 -07:00
|
|
|
if ( mainThread
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
&& multiPV == 1
|
|
|
|
&& (bestValue <= alpha || bestValue >= beta)
|
|
|
|
&& Time.elapsed() > 3000)
|
2015-10-23 23:27:24 -06:00
|
|
|
sync_cout << UCI::pv(rootPos, rootDepth, alpha, beta) << sync_endl;
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
|
|
|
|
// In case of failing low/high increase aspiration window and
|
|
|
|
// re-search, otherwise exit the loop.
|
|
|
|
if (bestValue <= alpha)
|
|
|
|
{
|
|
|
|
beta = (alpha + beta) / 2;
|
|
|
|
alpha = std::max(bestValue - delta, -VALUE_INFINITE);
|
2012-10-24 04:05:20 -06:00
|
|
|
|
2015-12-23 02:07:54 -07:00
|
|
|
if (mainThread)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
{
|
2015-12-23 02:07:54 -07:00
|
|
|
mainThread->failedLow = true;
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
Signals.stopOnPonderhit = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bestValue >= beta)
|
|
|
|
{
|
|
|
|
alpha = (alpha + beta) / 2;
|
|
|
|
beta = std::min(bestValue + delta, VALUE_INFINITE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
2013-02-03 03:14:21 -07:00
|
|
|
|
2015-10-20 20:46:06 -06:00
|
|
|
delta += delta / 4 + 5;
|
2014-11-10 06:46:05 -07:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
assert(alpha >= -VALUE_INFINITE && beta <= VALUE_INFINITE);
|
|
|
|
}
|
2009-04-11 07:46:35 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// Sort the PV lines searched so far and update the GUI
|
|
|
|
std::stable_sort(rootMoves.begin(), rootMoves.begin() + PVIdx + 1);
|
2011-04-02 02:05:53 -06:00
|
|
|
|
2015-12-23 02:07:54 -07:00
|
|
|
if (!mainThread)
|
2016-04-28 13:13:32 -06:00
|
|
|
continue;
|
2012-12-30 03:40:20 -07:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
if (Signals.stop)
|
|
|
|
sync_cout << "info nodes " << Threads.nodes_searched()
|
|
|
|
<< " time " << Time.elapsed() << sync_endl;
|
2015-03-12 13:49:30 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
else if (PVIdx + 1 == multiPV || Time.elapsed() > 3000)
|
2015-10-23 23:27:24 -06:00
|
|
|
sync_cout << UCI::pv(rootPos, rootDepth, alpha, beta) << sync_endl;
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
}
|
2015-01-25 03:07:43 -07:00
|
|
|
|
2015-11-02 02:58:18 -07:00
|
|
|
if (!Signals.stop)
|
|
|
|
completedDepth = rootDepth;
|
|
|
|
|
2015-12-23 02:07:54 -07:00
|
|
|
if (!mainThread)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
continue;
|
2015-03-12 13:49:30 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// If skill level is enabled and time is up, pick a sub-optimal best move
|
2015-10-23 23:27:24 -06:00
|
|
|
if (skill.enabled() && skill.time_to_pick(rootDepth))
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
skill.pick_best(multiPV);
|
|
|
|
|
|
|
|
// Have we found a "mate in x"?
|
|
|
|
if ( Limits.mate
|
|
|
|
&& bestValue >= VALUE_MATE_IN_MAX_PLY
|
|
|
|
&& VALUE_MATE - bestValue <= 2 * Limits.mate)
|
|
|
|
Signals.stop = true;
|
|
|
|
|
|
|
|
// Do we have time for the next iteration? Can we stop searching now?
|
|
|
|
if (Limits.use_time_management())
|
|
|
|
{
|
|
|
|
if (!Signals.stop && !Signals.stopOnPonderhit)
|
|
|
|
{
|
2016-01-16 14:34:29 -07:00
|
|
|
// Stop the search if only one legal move is available, or if all
|
|
|
|
// of the available time has been used, or if we matched an easyMove
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// from the previous search and just did a fast verification.
|
2016-05-16 14:30:57 -06:00
|
|
|
const int F[] = { mainThread->failedLow,
|
|
|
|
bestValue - mainThread->previousScore };
|
2016-01-16 01:03:56 -07:00
|
|
|
|
2016-05-16 14:30:57 -06:00
|
|
|
int improvingFactor = std::max(229, std::min(715, 357 + 119 * F[0] - 6 * F[1]));
|
2016-01-18 09:56:35 -07:00
|
|
|
double unstablePvFactor = 1 + mainThread->bestMoveChanges;
|
2016-01-16 01:03:56 -07:00
|
|
|
|
|
|
|
bool doEasyMove = rootMoves[0].pv[0] == easyMove
|
|
|
|
&& mainThread->bestMoveChanges < 0.03
|
2016-05-16 14:30:57 -06:00
|
|
|
&& Time.elapsed() > Time.optimum() * 5 / 42;
|
2016-01-16 01:03:56 -07:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
if ( rootMoves.size() == 1
|
2016-05-16 14:30:57 -06:00
|
|
|
|| Time.elapsed() > Time.optimum() * unstablePvFactor * improvingFactor / 628
|
2016-01-16 01:03:56 -07:00
|
|
|
|| (mainThread->easyMovePlayed = doEasyMove))
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
{
|
|
|
|
// If we are allowed to ponder do not stop the search now but
|
|
|
|
// keep pondering until the GUI sends "ponderhit" or "stop".
|
|
|
|
if (Limits.ponder)
|
|
|
|
Signals.stopOnPonderhit = true;
|
|
|
|
else
|
|
|
|
Signals.stop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rootMoves[0].pv.size() >= 3)
|
|
|
|
EasyMove.update(rootPos, rootMoves[0].pv);
|
|
|
|
else
|
|
|
|
EasyMove.clear();
|
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2015-12-23 02:07:54 -07:00
|
|
|
if (!mainThread)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Clear any candidate easy move that wasn't stable for the last search
|
|
|
|
// iterations; the second condition prevents consecutive fast moves.
|
2015-12-23 02:07:54 -07:00
|
|
|
if (EasyMove.stableCnt < 6 || mainThread->easyMovePlayed)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
EasyMove.clear();
|
|
|
|
|
|
|
|
// If skill level is enabled, swap best PV line with the sub-optimal one
|
|
|
|
if (skill.enabled())
|
|
|
|
std::swap(rootMoves[0], *std::find(rootMoves.begin(),
|
|
|
|
rootMoves.end(), skill.best_move(multiPV)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2015-10-25 05:07:22 -06:00
|
|
|
// search<>() is the main search function for both PV and non-PV nodes
|
2008-08-31 23:59:13 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
template <NodeType NT>
|
2013-06-09 01:43:04 -06:00
|
|
|
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode) {
|
2010-05-08 02:54:51 -06:00
|
|
|
|
2016-01-18 15:20:16 -07:00
|
|
|
const bool PvNode = NT == PV;
|
|
|
|
const bool rootNode = PvNode && (ss-1)->ply == 0;
|
2011-05-28 05:13:42 -06:00
|
|
|
|
2014-02-15 01:20:27 -07:00
|
|
|
assert(-VALUE_INFINITE <= alpha && alpha < beta && beta <= VALUE_INFINITE);
|
2012-09-29 10:26:17 -06:00
|
|
|
assert(PvNode || (alpha == beta - 1));
|
2015-11-06 21:19:13 -07:00
|
|
|
assert(DEPTH_ZERO < depth && depth < DEPTH_MAX);
|
2016-06-23 08:14:51 -06:00
|
|
|
assert(!(PvNode && cutNode));
|
2016-08-19 04:17:38 -06:00
|
|
|
assert(depth / ONE_PLY * ONE_PLY == depth);
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-11-18 03:57:57 -07:00
|
|
|
Move pv[MAX_PLY+1], quietsSearched[64];
|
2009-11-05 03:11:02 -07:00
|
|
|
StateInfo st;
|
2014-12-13 00:16:35 -07:00
|
|
|
TTEntry* tte;
|
2010-06-02 06:22:48 -06:00
|
|
|
Key posKey;
|
2013-12-14 04:27:29 -07:00
|
|
|
Move ttMove, move, excludedMove, bestMove;
|
2016-09-14 07:09:41 -06:00
|
|
|
Depth extension, newDepth;
|
2016-06-03 08:21:12 -06:00
|
|
|
Value bestValue, value, ttValue, eval, nullValue;
|
2014-12-13 01:27:39 -07:00
|
|
|
bool ttHit, inCheck, givesCheck, singularExtensionNode, improving;
|
2016-06-06 07:39:26 -06:00
|
|
|
bool captureOrPromotion, doFullDepthSearch, moveCountPruning;
|
2016-05-18 00:46:05 -06:00
|
|
|
Piece moved_piece;
|
2013-11-17 15:47:18 -07:00
|
|
|
int moveCount, quietCount;
|
2011-01-16 04:02:32 -07:00
|
|
|
|
2012-10-01 01:33:13 -06:00
|
|
|
// Step 1. Initialize node
|
2012-09-29 10:26:17 -06:00
|
|
|
Thread* thisThread = pos.this_thread();
|
2012-12-25 09:59:35 -07:00
|
|
|
inCheck = pos.checkers();
|
2015-07-29 10:50:45 -06:00
|
|
|
moveCount = quietCount = ss->moveCount = 0;
|
2012-10-01 01:33:13 -06:00
|
|
|
bestValue = -VALUE_INFINITE;
|
|
|
|
ss->ply = (ss-1)->ply + 1;
|
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
// Check for the available remaining time
|
2015-11-05 00:40:23 -07:00
|
|
|
if (thisThread->resetCalls.load(std::memory_order_relaxed))
|
Get rid of timer thread
Unfortunately std::condition_variable::wait_for()
is not accurate in general case and the timer thread
can wake up also after tens or even hundreds of
millisecs after time has elapsded. CPU load, process
priorities, number of concurrent threads, even from
other processes, will have effect upon it.
Even official documentation says: "This function may
block for longer than timeout_duration due to scheduling
or resource contention delays."
So retire timer and use a polling scheme based on a
local thread counter that counts search() calls and
a small trick to keep polling frequency constant,
independently from the number of threads.
Tested for no regression at very fast TC 2+0.05 th 7:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 32969 W: 6720 L: 6620 D: 19629
TC 2+0.05 th 1:
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 7765 W: 1917 L: 1765 D: 4083
And at STC TC, both single thread
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 15587 W: 3036 L: 2905 D: 9646
And with 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 8149 W: 1367 L: 1227 D: 5555
bench: 8639247
2015-11-03 03:15:14 -07:00
|
|
|
{
|
2015-11-05 00:40:23 -07:00
|
|
|
thisThread->resetCalls = false;
|
Get rid of timer thread
Unfortunately std::condition_variable::wait_for()
is not accurate in general case and the timer thread
can wake up also after tens or even hundreds of
millisecs after time has elapsded. CPU load, process
priorities, number of concurrent threads, even from
other processes, will have effect upon it.
Even official documentation says: "This function may
block for longer than timeout_duration due to scheduling
or resource contention delays."
So retire timer and use a polling scheme based on a
local thread counter that counts search() calls and
a small trick to keep polling frequency constant,
independently from the number of threads.
Tested for no regression at very fast TC 2+0.05 th 7:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 32969 W: 6720 L: 6620 D: 19629
TC 2+0.05 th 1:
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 7765 W: 1917 L: 1765 D: 4083
And at STC TC, both single thread
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 15587 W: 3036 L: 2905 D: 9646
And with 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 8149 W: 1367 L: 1227 D: 5555
bench: 8639247
2015-11-03 03:15:14 -07:00
|
|
|
thisThread->callsCnt = 0;
|
|
|
|
}
|
|
|
|
if (++thisThread->callsCnt > 4096)
|
|
|
|
{
|
|
|
|
for (Thread* th : Threads)
|
2015-11-05 00:40:23 -07:00
|
|
|
th->resetCalls = true;
|
Get rid of timer thread
Unfortunately std::condition_variable::wait_for()
is not accurate in general case and the timer thread
can wake up also after tens or even hundreds of
millisecs after time has elapsded. CPU load, process
priorities, number of concurrent threads, even from
other processes, will have effect upon it.
Even official documentation says: "This function may
block for longer than timeout_duration due to scheduling
or resource contention delays."
So retire timer and use a polling scheme based on a
local thread counter that counts search() calls and
a small trick to keep polling frequency constant,
independently from the number of threads.
Tested for no regression at very fast TC 2+0.05 th 7:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 32969 W: 6720 L: 6620 D: 19629
TC 2+0.05 th 1:
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 7765 W: 1917 L: 1765 D: 4083
And at STC TC, both single thread
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 15587 W: 3036 L: 2905 D: 9646
And with 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 8149 W: 1367 L: 1227 D: 5555
bench: 8639247
2015-11-03 03:15:14 -07:00
|
|
|
|
|
|
|
check_time();
|
|
|
|
}
|
|
|
|
|
2012-10-01 01:33:13 -06:00
|
|
|
// Used to send selDepth info to GUI
|
|
|
|
if (PvNode && thisThread->maxPly < ss->ply)
|
|
|
|
thisThread->maxPly = ss->ply;
|
2009-11-05 03:11:02 -07:00
|
|
|
|
2016-01-18 15:20:16 -07:00
|
|
|
if (!rootNode)
|
2011-06-18 10:10:29 -06:00
|
|
|
{
|
2012-09-29 10:26:17 -06:00
|
|
|
// Step 2. Check for aborted search and immediate draw
|
Use atomics instead of volatile
Rely on well defined behaviour for message passing, instead of volatile. Three
versions have been tested, to make sure this wouldn't cause a slowdown on any
platform.
v1: Sequentially consistent atomics
No mesurable regression, despite the extra memory barriers on x86. Even with 15
threads and extreme time pressure, both acting as a magnifying glass:
threads=15, tc=2+0.02
ELO: 2.59 +-3.4 (95%) LOS: 93.3%
Total: 18132 W: 4113 L: 3978 D: 10041
threads=7, tc=2+0.02
ELO: -1.64 +-3.6 (95%) LOS: 18.8%
Total: 16914 W: 4053 L: 4133 D: 8728
v2: Acquire/Release semantics
This version generates no extra barriers for x86 (on the hot path). As expected,
no regression either, under the same conditions:
threads=15, tc=2+0.02
ELO: 2.85 +-3.3 (95%) LOS: 95.4%
Total: 19661 W: 4640 L: 4479 D: 10542
threads=7, tc=2+0.02
ELO: 0.23 +-3.5 (95%) LOS: 55.1%
Total: 18108 W: 4326 L: 4314 D: 9468
As suggested by Joona, another test at LTC:
threads=15, tc=20+0.05
ELO: 0.64 +-2.6 (95%) LOS: 68.3%
Total: 20000 W: 3053 L: 3016 D: 13931
v3: Final version: SeqCst/Relaxed
threads=15, tc=10+0.1
ELO: 0.87 +-3.9 (95%) LOS: 67.1%
Total: 9541 W: 1478 L: 1454 D: 6609
Resolves #474
2015-10-24 15:50:51 -06:00
|
|
|
if (Signals.stop.load(std::memory_order_relaxed) || pos.is_draw() || ss->ply >= MAX_PLY)
|
2015-10-25 01:30:07 -06:00
|
|
|
return ss->ply >= MAX_PLY && !inCheck ? evaluate(pos)
|
2015-10-23 23:27:24 -06:00
|
|
|
: DrawValue[pos.side_to_move()];
|
2012-09-29 10:26:17 -06:00
|
|
|
|
|
|
|
// Step 3. Mate distance pruning. Even if we mate at the next move our score
|
|
|
|
// would be at best mate_in(ss->ply+1), but if alpha is already bigger because
|
|
|
|
// a shorter mate was found upward in the tree then there is no need to search
|
2013-12-02 11:04:09 -07:00
|
|
|
// because we will never beat the current alpha. Same logic but with reversed
|
|
|
|
// signs applies also in the opposite condition of being mated instead of giving
|
|
|
|
// mate. In this case return a fail-high score.
|
2011-12-27 08:01:33 -07:00
|
|
|
alpha = std::max(mated_in(ss->ply), alpha);
|
|
|
|
beta = std::min(mate_in(ss->ply+1), beta);
|
2011-06-18 10:10:29 -06:00
|
|
|
if (alpha >= beta)
|
|
|
|
return alpha;
|
|
|
|
}
|
2010-02-24 03:19:47 -07:00
|
|
|
|
Cleanup MAX_PLY
This area has become obscure and tricky over the course of incremental
changes that did not respect the original's consistency and clarity. Now,
it's not clear why we use MAX_PLY = 120, or why we use MAX_PLY+6, among
other things.
This patch does the following:
* ID loop: depth ranges from 1 to MAX_PLY-1, and due to TT constraint (depth
must fit into an int8_t), MAX_PLY should be 128.
* stack[]: plies now range from 0 to MAX_PLY-1, hence stack[MAX_PLY+4],
because of the extra 2+2 padding elements (for ss-2 and ss+2). Document this
better, while we're at it.
* Enforce 0 <= ply < MAX_PLY:
- stop condition is now ss->ply >= MAX_PLY and not ss->ply > MAX_PLY.
- assert(ss->ply < MAX_PLY), before using ss+1 and ss+2.
- as a result, we don't need the artificial MAX_PLY+6 range. Instead we
can use MAX_PLY+4 and it's clear why (for ss-2 and ss+2).
* fix: extract_pv_from_tt() and insert_pv_in_tt() had no reason to use
MAX_PLY_PLUS_6, because the array is indexed by plies, so the range of
available plies applies (0..MAX_PLY before, and now 0..MAX_PLY-1).
Tested with debug compile, using MAX_PLY=16, and running bench at depth 17,
using 1 and 7 threads. No assert() fired. Feel free to submit to more severe
crash-tests, if you can think of any.
No functional change.
2014-11-03 08:36:24 -07:00
|
|
|
assert(0 <= ss->ply && ss->ply < MAX_PLY);
|
|
|
|
|
2015-12-20 13:37:18 -07:00
|
|
|
ss->currentMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
|
2016-04-17 08:14:07 -06:00
|
|
|
ss->counterMoves = nullptr;
|
2015-12-20 14:45:21 -07:00
|
|
|
(ss+1)->skipEarlyPruning = false;
|
Cleanup MAX_PLY
This area has become obscure and tricky over the course of incremental
changes that did not respect the original's consistency and clarity. Now,
it's not clear why we use MAX_PLY = 120, or why we use MAX_PLY+6, among
other things.
This patch does the following:
* ID loop: depth ranges from 1 to MAX_PLY-1, and due to TT constraint (depth
must fit into an int8_t), MAX_PLY should be 128.
* stack[]: plies now range from 0 to MAX_PLY-1, hence stack[MAX_PLY+4],
because of the extra 2+2 padding elements (for ss-2 and ss+2). Document this
better, while we're at it.
* Enforce 0 <= ply < MAX_PLY:
- stop condition is now ss->ply >= MAX_PLY and not ss->ply > MAX_PLY.
- assert(ss->ply < MAX_PLY), before using ss+1 and ss+2.
- as a result, we don't need the artificial MAX_PLY+6 range. Instead we
can use MAX_PLY+4 and it's clear why (for ss-2 and ss+2).
* fix: extract_pv_from_tt() and insert_pv_in_tt() had no reason to use
MAX_PLY_PLUS_6, because the array is indexed by plies, so the range of
available plies applies (0..MAX_PLY before, and now 0..MAX_PLY-1).
Tested with debug compile, using MAX_PLY=16, and running bench at depth 17,
using 1 and 7 threads. No assert() fired. Feel free to submit to more severe
crash-tests, if you can think of any.
No functional change.
2014-11-03 08:36:24 -07:00
|
|
|
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
|
|
|
|
|
2015-10-23 23:27:24 -06:00
|
|
|
// Step 4. Transposition table lookup. We don't want the score of a partial
|
|
|
|
// search to overwrite a previous full search TT value, so we use a different
|
|
|
|
// position key in case of an excluded move.
|
2013-11-18 23:19:28 -07:00
|
|
|
excludedMove = ss->excludedMove;
|
2016-08-30 06:27:05 -06:00
|
|
|
posKey = pos.key() ^ Key(excludedMove);
|
2014-12-13 00:16:35 -07:00
|
|
|
tte = TT.probe(posKey, ttHit);
|
|
|
|
ttValue = ttHit ? value_from_tt(tte->value(), ss->ply) : VALUE_NONE;
|
2016-01-18 15:20:16 -07:00
|
|
|
ttMove = rootNode ? thisThread->rootMoves[thisThread->PVIdx].pv[0]
|
2015-12-20 13:37:18 -07:00
|
|
|
: ttHit ? tte->move() : MOVE_NONE;
|
2008-09-06 07:53:43 -06:00
|
|
|
|
2015-10-23 23:27:24 -06:00
|
|
|
// At non-PV nodes we check for an early TT cutoff
|
2014-11-18 03:57:57 -07:00
|
|
|
if ( !PvNode
|
2014-12-13 00:16:35 -07:00
|
|
|
&& ttHit
|
2012-12-15 03:11:38 -07:00
|
|
|
&& tte->depth() >= depth
|
2015-10-23 23:27:24 -06:00
|
|
|
&& ttValue != VALUE_NONE // Possible in case of TT access race
|
2014-11-12 14:13:55 -07:00
|
|
|
&& (ttValue >= beta ? (tte->bound() & BOUND_LOWER)
|
|
|
|
: (tte->bound() & BOUND_UPPER)))
|
2008-09-06 07:53:43 -06:00
|
|
|
{
|
2012-12-15 03:11:38 -07:00
|
|
|
ss->currentMove = ttMove; // Can be MOVE_NONE
|
2011-09-18 12:50:42 -06:00
|
|
|
|
2015-03-28 16:09:48 -06:00
|
|
|
// If ttMove is quiet, update killers, history, counter move on TT hit
|
2016-08-23 07:57:56 -06:00
|
|
|
if (ttValue >= beta && ttMove)
|
2016-08-24 08:52:05 -06:00
|
|
|
{
|
|
|
|
int d = depth / ONE_PLY;
|
2013-12-09 03:14:14 -07:00
|
|
|
|
2016-08-24 08:52:05 -06:00
|
|
|
if (!pos.capture_or_promotion(ttMove))
|
|
|
|
{
|
|
|
|
Value bonus = Value(d * d + 2 * d - 2);
|
|
|
|
update_stats(pos, ss, ttMove, nullptr, 0, bonus);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extra penalty for a quiet TT move in previous ply when it gets refuted
|
2016-09-03 10:14:01 -06:00
|
|
|
if ((ss-1)->moveCount == 1 && !pos.captured_piece())
|
2016-08-24 08:52:05 -06:00
|
|
|
{
|
|
|
|
Value penalty = Value(d * d + 4 * d + 1);
|
2016-08-26 11:47:40 -06:00
|
|
|
Square prevSq = to_sq((ss-1)->currentMove);
|
|
|
|
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, -penalty);
|
2016-08-24 08:52:05 -06:00
|
|
|
}
|
|
|
|
}
|
2012-12-15 03:11:38 -07:00
|
|
|
return ttValue;
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2015-01-18 00:05:05 -07:00
|
|
|
// Step 4a. Tablebase probe
|
2016-01-18 15:20:16 -07:00
|
|
|
if (!rootNode && TB::Cardinality)
|
2015-01-18 00:05:05 -07:00
|
|
|
{
|
|
|
|
int piecesCnt = pos.count<ALL_PIECES>(WHITE) + pos.count<ALL_PIECES>(BLACK);
|
|
|
|
|
|
|
|
if ( piecesCnt <= TB::Cardinality
|
|
|
|
&& (piecesCnt < TB::Cardinality || depth >= TB::ProbeDepth)
|
2016-01-20 08:24:21 -07:00
|
|
|
&& pos.rule50_count() == 0
|
|
|
|
&& !pos.can_castle(ANY_CASTLING))
|
2015-01-18 00:05:05 -07:00
|
|
|
{
|
|
|
|
int found, v = Tablebases::probe_wdl(pos, &found);
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
TB::Hits++;
|
|
|
|
|
|
|
|
int drawScore = TB::UseRule50 ? 1 : 0;
|
|
|
|
|
|
|
|
value = v < -drawScore ? -VALUE_MATE + MAX_PLY + ss->ply
|
|
|
|
: v > drawScore ? VALUE_MATE - MAX_PLY - ss->ply
|
|
|
|
: VALUE_DRAW + 2 * v * drawScore;
|
|
|
|
|
|
|
|
tte->save(posKey, value_to_tt(value, ss->ply), BOUND_EXACT,
|
|
|
|
std::min(DEPTH_MAX - ONE_PLY, depth + 6 * ONE_PLY),
|
|
|
|
MOVE_NONE, VALUE_NONE, TT.generation());
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 14:58:13 -06:00
|
|
|
// Step 5. Evaluate the position statically
|
2011-04-29 08:26:48 -06:00
|
|
|
if (inCheck)
|
2013-07-07 05:27:31 -06:00
|
|
|
{
|
2013-11-08 03:42:22 -07:00
|
|
|
ss->staticEval = eval = VALUE_NONE;
|
2013-07-07 05:45:46 -06:00
|
|
|
goto moves_loop;
|
2013-07-07 05:27:31 -06:00
|
|
|
}
|
2012-12-27 04:13:31 -07:00
|
|
|
|
2014-12-13 00:16:35 -07:00
|
|
|
else if (ttHit)
|
2010-01-17 04:55:10 -07:00
|
|
|
{
|
2012-12-31 08:28:40 -07:00
|
|
|
// Never assume anything on values stored in TT
|
2015-01-09 04:35:44 -07:00
|
|
|
if ((ss->staticEval = eval = tte->eval()) == VALUE_NONE)
|
2014-06-06 01:35:34 -06:00
|
|
|
eval = ss->staticEval = evaluate(pos);
|
2012-10-26 04:33:58 -06:00
|
|
|
|
2012-10-22 01:50:00 -06:00
|
|
|
// Can ttValue be used as a better position evaluation?
|
2012-12-27 04:13:31 -07:00
|
|
|
if (ttValue != VALUE_NONE)
|
2013-09-25 05:04:38 -06:00
|
|
|
if (tte->bound() & (ttValue > eval ? BOUND_LOWER : BOUND_UPPER))
|
2012-10-26 04:33:58 -06:00
|
|
|
eval = ttValue;
|
2012-12-27 04:13:31 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-06 03:12:05 -06:00
|
|
|
eval = ss->staticEval =
|
2015-10-23 23:27:24 -06:00
|
|
|
(ss-1)->currentMove != MOVE_NULL ? evaluate(pos)
|
|
|
|
: -(ss-1)->staticEval + 2 * Eval::Tempo;
|
2014-06-06 03:12:05 -06:00
|
|
|
|
2015-10-23 23:27:24 -06:00
|
|
|
tte->save(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE,
|
|
|
|
ss->staticEval, TT.generation());
|
2011-10-31 01:28:59 -06:00
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-12-08 01:46:21 -07:00
|
|
|
if (ss->skipEarlyPruning)
|
|
|
|
goto moves_loop;
|
|
|
|
|
2013-07-19 01:37:31 -06:00
|
|
|
// Step 6. Razoring (skipped when in check)
|
2010-05-08 02:54:51 -06:00
|
|
|
if ( !PvNode
|
2012-10-03 02:08:10 -06:00
|
|
|
&& depth < 4 * ONE_PLY
|
2016-08-30 23:51:52 -06:00
|
|
|
&& ttMove == MOVE_NONE
|
|
|
|
&& eval + razor_margin[depth / ONE_PLY] <= alpha)
|
2010-02-24 03:26:36 -07:00
|
|
|
{
|
2014-05-13 14:33:41 -06:00
|
|
|
if ( depth <= ONE_PLY
|
2015-10-20 20:46:06 -06:00
|
|
|
&& eval + razor_margin[3 * ONE_PLY] <= alpha)
|
2014-05-13 14:33:41 -06:00
|
|
|
return qsearch<NonPV, false>(pos, ss, alpha, beta, DEPTH_ZERO);
|
|
|
|
|
2016-08-19 04:17:38 -06:00
|
|
|
Value ralpha = alpha - razor_margin[depth / ONE_PLY];
|
Better document razoring
Use ralpha instead of rbeta
* rbeta is confusing people. It took THREE attempts to code razoring
at PV nodes correctly in a recent test, because of the rbeta trick.
Unnecessary tricks should be avoided.
* The more correct and self-documenting way of doing this, is to say
that we use a zero window around alpha-margin, not beta-margin.
The fact that, because we only do it at PV nodes, alpha happens to be
beta-1 and that the current stuff with rbeta works, may be correct,
but is confusing.
Remove the misleading and partially erroneous comment about returning
v + margin:
* comments should explain what the code does, not what it could have done.
* this comment is partially wrong in saying that v+margin is "logical",
and that it is "surprising" that is doesn't work.
From a theoretical perspective, at least 3 ways of doing this are equally
defendable:
1/ fail hard: return alpha: The most conservative. We bet that the search
will fail low, but we don't know by how much and don't want to take risks.
2/ aggressive fail soft: return v (what the current code does). This
corresponds to normal fail soft, with the added assumption that we don't
care about the reduction effect (see below point 3/)
3/ conservative fail soft: return v + margin. If the reduced search (qsearch)
gives us a score <= v, we bet that the non reduced search will give us a
score <= v + margin.
* Saying that 2/ is "logical" implies that 1/ and 3/ are not, which is
arguably wrong. Besides, experimental results tell us that 2/ beats 3/,
and that's not something we can argue against: experimental results are
the only trusted metric.
* Also, with the benefit of hindsight, I don't think the fact that 2/ is
better than 3/ is surprising at all. The point is that it is YOUR turn to
move, and you are assuming that by NOT playing (and letting the opponent
capture your hanging pieces in QS) you cannot generally GAIN razor_margin(depth).
No functional change.
2014-02-02 18:41:32 -07:00
|
|
|
Value v = qsearch<NonPV, false>(pos, ss, ralpha, ralpha+1, DEPTH_ZERO);
|
|
|
|
if (v <= ralpha)
|
2010-03-03 23:52:35 -07:00
|
|
|
return v;
|
2010-02-24 03:26:36 -07:00
|
|
|
}
|
|
|
|
|
2013-11-08 03:42:22 -07:00
|
|
|
// Step 7. Futility pruning: child node (skipped when in check)
|
2016-01-18 15:20:16 -07:00
|
|
|
if ( !rootNode
|
2013-11-08 03:42:22 -07:00
|
|
|
&& depth < 7 * ONE_PLY
|
|
|
|
&& eval - futility_margin(depth) >= beta
|
2014-09-28 10:45:49 -06:00
|
|
|
&& eval < VALUE_KNOWN_WIN // Do not return unproven wins
|
2010-06-01 12:49:46 -06:00
|
|
|
&& pos.non_pawn_material(pos.side_to_move()))
|
2013-11-08 03:42:22 -07:00
|
|
|
return eval - futility_margin(depth);
|
2010-01-21 10:03:06 -07:00
|
|
|
|
2010-05-08 02:54:51 -06:00
|
|
|
// Step 8. Null move search with verification search (is omitted in PV nodes)
|
|
|
|
if ( !PvNode
|
2012-10-22 01:50:00 -06:00
|
|
|
&& eval >= beta
|
2016-07-14 02:14:32 -06:00
|
|
|
&& (ss->staticEval >= beta - 35 * (depth / ONE_PLY - 6) || depth >= 13 * ONE_PLY)
|
2010-06-01 12:49:46 -06:00
|
|
|
&& pos.non_pawn_material(pos.side_to_move()))
|
2009-08-29 13:19:09 -06:00
|
|
|
{
|
2010-05-30 01:56:38 -06:00
|
|
|
ss->currentMove = MOVE_NULL;
|
2016-04-17 08:14:07 -06:00
|
|
|
ss->counterMoves = nullptr;
|
2009-08-29 13:19:09 -06:00
|
|
|
|
2014-01-24 13:52:56 -07:00
|
|
|
assert(eval - beta >= 0);
|
2009-11-13 03:25:34 -07:00
|
|
|
|
2014-01-24 13:52:56 -07:00
|
|
|
// Null move dynamic reduction based on depth and value
|
2016-08-19 04:17:38 -06:00
|
|
|
Depth R = ((823 + 67 * depth / ONE_PLY) / 256 + std::min((eval - beta) / PawnValueMg, 3)) * ONE_PLY;
|
2009-08-29 13:19:09 -06:00
|
|
|
|
2013-01-27 03:45:01 -07:00
|
|
|
pos.do_null_move(st);
|
2014-12-08 01:46:21 -07:00
|
|
|
(ss+1)->skipEarlyPruning = true;
|
Better document null search window
Hopefully this patch makes the code more:
* Self-documenting: Null search is always a zero window search,
because it is testing for a fail high. It should never be done
on a full window! The current code only works because we don't
do it at PV nodes, and therefore (alpha, beta) = (beta-1, beta):
that's the kind of "clever" trick we should avoid.
* Idiot-proof: If we want to enable null search at PV nodes, all we
need to do now is comment out the !PvNode condition. It's that simple!
In theory, null search should not be done at PV nodes, because PV nodes
should never fail high. But in practice, they DO fail high, because of
aspiration windows, and search inconsistencies, for example. So it makes
sense to keep that flexibility in the code.
No functional change.
2014-02-04 00:18:19 -07:00
|
|
|
nullValue = depth-R < ONE_PLY ? -qsearch<NonPV, false>(pos, ss+1, -beta, -beta+1, DEPTH_ZERO)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
: - search<NonPV>(pos, ss+1, -beta, -beta+1, depth-R, !cutNode);
|
2014-12-08 01:46:21 -07:00
|
|
|
(ss+1)->skipEarlyPruning = false;
|
2013-01-27 03:45:01 -07:00
|
|
|
pos.undo_null_move();
|
2009-08-24 08:46:03 -06:00
|
|
|
|
2014-02-12 06:16:21 -07:00
|
|
|
if (nullValue >= beta)
|
|
|
|
{
|
|
|
|
// Do not return unproven mate scores
|
|
|
|
if (nullValue >= VALUE_MATE_IN_MAX_PLY)
|
|
|
|
nullValue = beta;
|
|
|
|
|
2014-06-16 13:46:42 -06:00
|
|
|
if (depth < 12 * ONE_PLY && abs(beta) < VALUE_KNOWN_WIN)
|
2014-02-12 06:16:21 -07:00
|
|
|
return nullValue;
|
|
|
|
|
|
|
|
// Do verification search at high depths
|
2014-12-08 01:46:21 -07:00
|
|
|
ss->skipEarlyPruning = true;
|
2014-02-12 06:16:21 -07:00
|
|
|
Value v = depth-R < ONE_PLY ? qsearch<NonPV, false>(pos, ss, beta-1, beta, DEPTH_ZERO)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
: search<NonPV>(pos, ss, beta-1, beta, depth-R, false);
|
2014-12-08 01:46:21 -07:00
|
|
|
ss->skipEarlyPruning = false;
|
2014-02-12 06:16:21 -07:00
|
|
|
|
|
|
|
if (v >= beta)
|
|
|
|
return nullValue;
|
|
|
|
}
|
2009-08-29 13:19:09 -06:00
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-02-15 14:17:58 -07:00
|
|
|
// Step 9. ProbCut (skipped when in check)
|
2016-08-28 04:39:49 -06:00
|
|
|
// If we have a good enough capture and a reduced search returns a value
|
|
|
|
// much above beta, we can (almost) safely prune the previous move.
|
2011-05-21 10:17:11 -06:00
|
|
|
if ( !PvNode
|
2012-10-03 02:08:10 -06:00
|
|
|
&& depth >= 5 * ONE_PLY
|
2011-12-30 09:08:07 -07:00
|
|
|
&& abs(beta) < VALUE_MATE_IN_MAX_PLY)
|
2011-05-21 10:17:11 -06:00
|
|
|
{
|
2014-02-22 02:34:48 -07:00
|
|
|
Value rbeta = std::min(beta + 200, VALUE_INFINITE);
|
2014-03-03 00:07:57 -07:00
|
|
|
Depth rdepth = depth - 4 * ONE_PLY;
|
2011-05-21 10:17:11 -06:00
|
|
|
|
|
|
|
assert(rdepth >= ONE_PLY);
|
2012-01-21 15:30:56 -07:00
|
|
|
assert((ss-1)->currentMove != MOVE_NONE);
|
2012-02-20 06:21:25 -07:00
|
|
|
assert((ss-1)->currentMove != MOVE_NULL);
|
2011-05-21 10:17:11 -06:00
|
|
|
|
2016-08-28 04:39:49 -06:00
|
|
|
MovePicker mp(pos, ttMove, rbeta - ss->staticEval);
|
2011-05-21 10:17:11 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
while ((move = mp.next_move()) != MOVE_NONE)
|
2016-07-03 02:35:44 -06:00
|
|
|
if (pos.legal(move))
|
2011-05-21 10:17:11 -06:00
|
|
|
{
|
2012-01-21 15:30:56 -07:00
|
|
|
ss->currentMove = move;
|
2016-08-29 01:11:20 -06:00
|
|
|
ss->counterMoves = &thisThread->counterMoveHistory[pos.moved_piece(move)][to_sq(move)];
|
2016-07-03 02:35:44 -06:00
|
|
|
pos.do_move(move, st, pos.gives_check(move));
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
value = -search<NonPV>(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode);
|
2011-05-21 10:17:11 -06:00
|
|
|
pos.undo_move(move);
|
|
|
|
if (value >= rbeta)
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-19 01:37:31 -06:00
|
|
|
// Step 10. Internal iterative deepening (skipped when in check)
|
2016-08-15 09:19:21 -06:00
|
|
|
if ( depth >= 6 * ONE_PLY
|
2014-02-15 01:20:27 -07:00
|
|
|
&& !ttMove
|
2014-04-27 02:13:59 -06:00
|
|
|
&& (PvNode || ss->staticEval + 256 >= beta))
|
2008-09-06 10:25:58 -06:00
|
|
|
{
|
2016-08-19 04:17:38 -06:00
|
|
|
Depth d = (3 * depth / (4 * ONE_PLY) - 2) * ONE_PLY;
|
2014-12-08 01:46:21 -07:00
|
|
|
ss->skipEarlyPruning = true;
|
2016-08-19 04:17:38 -06:00
|
|
|
search<NT>(pos, ss, alpha, beta, d, cutNode);
|
2014-12-08 01:46:21 -07:00
|
|
|
ss->skipEarlyPruning = false;
|
2010-06-02 06:32:31 -06:00
|
|
|
|
2014-12-13 00:16:35 -07:00
|
|
|
tte = TT.probe(posKey, ttHit);
|
|
|
|
ttMove = ttHit ? tte->move() : MOVE_NONE;
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
moves_loop: // When in check search starts from here
|
2010-10-16 03:01:45 -06:00
|
|
|
|
2016-05-18 00:46:05 -06:00
|
|
|
const CounterMoveStats* cmh = (ss-1)->counterMoves;
|
|
|
|
const CounterMoveStats* fmh = (ss-2)->counterMoves;
|
|
|
|
const CounterMoveStats* fmh2 = (ss-4)->counterMoves;
|
2013-05-19 13:32:52 -06:00
|
|
|
|
2016-04-17 08:14:07 -06:00
|
|
|
MovePicker mp(pos, ttMove, depth, ss);
|
2012-09-29 10:26:17 -06:00
|
|
|
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
|
2013-08-09 00:21:55 -06:00
|
|
|
improving = ss->staticEval >= (ss-2)->staticEval
|
2016-06-23 08:08:43 -06:00
|
|
|
/* || ss->staticEval == VALUE_NONE Already implicit in the previous condition */
|
2013-08-09 00:21:55 -06:00
|
|
|
||(ss-2)->staticEval == VALUE_NONE;
|
|
|
|
|
2016-01-18 15:20:16 -07:00
|
|
|
singularExtensionNode = !rootNode
|
2013-09-07 01:32:01 -06:00
|
|
|
&& depth >= 8 * ONE_PLY
|
2012-04-28 04:08:10 -06:00
|
|
|
&& ttMove != MOVE_NONE
|
Fix Singular extension condition to handle mate scores
With Eelco's patch "Don't special case for abs(beta) >= VALUE_MATE_IN_MAX_PLY" condition "abs(ttValue) < VALUE_KNOWN_WIN" has been removed from singular extension search, and condition "abs(beta) < VALUE_KNOWN_WIN" was added to the SingularExtensionNode definition.
This might lead to problems, especially in positions, where a mate is due.
For example, this position 5rk1/4K1pp/8/5PPP/8/8/8/1R6 w - - 12 1 triggers an assert.
stockfish: search.cpp:434: Value {anonymous}::search(Position&, Search::Stack*, Value, Value, Depth, bool) [with {anonymous}::NodeType NT = (<unnamed>::NodeType)2u; bool SpNode = false]: Assertion `-VALUE_INFINITE <= alpha && alpha < beta && beta <= VALUE_INFINITE' failed.
So let's re-insert the removed condition.
First spotted by Uri Blass, fix by me.
Bench: 8759675
2014-06-29 13:17:40 -06:00
|
|
|
/* && ttValue != VALUE_NONE Already implicit in the next condition */
|
|
|
|
&& abs(ttValue) < VALUE_KNOWN_WIN
|
2011-12-10 11:14:13 -07:00
|
|
|
&& !excludedMove // Recursive singular search is not allowed
|
2013-06-29 02:23:43 -06:00
|
|
|
&& (tte->bound() & BOUND_LOWER)
|
2012-04-28 04:08:10 -06:00
|
|
|
&& tte->depth() >= depth - 3 * ONE_PLY;
|
2010-10-16 03:01:45 -06:00
|
|
|
|
2011-05-21 10:17:11 -06:00
|
|
|
// Step 11. Loop through moves
|
2011-05-28 05:57:36 -06:00
|
|
|
// Loop through all pseudo-legal moves until no moves remain or a beta cutoff occurs
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
while ((move = mp.next_move()) != MOVE_NONE)
|
2008-09-06 10:25:58 -06:00
|
|
|
{
|
2011-10-03 02:56:49 -06:00
|
|
|
assert(is_ok(move));
|
2011-01-16 15:40:06 -07:00
|
|
|
|
2011-05-28 03:35:52 -06:00
|
|
|
if (move == excludedMove)
|
|
|
|
continue;
|
|
|
|
|
2011-10-08 03:51:39 -06:00
|
|
|
// At root obey the "searchmoves" option and skip moves not listed in Root
|
2013-12-04 23:18:12 -07:00
|
|
|
// Move List. As a consequence any illegal move is also skipped. In MultiPV
|
2011-10-08 03:51:39 -06:00
|
|
|
// mode we also skip PV moves which have been already searched.
|
2016-01-18 15:20:16 -07:00
|
|
|
if (rootNode && !std::count(thisThread->rootMoves.begin() + thisThread->PVIdx,
|
2015-10-23 23:27:24 -06:00
|
|
|
thisThread->rootMoves.end(), move))
|
2011-07-31 06:18:52 -06:00
|
|
|
continue;
|
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
ss->moveCount = ++moveCount;
|
2012-09-29 09:41:53 -06:00
|
|
|
|
2016-01-18 15:20:16 -07:00
|
|
|
if (rootNode && thisThread == Threads.main() && Time.elapsed() > 3000)
|
2015-12-09 00:07:34 -07:00
|
|
|
sync_cout << "info depth " << depth / ONE_PLY
|
|
|
|
<< " currmove " << UCI::move(move, pos.is_chess960())
|
|
|
|
<< " currmovenumber " << moveCount + thisThread->PVIdx << sync_endl;
|
2011-01-16 04:02:32 -07:00
|
|
|
|
2014-11-12 14:13:55 -07:00
|
|
|
if (PvNode)
|
2015-01-18 00:00:50 -07:00
|
|
|
(ss+1)->pv = nullptr;
|
2014-11-12 14:13:55 -07:00
|
|
|
|
2014-12-07 16:53:33 -07:00
|
|
|
extension = DEPTH_ZERO;
|
2013-09-28 06:43:50 -06:00
|
|
|
captureOrPromotion = pos.capture_or_promotion(move);
|
2016-05-18 00:46:05 -06:00
|
|
|
moved_piece = pos.moved_piece(move);
|
2014-02-08 05:21:50 -07:00
|
|
|
|
2016-07-03 02:35:44 -06:00
|
|
|
givesCheck = type_of(move) == NORMAL && !pos.discovered_check_candidates()
|
2016-08-27 02:05:42 -06:00
|
|
|
? pos.check_squares(type_of(pos.piece_on(from_sq(move)))) & to_sq(move)
|
2016-07-03 02:35:44 -06:00
|
|
|
: pos.gives_check(move);
|
2014-02-08 05:21:50 -07:00
|
|
|
|
2016-06-06 07:39:26 -06:00
|
|
|
moveCountPruning = depth < 16 * ONE_PLY
|
2016-08-19 04:17:38 -06:00
|
|
|
&& moveCount >= FutilityMoveCounts[improving][depth / ONE_PLY];
|
2016-06-06 07:39:26 -06:00
|
|
|
|
2013-09-26 04:25:27 -06:00
|
|
|
// Step 12. Extend checks
|
2016-06-11 22:40:10 -06:00
|
|
|
if ( givesCheck
|
|
|
|
&& !moveCountPruning
|
|
|
|
&& pos.see_sign(move) >= VALUE_ZERO)
|
2014-12-07 16:53:33 -07:00
|
|
|
extension = ONE_PLY;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-04-03 02:19:08 -06:00
|
|
|
// Singular extension search. If all moves but one fail low on a search of
|
|
|
|
// (alpha-s, beta-s), and just one fails high on (alpha, beta), then that move
|
|
|
|
// is singular and should be extended. To verify this we do a reduced search
|
2013-12-02 11:04:09 -07:00
|
|
|
// on all the other moves but the ttMove and if the result is lower than
|
|
|
|
// ttValue minus a margin then we extend the ttMove.
|
2012-04-28 04:08:10 -06:00
|
|
|
if ( singularExtensionNode
|
|
|
|
&& move == ttMove
|
2014-12-07 16:53:33 -07:00
|
|
|
&& !extension
|
2016-07-03 02:35:44 -06:00
|
|
|
&& pos.legal(move))
|
2009-11-21 06:22:52 -07:00
|
|
|
{
|
2014-11-25 16:53:40 -07:00
|
|
|
Value rBeta = ttValue - 2 * depth / ONE_PLY;
|
2016-08-19 04:17:38 -06:00
|
|
|
Depth d = (depth / (2 * ONE_PLY)) * ONE_PLY;
|
2012-07-14 05:18:14 -06:00
|
|
|
ss->excludedMove = move;
|
2014-12-08 01:46:21 -07:00
|
|
|
ss->skipEarlyPruning = true;
|
2016-08-19 04:17:38 -06:00
|
|
|
value = search<NonPV>(pos, ss, rBeta - 1, rBeta, d, cutNode);
|
2014-12-08 01:46:21 -07:00
|
|
|
ss->skipEarlyPruning = false;
|
2012-07-14 05:18:14 -06:00
|
|
|
ss->excludedMove = MOVE_NONE;
|
|
|
|
|
|
|
|
if (value < rBeta)
|
2014-12-07 16:53:33 -07:00
|
|
|
extension = ONE_PLY;
|
2009-11-21 06:22:52 -07:00
|
|
|
}
|
|
|
|
|
2013-12-02 11:04:09 -07:00
|
|
|
// Update the current move (this must be done after singular extension search)
|
2014-12-07 16:53:33 -07:00
|
|
|
newDepth = depth - ONE_PLY + extension;
|
2009-11-21 08:05:18 -07:00
|
|
|
|
2015-01-14 13:11:33 -07:00
|
|
|
// Step 13. Pruning at shallow depth
|
2016-09-07 21:57:52 -06:00
|
|
|
if ( !rootNode
|
2016-09-07 15:37:06 -06:00
|
|
|
&& !inCheck
|
|
|
|
&& bestValue > VALUE_MATED_IN_MAX_PLY)
|
2008-09-06 10:25:58 -06:00
|
|
|
{
|
2016-09-07 21:57:52 -06:00
|
|
|
if ( !captureOrPromotion
|
|
|
|
&& !givesCheck
|
|
|
|
&& !pos.advanced_pawn_push(move))
|
|
|
|
{
|
|
|
|
// Move count based pruning
|
|
|
|
if (moveCountPruning)
|
|
|
|
continue;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2016-09-14 07:09:41 -06:00
|
|
|
// Reduced depth of the next LMR search
|
|
|
|
int lmrDepth = std::max(newDepth - reduction<PvNode>(improving, depth, moveCount), DEPTH_ZERO) / ONE_PLY;
|
2016-08-12 11:55:12 -06:00
|
|
|
|
2016-09-07 21:57:52 -06:00
|
|
|
// Countermoves based pruning
|
2016-09-14 07:09:41 -06:00
|
|
|
if ( lmrDepth < 3
|
2016-09-07 21:57:52 -06:00
|
|
|
&& (!cmh || (*cmh )[moved_piece][to_sq(move)] < VALUE_ZERO)
|
|
|
|
&& (!fmh || (*fmh )[moved_piece][to_sq(move)] < VALUE_ZERO)
|
|
|
|
&& (!fmh2 || (*fmh2)[moved_piece][to_sq(move)] < VALUE_ZERO || (cmh && fmh)))
|
|
|
|
continue;
|
2015-10-21 16:21:23 -06:00
|
|
|
|
2016-09-07 21:57:52 -06:00
|
|
|
// Futility pruning: parent node
|
2016-09-14 07:09:41 -06:00
|
|
|
if ( lmrDepth < 7
|
|
|
|
&& ss->staticEval + 256 + 200 * lmrDepth <= alpha)
|
2016-09-07 21:57:52 -06:00
|
|
|
continue;
|
2013-11-07 14:29:07 -07:00
|
|
|
|
2016-09-14 07:09:41 -06:00
|
|
|
// Prune moves with negative SEE
|
|
|
|
if ( lmrDepth < 8
|
|
|
|
&& pos.see_sign(move) < Value(-35 * lmrDepth * lmrDepth))
|
|
|
|
continue;
|
2016-07-23 01:49:18 -06:00
|
|
|
}
|
2016-09-14 07:09:41 -06:00
|
|
|
else if ( depth < 7 * ONE_PLY
|
|
|
|
&& pos.see_sign(move) < Value(-35 * depth / ONE_PLY * depth / ONE_PLY))
|
|
|
|
continue;
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2014-10-03 22:07:55 -06:00
|
|
|
// Speculative prefetch as early as possible
|
2015-02-07 11:13:41 -07:00
|
|
|
prefetch(TT.first_entry(pos.key_after(move)));
|
2014-10-02 15:19:14 -06:00
|
|
|
|
2013-12-02 11:04:09 -07:00
|
|
|
// Check for legality just before making the move
|
2016-07-03 02:35:44 -06:00
|
|
|
if (!rootNode && !pos.legal(move))
|
2011-05-28 03:35:52 -06:00
|
|
|
{
|
2015-07-28 04:53:13 -06:00
|
|
|
ss->moveCount = --moveCount;
|
2011-05-23 07:14:47 -06:00
|
|
|
continue;
|
2011-05-28 03:35:52 -06:00
|
|
|
}
|
2011-05-23 07:14:47 -06:00
|
|
|
|
|
|
|
ss->currentMove = move;
|
2016-08-29 01:11:20 -06:00
|
|
|
ss->counterMoves = &thisThread->counterMoveHistory[moved_piece][to_sq(move)];
|
2011-05-23 07:14:47 -06:00
|
|
|
|
2011-05-21 10:17:11 -06:00
|
|
|
// Step 14. Make the move
|
Compute checkers from scratch
This micro-optimization only complicates the code and provides no benefit.
Removing it is even a speedup on my machine (i7-3770k, linux, gcc 4.9.1):
stat test master diff
mean 2,403,118 2,390,904 12,214
stdev 12,043 10,620 3,677
speedup 0.51%
P(speedup>0) 100.0%
No functional change.
2015-02-15 00:49:20 -07:00
|
|
|
pos.do_move(move, st, givesCheck);
|
2008-09-03 15:33:49 -06:00
|
|
|
|
2013-12-04 23:18:12 -07:00
|
|
|
// Step 15. Reduced depth search (LMR). If the move fails high it will be
|
2011-11-19 05:55:26 -07:00
|
|
|
// re-searched at full depth.
|
2013-09-07 01:20:22 -06:00
|
|
|
if ( depth >= 3 * ONE_PLY
|
2014-11-07 14:40:24 -07:00
|
|
|
&& moveCount > 1
|
2016-08-16 07:53:45 -06:00
|
|
|
&& (!captureOrPromotion || moveCountPruning))
|
2008-09-06 10:25:58 -06:00
|
|
|
{
|
2015-12-20 14:45:21 -07:00
|
|
|
Depth r = reduction<PvNode>(improving, depth, moveCount);
|
2016-08-16 07:53:45 -06:00
|
|
|
|
|
|
|
if (captureOrPromotion)
|
|
|
|
r -= r ? ONE_PLY : DEPTH_ZERO;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Increase reduction for cut nodes
|
|
|
|
if (cutNode)
|
|
|
|
r += 2 * ONE_PLY;
|
|
|
|
|
|
|
|
// Decrease reduction for moves that escape a capture. Filter out
|
|
|
|
// castling moves, because they are coded as "king captures rook" and
|
|
|
|
// hence break make_move(). Also use see() instead of see_sign(),
|
|
|
|
// because the destination square is empty.
|
|
|
|
else if ( type_of(move) == NORMAL
|
|
|
|
&& type_of(pos.piece_on(to_sq(move))) != PAWN
|
|
|
|
&& pos.see(make_move(to_sq(move), from_sq(move))) < VALUE_ZERO)
|
|
|
|
r -= 2 * ONE_PLY;
|
|
|
|
|
|
|
|
// Decrease/increase reduction for moves with a good/bad history
|
2016-08-19 04:17:38 -06:00
|
|
|
Value val = thisThread->history[moved_piece][to_sq(move)]
|
|
|
|
+ (cmh ? (*cmh )[moved_piece][to_sq(move)] : VALUE_ZERO)
|
|
|
|
+ (fmh ? (*fmh )[moved_piece][to_sq(move)] : VALUE_ZERO)
|
|
|
|
+ (fmh2 ? (*fmh2)[moved_piece][to_sq(move)] : VALUE_ZERO)
|
|
|
|
+ thisThread->fromTo.get(~pos.side_to_move(), move);
|
2016-08-23 07:57:56 -06:00
|
|
|
int rHist = (val - 8000) / 20000;
|
2016-08-19 04:17:38 -06:00
|
|
|
r = std::max(DEPTH_ZERO, (r / ONE_PLY - rHist) * ONE_PLY);
|
2016-08-16 07:53:45 -06:00
|
|
|
}
|
2014-06-03 03:32:45 -06:00
|
|
|
|
2015-12-20 14:45:21 -07:00
|
|
|
Depth d = std::max(newDepth - r, ONE_PLY);
|
2011-06-25 07:31:57 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
|
2011-06-25 07:31:57 -06:00
|
|
|
|
2016-08-16 07:53:45 -06:00
|
|
|
doFullDepthSearch = (value > alpha && d != newDepth);
|
2011-11-19 05:55:26 -07:00
|
|
|
}
|
|
|
|
else
|
2014-11-08 03:39:38 -07:00
|
|
|
doFullDepthSearch = !PvNode || moveCount > 1;
|
2010-05-08 02:54:51 -06:00
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
// Step 16. Full depth search when LMR is skipped or fails high
|
2011-11-19 05:55:26 -07:00
|
|
|
if (doFullDepthSearch)
|
2014-09-29 06:08:56 -06:00
|
|
|
value = newDepth < ONE_PLY ?
|
|
|
|
givesCheck ? -qsearch<NonPV, true>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
|
|
|
: -qsearch<NonPV, false>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode);
|
2010-02-24 03:55:58 -07:00
|
|
|
|
2013-12-02 11:04:09 -07:00
|
|
|
// For PV nodes only, do a full PV search on the first move or after a fail
|
|
|
|
// high (in the latter case search only if value < beta), otherwise let the
|
2016-01-16 14:34:29 -07:00
|
|
|
// parent node fail low with value <= alpha and try another move.
|
2016-01-18 15:20:16 -07:00
|
|
|
if (PvNode && (moveCount == 1 || (value > alpha && (rootNode || value < beta))))
|
2014-11-18 03:57:57 -07:00
|
|
|
{
|
|
|
|
(ss+1)->pv = pv;
|
2014-11-21 01:10:52 -07:00
|
|
|
(ss+1)->pv[0] = MOVE_NONE;
|
|
|
|
|
2014-09-29 06:08:56 -06:00
|
|
|
value = newDepth < ONE_PLY ?
|
|
|
|
givesCheck ? -qsearch<PV, true>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
|
|
|
: -qsearch<PV, false>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, false);
|
2014-11-12 14:13:55 -07:00
|
|
|
}
|
2014-11-18 03:57:57 -07:00
|
|
|
|
2011-05-21 10:17:11 -06:00
|
|
|
// Step 17. Undo move
|
2009-02-22 09:49:52 -07:00
|
|
|
pos.undo_move(move);
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
|
2008-09-03 15:33:49 -06:00
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
// Step 18. Check for a new best move
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// Finished searching the move. If a stop occurred, the return value of
|
|
|
|
// the search cannot be trusted, and we return immediately without
|
2014-05-01 00:28:49 -06:00
|
|
|
// updating best move, PV and TT.
|
Use atomics instead of volatile
Rely on well defined behaviour for message passing, instead of volatile. Three
versions have been tested, to make sure this wouldn't cause a slowdown on any
platform.
v1: Sequentially consistent atomics
No mesurable regression, despite the extra memory barriers on x86. Even with 15
threads and extreme time pressure, both acting as a magnifying glass:
threads=15, tc=2+0.02
ELO: 2.59 +-3.4 (95%) LOS: 93.3%
Total: 18132 W: 4113 L: 3978 D: 10041
threads=7, tc=2+0.02
ELO: -1.64 +-3.6 (95%) LOS: 18.8%
Total: 16914 W: 4053 L: 4133 D: 8728
v2: Acquire/Release semantics
This version generates no extra barriers for x86 (on the hot path). As expected,
no regression either, under the same conditions:
threads=15, tc=2+0.02
ELO: 2.85 +-3.3 (95%) LOS: 95.4%
Total: 19661 W: 4640 L: 4479 D: 10542
threads=7, tc=2+0.02
ELO: 0.23 +-3.5 (95%) LOS: 55.1%
Total: 18108 W: 4326 L: 4314 D: 9468
As suggested by Joona, another test at LTC:
threads=15, tc=20+0.05
ELO: 0.64 +-2.6 (95%) LOS: 68.3%
Total: 20000 W: 3053 L: 3016 D: 13931
v3: Final version: SeqCst/Relaxed
threads=15, tc=10+0.1
ELO: 0.87 +-3.9 (95%) LOS: 67.1%
Total: 9541 W: 1478 L: 1454 D: 6609
Resolves #474
2015-10-24 15:50:51 -06:00
|
|
|
if (Signals.stop.load(std::memory_order_relaxed))
|
2014-05-01 08:25:17 -06:00
|
|
|
return VALUE_ZERO;
|
2013-08-15 01:36:26 -06:00
|
|
|
|
2016-01-18 15:20:16 -07:00
|
|
|
if (rootNode)
|
2011-01-16 04:02:32 -07:00
|
|
|
{
|
2015-10-23 23:27:24 -06:00
|
|
|
RootMove& rm = *std::find(thisThread->rootMoves.begin(),
|
|
|
|
thisThread->rootMoves.end(), move);
|
2011-01-16 04:02:32 -07:00
|
|
|
|
2011-02-17 01:24:55 -07:00
|
|
|
// PV move or new best move ?
|
2014-11-08 03:39:38 -07:00
|
|
|
if (moveCount == 1 || value > alpha)
|
2011-01-16 04:02:32 -07:00
|
|
|
{
|
2011-12-12 09:55:20 -07:00
|
|
|
rm.score = value;
|
2014-11-12 14:13:55 -07:00
|
|
|
rm.pv.resize(1);
|
2014-11-21 01:10:52 -07:00
|
|
|
|
|
|
|
assert((ss+1)->pv);
|
|
|
|
|
|
|
|
for (Move* m = (ss+1)->pv; *m != MOVE_NONE; ++m)
|
|
|
|
rm.pv.push_back(*m);
|
2011-01-16 04:02:32 -07:00
|
|
|
|
|
|
|
// We record how often the best move has been changed in each
|
2011-02-12 11:04:27 -07:00
|
|
|
// iteration. This information is used for time management: When
|
2011-01-16 04:02:32 -07:00
|
|
|
// the best move changes frequently, we allocate some more time.
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
if (moveCount > 1 && thisThread == Threads.main())
|
2015-12-23 02:07:54 -07:00
|
|
|
++static_cast<MainThread*>(thisThread)->bestMoveChanges;
|
2011-02-17 01:24:55 -07:00
|
|
|
}
|
|
|
|
else
|
2013-12-02 11:04:09 -07:00
|
|
|
// All other moves but the PV are set to the lowest value: this is
|
|
|
|
// not a problem when sorting because the sort is stable and the
|
|
|
|
// move position in the list is preserved - just the PV is pushed up.
|
2011-12-12 09:55:20 -07:00
|
|
|
rm.score = -VALUE_INFINITE;
|
2011-12-10 11:14:13 -07:00
|
|
|
}
|
2011-01-16 04:02:32 -07:00
|
|
|
|
2011-08-06 02:15:46 -06:00
|
|
|
if (value > bestValue)
|
|
|
|
{
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
bestValue = value;
|
2011-08-06 02:15:46 -06:00
|
|
|
|
2012-10-03 06:11:20 -06:00
|
|
|
if (value > alpha)
|
2012-10-01 01:33:13 -06:00
|
|
|
{
|
2015-03-18 01:12:59 -06:00
|
|
|
// If there is an easy move for this position, clear it if unstable
|
|
|
|
if ( PvNode
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
&& thisThread == Threads.main()
|
2015-03-18 01:12:59 -06:00
|
|
|
&& EasyMove.get(pos.key())
|
|
|
|
&& (move != EasyMove.get(pos.key()) || moveCount > 1))
|
|
|
|
EasyMove.clear();
|
2015-03-12 13:49:30 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
bestMove = move;
|
2012-10-03 06:11:20 -06:00
|
|
|
|
2016-01-18 15:20:16 -07:00
|
|
|
if (PvNode && !rootNode) // Update pv even in fail-high case
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
update_pv(ss->pv, move, (ss+1)->pv);
|
2014-11-12 14:13:55 -07:00
|
|
|
|
2013-01-13 04:34:31 -07:00
|
|
|
if (PvNode && value < beta) // Update alpha! Always alpha < beta
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
alpha = value;
|
2012-11-17 04:44:19 -07:00
|
|
|
else
|
2012-10-05 07:00:35 -06:00
|
|
|
{
|
2012-11-17 04:44:19 -07:00
|
|
|
assert(value >= beta); // Fail high
|
2012-10-05 07:00:35 -06:00
|
|
|
break;
|
|
|
|
}
|
2011-08-06 02:15:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
if (!captureOrPromotion && move != bestMove && quietCount < 64)
|
2015-04-10 13:32:39 -06:00
|
|
|
quietsSearched[quietCount++] = move;
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
// The following condition would detect a stop only after move loop has been
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
// completed. But in this case bestValue is valid because we have fully
|
|
|
|
// searched our subtree, and we can anyhow save the result in TT.
|
2014-05-01 00:28:49 -06:00
|
|
|
/*
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
if (Signals.stop)
|
2014-05-01 00:28:49 -06:00
|
|
|
return VALUE_DRAW;
|
|
|
|
*/
|
|
|
|
|
2011-05-21 10:17:11 -06:00
|
|
|
// Step 20. Check for mate and stalemate
|
2011-10-18 04:24:47 -06:00
|
|
|
// All legal moves have been searched and if there are no legal moves, it
|
2016-01-16 14:34:29 -07:00
|
|
|
// must be a mate or a stalemate. If we are in a singular extension search then
|
2014-05-01 00:28:49 -06:00
|
|
|
// return a fail low score.
|
2012-10-03 06:11:20 -06:00
|
|
|
if (!moveCount)
|
2014-05-11 02:56:25 -06:00
|
|
|
bestValue = excludedMove ? alpha
|
|
|
|
: inCheck ? mated_in(ss->ply) : DrawValue[pos.side_to_move()];
|
2016-08-23 07:57:56 -06:00
|
|
|
else if (bestMove)
|
2016-08-24 08:52:05 -06:00
|
|
|
{
|
|
|
|
int d = depth / ONE_PLY;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2016-08-24 08:52:05 -06:00
|
|
|
// Quiet best move: update killers, history and countermoves
|
|
|
|
if (!pos.capture_or_promotion(bestMove))
|
|
|
|
{
|
|
|
|
Value bonus = Value(d * d + 2 * d - 2);
|
|
|
|
update_stats(pos, ss, bestMove, quietsSearched, quietCount, bonus);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extra penalty for a quiet TT move in previous ply when it gets refuted
|
2016-09-03 10:14:01 -06:00
|
|
|
if ((ss-1)->moveCount == 1 && !pos.captured_piece())
|
2016-08-24 08:52:05 -06:00
|
|
|
{
|
|
|
|
Value penalty = Value(d * d + 4 * d + 1);
|
2016-08-26 11:47:40 -06:00
|
|
|
Square prevSq = to_sq((ss-1)->currentMove);
|
|
|
|
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, -penalty);
|
2016-08-24 08:52:05 -06:00
|
|
|
}
|
|
|
|
}
|
2015-10-12 15:00:54 -06:00
|
|
|
// Bonus for prior countermove that caused the fail low
|
2015-10-23 23:27:24 -06:00
|
|
|
else if ( depth >= 3 * ONE_PLY
|
2016-09-03 10:14:01 -06:00
|
|
|
&& !pos.captured_piece()
|
2016-04-17 08:14:07 -06:00
|
|
|
&& is_ok((ss-1)->currentMove))
|
2015-10-12 15:00:54 -06:00
|
|
|
{
|
2016-08-24 08:52:05 -06:00
|
|
|
int d = depth / ONE_PLY;
|
|
|
|
Value bonus = Value(d * d + 2 * d - 2);
|
2016-08-26 11:47:40 -06:00
|
|
|
Square prevSq = to_sq((ss-1)->currentMove);
|
|
|
|
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, bonus);
|
2015-10-12 15:00:54 -06:00
|
|
|
}
|
|
|
|
|
2014-12-13 00:16:35 -07:00
|
|
|
tte->save(posKey, value_to_tt(bestValue, ss->ply),
|
|
|
|
bestValue >= beta ? BOUND_LOWER :
|
|
|
|
PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER,
|
2014-12-13 01:27:39 -07:00
|
|
|
depth, bestMove, ss->staticEval, TT.generation());
|
2010-05-08 02:54:51 -06:00
|
|
|
|
2009-03-22 07:49:18 -06:00
|
|
|
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
|
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
return bestValue;
|
|
|
|
}
|
2008-09-03 15:33:49 -06:00
|
|
|
|
2011-12-10 11:14:13 -07:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
// qsearch() is the quiescence search function, which is called by the main
|
|
|
|
// search function when the remaining depth is zero (or, to be more precise,
|
2010-08-18 07:23:19 -06:00
|
|
|
// less than ONE_PLY).
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2012-11-01 07:49:54 -06:00
|
|
|
template <NodeType NT, bool InCheck>
|
2011-12-04 03:46:31 -07:00
|
|
|
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-05-04 05:11:32 -06:00
|
|
|
const bool PvNode = NT == PV;
|
2011-05-28 05:13:42 -06:00
|
|
|
|
2012-12-25 09:59:35 -07:00
|
|
|
assert(InCheck == !!pos.checkers());
|
2011-12-26 17:00:44 -07:00
|
|
|
assert(alpha >= -VALUE_INFINITE && alpha < beta && beta <= VALUE_INFINITE);
|
2012-10-07 01:34:04 -06:00
|
|
|
assert(PvNode || (alpha == beta - 1));
|
2011-12-26 17:00:44 -07:00
|
|
|
assert(depth <= DEPTH_ZERO);
|
2016-08-19 04:17:38 -06:00
|
|
|
assert(depth / ONE_PLY * ONE_PLY == depth);
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-11-18 03:57:57 -07:00
|
|
|
Move pv[MAX_PLY+1];
|
2009-11-05 03:11:02 -07:00
|
|
|
StateInfo st;
|
2014-12-13 00:16:35 -07:00
|
|
|
TTEntry* tte;
|
2012-10-07 01:34:04 -06:00
|
|
|
Key posKey;
|
|
|
|
Move ttMove, move, bestMove;
|
2012-12-15 03:11:38 -07:00
|
|
|
Value bestValue, value, ttValue, futilityValue, futilityBase, oldAlpha;
|
2014-12-13 01:27:39 -07:00
|
|
|
bool ttHit, givesCheck, evasionPrunable;
|
2010-12-18 02:27:24 -07:00
|
|
|
Depth ttDepth;
|
2009-11-05 03:11:02 -07:00
|
|
|
|
2014-11-18 03:57:57 -07:00
|
|
|
if (PvNode)
|
|
|
|
{
|
|
|
|
oldAlpha = alpha; // To flag BOUND_EXACT when eval above alpha and no available moves
|
|
|
|
(ss+1)->pv = pv;
|
|
|
|
ss->pv[0] = MOVE_NONE;
|
2014-11-12 14:13:55 -07:00
|
|
|
}
|
|
|
|
|
2012-02-20 06:21:25 -07:00
|
|
|
ss->currentMove = bestMove = MOVE_NONE;
|
2011-04-16 07:41:53 -06:00
|
|
|
ss->ply = (ss-1)->ply + 1;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2013-12-02 11:04:09 -07:00
|
|
|
// Check for an instant draw or if the maximum ply has been reached
|
Cleanup MAX_PLY
This area has become obscure and tricky over the course of incremental
changes that did not respect the original's consistency and clarity. Now,
it's not clear why we use MAX_PLY = 120, or why we use MAX_PLY+6, among
other things.
This patch does the following:
* ID loop: depth ranges from 1 to MAX_PLY-1, and due to TT constraint (depth
must fit into an int8_t), MAX_PLY should be 128.
* stack[]: plies now range from 0 to MAX_PLY-1, hence stack[MAX_PLY+4],
because of the extra 2+2 padding elements (for ss-2 and ss+2). Document this
better, while we're at it.
* Enforce 0 <= ply < MAX_PLY:
- stop condition is now ss->ply >= MAX_PLY and not ss->ply > MAX_PLY.
- assert(ss->ply < MAX_PLY), before using ss+1 and ss+2.
- as a result, we don't need the artificial MAX_PLY+6 range. Instead we
can use MAX_PLY+4 and it's clear why (for ss-2 and ss+2).
* fix: extract_pv_from_tt() and insert_pv_in_tt() had no reason to use
MAX_PLY_PLUS_6, because the array is indexed by plies, so the range of
available plies applies (0..MAX_PLY before, and now 0..MAX_PLY-1).
Tested with debug compile, using MAX_PLY=16, and running bench at depth 17,
using 1 and 7 threads. No assert() fired. Feel free to submit to more severe
crash-tests, if you can think of any.
No functional change.
2014-11-03 08:36:24 -07:00
|
|
|
if (pos.is_draw() || ss->ply >= MAX_PLY)
|
2015-10-23 23:27:24 -06:00
|
|
|
return ss->ply >= MAX_PLY && !InCheck ? evaluate(pos)
|
|
|
|
: DrawValue[pos.side_to_move()];
|
Cleanup MAX_PLY
This area has become obscure and tricky over the course of incremental
changes that did not respect the original's consistency and clarity. Now,
it's not clear why we use MAX_PLY = 120, or why we use MAX_PLY+6, among
other things.
This patch does the following:
* ID loop: depth ranges from 1 to MAX_PLY-1, and due to TT constraint (depth
must fit into an int8_t), MAX_PLY should be 128.
* stack[]: plies now range from 0 to MAX_PLY-1, hence stack[MAX_PLY+4],
because of the extra 2+2 padding elements (for ss-2 and ss+2). Document this
better, while we're at it.
* Enforce 0 <= ply < MAX_PLY:
- stop condition is now ss->ply >= MAX_PLY and not ss->ply > MAX_PLY.
- assert(ss->ply < MAX_PLY), before using ss+1 and ss+2.
- as a result, we don't need the artificial MAX_PLY+6 range. Instead we
can use MAX_PLY+4 and it's clear why (for ss-2 and ss+2).
* fix: extract_pv_from_tt() and insert_pv_in_tt() had no reason to use
MAX_PLY_PLUS_6, because the array is indexed by plies, so the range of
available plies applies (0..MAX_PLY before, and now 0..MAX_PLY-1).
Tested with debug compile, using MAX_PLY=16, and running bench at depth 17,
using 1 and 7 threads. No assert() fired. Feel free to submit to more severe
crash-tests, if you can think of any.
No functional change.
2014-11-03 08:36:24 -07:00
|
|
|
|
|
|
|
assert(0 <= ss->ply && ss->ply < MAX_PLY);
|
2011-07-19 20:31:50 -06:00
|
|
|
|
2013-12-02 11:04:09 -07:00
|
|
|
// Decide whether or not to include checks: this fixes also the type of
|
2013-03-11 08:18:15 -06:00
|
|
|
// TT entry depth that we are going to use. Note that in qsearch we use
|
|
|
|
// only two types of depth in TT: DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS.
|
|
|
|
ttDepth = InCheck || depth >= DEPTH_QS_CHECKS ? DEPTH_QS_CHECKS
|
|
|
|
: DEPTH_QS_NO_CHECKS;
|
|
|
|
|
2013-06-30 05:12:04 -06:00
|
|
|
// Transposition table lookup
|
2012-10-07 01:34:04 -06:00
|
|
|
posKey = pos.key();
|
2014-12-13 00:16:35 -07:00
|
|
|
tte = TT.probe(posKey, ttHit);
|
|
|
|
ttMove = ttHit ? tte->move() : MOVE_NONE;
|
|
|
|
ttValue = ttHit ? value_from_tt(tte->value(), ss->ply) : VALUE_NONE;
|
2012-10-07 01:34:04 -06:00
|
|
|
|
2014-11-18 03:57:57 -07:00
|
|
|
if ( !PvNode
|
2014-12-13 00:16:35 -07:00
|
|
|
&& ttHit
|
2012-12-15 03:11:38 -07:00
|
|
|
&& tte->depth() >= ttDepth
|
|
|
|
&& ttValue != VALUE_NONE // Only in case of TT access race
|
2014-11-12 14:13:55 -07:00
|
|
|
&& (ttValue >= beta ? (tte->bound() & BOUND_LOWER)
|
|
|
|
: (tte->bound() & BOUND_UPPER)))
|
2009-03-21 07:51:31 -06:00
|
|
|
{
|
2012-12-15 03:11:38 -07:00
|
|
|
ss->currentMove = ttMove; // Can be MOVE_NONE
|
|
|
|
return ttValue;
|
2009-03-21 07:51:31 -06:00
|
|
|
}
|
2008-09-08 23:37:46 -06:00
|
|
|
|
2009-11-28 03:52:13 -07:00
|
|
|
// Evaluate the position statically
|
2012-11-01 07:49:54 -06:00
|
|
|
if (InCheck)
|
2010-05-22 02:56:46 -06:00
|
|
|
{
|
2013-11-08 03:42:22 -07:00
|
|
|
ss->staticEval = VALUE_NONE;
|
2010-06-03 11:29:48 -06:00
|
|
|
bestValue = futilityBase = -VALUE_INFINITE;
|
2010-05-22 02:56:46 -06:00
|
|
|
}
|
2009-03-24 08:48:14 -06:00
|
|
|
else
|
2010-01-21 08:58:00 -07:00
|
|
|
{
|
2014-12-13 00:16:35 -07:00
|
|
|
if (ttHit)
|
2012-12-27 04:13:31 -07:00
|
|
|
{
|
2012-12-31 08:28:40 -07:00
|
|
|
// Never assume anything on values stored in TT
|
2015-01-09 04:35:44 -07:00
|
|
|
if ((ss->staticEval = bestValue = tte->eval()) == VALUE_NONE)
|
2014-06-06 01:35:34 -06:00
|
|
|
ss->staticEval = bestValue = evaluate(pos);
|
2013-10-07 01:10:48 -06:00
|
|
|
|
|
|
|
// Can ttValue be used as a better position evaluation?
|
|
|
|
if (ttValue != VALUE_NONE)
|
|
|
|
if (tte->bound() & (ttValue > bestValue ? BOUND_LOWER : BOUND_UPPER))
|
|
|
|
bestValue = ttValue;
|
2012-12-27 04:13:31 -07:00
|
|
|
}
|
2012-12-01 10:06:29 -07:00
|
|
|
else
|
2014-06-06 03:12:05 -06:00
|
|
|
ss->staticEval = bestValue =
|
2015-10-23 23:27:24 -06:00
|
|
|
(ss-1)->currentMove != MOVE_NULL ? evaluate(pos)
|
|
|
|
: -(ss-1)->staticEval + 2 * Eval::Tempo;
|
2010-01-21 08:58:00 -07:00
|
|
|
|
2010-06-03 11:29:48 -06:00
|
|
|
// Stand pat. Return immediately if static value is at least beta
|
|
|
|
if (bestValue >= beta)
|
|
|
|
{
|
2014-12-13 00:16:35 -07:00
|
|
|
if (!ttHit)
|
|
|
|
tte->save(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER,
|
2014-12-13 01:27:39 -07:00
|
|
|
DEPTH_NONE, MOVE_NONE, ss->staticEval, TT.generation());
|
2010-06-04 01:46:38 -06:00
|
|
|
|
2010-06-03 11:29:48 -06:00
|
|
|
return bestValue;
|
|
|
|
}
|
2009-03-27 08:30:45 -06:00
|
|
|
|
2010-06-03 11:29:48 -06:00
|
|
|
if (PvNode && bestValue > alpha)
|
|
|
|
alpha = bestValue;
|
2008-09-07 00:31:30 -06:00
|
|
|
|
2014-04-27 02:13:59 -06:00
|
|
|
futilityBase = bestValue + 128;
|
2010-06-03 11:29:48 -06:00
|
|
|
}
|
2010-01-19 07:24:26 -07:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
// Initialize a MovePicker object for the current position, and prepare
|
2010-01-19 07:24:26 -07:00
|
|
|
// to search the moves. Because the depth is <= 0 here, only captures,
|
2010-12-18 02:27:24 -07:00
|
|
|
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
|
|
|
|
// be generated.
|
2016-04-17 08:14:07 -06:00
|
|
|
MovePicker mp(pos, ttMove, depth, to_sq((ss-1)->currentMove));
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2010-03-24 03:15:00 -06:00
|
|
|
// Loop through the moves until no moves remain or a beta cutoff occurs
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
while ((move = mp.next_move()) != MOVE_NONE)
|
2008-09-07 00:31:30 -06:00
|
|
|
{
|
2011-10-03 02:56:49 -06:00
|
|
|
assert(is_ok(move));
|
2008-09-07 00:31:30 -06:00
|
|
|
|
2016-07-03 02:35:44 -06:00
|
|
|
givesCheck = type_of(move) == NORMAL && !pos.discovered_check_candidates()
|
2016-08-27 02:05:42 -06:00
|
|
|
? pos.check_squares(type_of(pos.piece_on(from_sq(move)))) & to_sq(move)
|
2016-07-03 02:35:44 -06:00
|
|
|
: pos.gives_check(move);
|
2010-01-08 03:45:46 -07:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
// Futility pruning
|
2015-01-14 13:18:41 -07:00
|
|
|
if ( !InCheck
|
2011-04-29 08:26:48 -06:00
|
|
|
&& !givesCheck
|
2013-08-24 02:05:48 -06:00
|
|
|
&& futilityBase > -VALUE_KNOWN_WIN
|
2013-12-03 14:58:39 -07:00
|
|
|
&& !pos.advanced_pawn_push(move))
|
2008-09-07 00:31:30 -06:00
|
|
|
{
|
2013-12-04 08:49:01 -07:00
|
|
|
assert(type_of(move) != ENPASSANT); // Due to !pos.advanced_pawn_push
|
|
|
|
|
|
|
|
futilityValue = futilityBase + PieceValue[EG][pos.piece_on(to_sq(move))];
|
2008-09-07 00:31:30 -06:00
|
|
|
|
2015-01-14 13:18:41 -07:00
|
|
|
if (futilityValue <= alpha)
|
2008-09-07 00:31:30 -06:00
|
|
|
{
|
2012-11-26 08:13:36 -07:00
|
|
|
bestValue = std::max(bestValue, futilityValue);
|
2008-09-07 00:31:30 -06:00
|
|
|
continue;
|
|
|
|
}
|
2011-02-22 15:23:45 -07:00
|
|
|
|
2015-01-14 13:18:41 -07:00
|
|
|
if (futilityBase <= alpha && pos.see(move) <= VALUE_ZERO)
|
2012-11-26 08:13:36 -07:00
|
|
|
{
|
|
|
|
bestValue = std::max(bestValue, futilityBase);
|
2011-02-22 15:23:45 -07:00
|
|
|
continue;
|
2012-11-26 08:13:36 -07:00
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2013-12-02 11:04:09 -07:00
|
|
|
// Detect non-capture evasions that are candidates to be pruned
|
2013-07-13 05:27:22 -06:00
|
|
|
evasionPrunable = InCheck
|
2012-04-28 04:08:10 -06:00
|
|
|
&& bestValue > VALUE_MATED_IN_MAX_PLY
|
2015-04-03 18:00:15 -06:00
|
|
|
&& !pos.capture(move);
|
2010-01-20 03:40:33 -07:00
|
|
|
|
|
|
|
// Don't search moves with negative SEE values
|
2015-01-14 13:18:41 -07:00
|
|
|
if ( (!InCheck || evasionPrunable)
|
2012-06-24 03:08:16 -06:00
|
|
|
&& type_of(move) != PROMOTION
|
2014-02-16 05:06:31 -07:00
|
|
|
&& pos.see_sign(move) < VALUE_ZERO)
|
2008-09-07 00:31:30 -06:00
|
|
|
continue;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-10-03 22:07:55 -06:00
|
|
|
// Speculative prefetch as early as possible
|
2015-02-07 11:13:41 -07:00
|
|
|
prefetch(TT.first_entry(pos.key_after(move)));
|
2014-10-02 15:19:14 -06:00
|
|
|
|
2013-12-02 11:04:09 -07:00
|
|
|
// Check for legality just before making the move
|
2016-07-03 02:35:44 -06:00
|
|
|
if (!pos.legal(move))
|
2011-05-23 07:14:47 -06:00
|
|
|
continue;
|
|
|
|
|
2010-06-03 11:29:48 -06:00
|
|
|
ss->currentMove = move;
|
|
|
|
|
2009-11-05 03:11:02 -07:00
|
|
|
// Make and search the move
|
Compute checkers from scratch
This micro-optimization only complicates the code and provides no benefit.
Removing it is even a speedup on my machine (i7-3770k, linux, gcc 4.9.1):
stat test master diff
mean 2,403,118 2,390,904 12,214
stdev 12,043 10,620 3,677
speedup 0.51%
P(speedup>0) 100.0%
No functional change.
2015-02-15 00:49:20 -07:00
|
|
|
pos.do_move(move, st, givesCheck);
|
2012-11-01 07:49:54 -06:00
|
|
|
value = givesCheck ? -qsearch<NT, true>(pos, ss+1, -beta, -alpha, depth - ONE_PLY)
|
|
|
|
: -qsearch<NT, false>(pos, ss+1, -beta, -alpha, depth - ONE_PLY);
|
2009-02-22 09:49:52 -07:00
|
|
|
pos.undo_move(move);
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
|
|
|
|
|
2016-01-16 14:34:29 -07:00
|
|
|
// Check for a new best move
|
2008-09-07 00:31:30 -06:00
|
|
|
if (value > bestValue)
|
|
|
|
{
|
|
|
|
bestValue = value;
|
2011-08-07 03:29:47 -06:00
|
|
|
|
2012-10-07 01:34:04 -06:00
|
|
|
if (value > alpha)
|
|
|
|
{
|
2014-11-21 01:10:52 -07:00
|
|
|
if (PvNode) // Update pv even in fail-high case
|
2014-11-18 03:57:57 -07:00
|
|
|
update_pv(ss->pv, move, (ss+1)->pv);
|
2014-11-12 14:13:55 -07:00
|
|
|
|
2015-10-23 23:27:24 -06:00
|
|
|
if (PvNode && value < beta) // Update alpha here!
|
2012-10-07 01:34:04 -06:00
|
|
|
{
|
|
|
|
alpha = value;
|
|
|
|
bestMove = move;
|
|
|
|
}
|
|
|
|
else // Fail high
|
|
|
|
{
|
2014-12-13 00:16:35 -07:00
|
|
|
tte->save(posKey, value_to_tt(value, ss->ply), BOUND_LOWER,
|
2014-12-13 01:27:39 -07:00
|
|
|
ttDepth, move, ss->staticEval, TT.generation());
|
2012-12-27 04:13:31 -07:00
|
|
|
|
2012-10-07 01:34:04 -06:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
2008-09-07 00:31:30 -06:00
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2010-01-08 03:45:46 -07:00
|
|
|
// All legal moves have been searched. A special case: If we're in check
|
2009-06-11 07:57:42 -06:00
|
|
|
// and no legal moves were found, it is checkmate.
|
2012-11-01 07:49:54 -06:00
|
|
|
if (InCheck && bestValue == -VALUE_INFINITE)
|
2011-12-28 05:22:09 -07:00
|
|
|
return mated_in(ss->ply); // Plies to mate from the root
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-12-13 00:16:35 -07:00
|
|
|
tte->save(posKey, value_to_tt(bestValue, ss->ply),
|
|
|
|
PvNode && bestValue > oldAlpha ? BOUND_EXACT : BOUND_UPPER,
|
2014-12-13 01:27:39 -07:00
|
|
|
ttDepth, bestMove, ss->staticEval, TT.generation());
|
2009-09-18 02:32:57 -06:00
|
|
|
|
2010-01-08 03:45:46 -07:00
|
|
|
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
|
2009-04-18 07:03:33 -06:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
return bestValue;
|
|
|
|
}
|
|
|
|
|
2010-12-14 06:49:06 -07:00
|
|
|
|
2012-10-27 06:25:31 -06:00
|
|
|
// value_to_tt() adjusts a mate score from "plies to mate from the root" to
|
|
|
|
// "plies to mate from the current position". Non-mate scores are unchanged.
|
2013-12-02 11:04:09 -07:00
|
|
|
// The function is called before storing a value in the transposition table.
|
2012-10-27 06:25:31 -06:00
|
|
|
|
|
|
|
Value value_to_tt(Value v, int ply) {
|
|
|
|
|
|
|
|
assert(v != VALUE_NONE);
|
|
|
|
|
|
|
|
return v >= VALUE_MATE_IN_MAX_PLY ? v + ply
|
|
|
|
: v <= VALUE_MATED_IN_MAX_PLY ? v - ply : v;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score
|
2013-12-02 11:04:09 -07:00
|
|
|
// from the transposition table (which refers to the plies to mate/be mated
|
2012-10-27 06:25:31 -06:00
|
|
|
// from current position) to "plies to mate/be mated from the root".
|
|
|
|
|
|
|
|
Value value_from_tt(Value v, int ply) {
|
|
|
|
|
|
|
|
return v == VALUE_NONE ? VALUE_NONE
|
|
|
|
: v >= VALUE_MATE_IN_MAX_PLY ? v - ply
|
|
|
|
: v <= VALUE_MATED_IN_MAX_PLY ? v + ply : v;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-21 01:10:52 -07:00
|
|
|
// update_pv() adds current move and appends child pv[]
|
2014-11-18 03:57:57 -07:00
|
|
|
|
2014-11-21 01:10:52 -07:00
|
|
|
void update_pv(Move* pv, Move move, Move* childPv) {
|
2014-11-18 03:57:57 -07:00
|
|
|
|
2014-11-21 01:10:52 -07:00
|
|
|
for (*pv++ = move; childPv && *childPv != MOVE_NONE; )
|
|
|
|
*pv++ = *childPv++;
|
2014-11-18 03:57:57 -07:00
|
|
|
*pv = MOVE_NONE;
|
|
|
|
}
|
|
|
|
|
2014-01-05 06:08:26 -07:00
|
|
|
|
2016-08-26 11:47:40 -06:00
|
|
|
// update_cm_stats() updates countermove and follow-up move history
|
2014-01-05 06:08:26 -07:00
|
|
|
|
2016-08-26 11:47:40 -06:00
|
|
|
void update_cm_stats(Stack* ss, Piece pc, Square s, Value bonus) {
|
2016-08-23 07:57:56 -06:00
|
|
|
|
2016-08-26 11:47:40 -06:00
|
|
|
CounterMoveStats* cmh = (ss-1)->counterMoves;
|
|
|
|
CounterMoveStats* fmh1 = (ss-2)->counterMoves;
|
|
|
|
CounterMoveStats* fmh2 = (ss-4)->counterMoves;
|
2016-08-23 07:57:56 -06:00
|
|
|
|
2016-08-24 08:52:05 -06:00
|
|
|
if (cmh)
|
2016-08-26 11:47:40 -06:00
|
|
|
cmh->update(pc, s, bonus);
|
2016-08-23 07:57:56 -06:00
|
|
|
|
2016-08-24 08:52:05 -06:00
|
|
|
if (fmh1)
|
2016-08-26 11:47:40 -06:00
|
|
|
fmh1->update(pc, s, bonus);
|
2016-08-23 07:57:56 -06:00
|
|
|
|
2016-08-24 08:52:05 -06:00
|
|
|
if (fmh2)
|
2016-08-26 11:47:40 -06:00
|
|
|
fmh2->update(pc, s, bonus);
|
2016-08-24 08:52:05 -06:00
|
|
|
}
|
2016-08-23 07:57:56 -06:00
|
|
|
|
2016-08-24 08:52:05 -06:00
|
|
|
|
|
|
|
// update_stats() updates killers, history, countermove and countermove plus
|
|
|
|
// follow-up move history when a new quiet best move is found.
|
|
|
|
|
|
|
|
void update_stats(const Position& pos, Stack* ss, Move move,
|
|
|
|
Move* quiets, int quietsCnt, Value bonus) {
|
2016-08-23 07:57:56 -06:00
|
|
|
|
2014-01-05 06:08:26 -07:00
|
|
|
if (ss->killers[0] != move)
|
|
|
|
{
|
|
|
|
ss->killers[1] = ss->killers[0];
|
|
|
|
ss->killers[0] = move;
|
|
|
|
}
|
2016-08-12 11:55:12 -06:00
|
|
|
|
2016-08-23 07:57:56 -06:00
|
|
|
Color c = pos.side_to_move();
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
Thread* thisThread = pos.this_thread();
|
2016-07-25 07:53:18 -06:00
|
|
|
thisThread->fromTo.update(c, move, bonus);
|
2016-08-26 11:47:40 -06:00
|
|
|
thisThread->history.update(pos.moved_piece(move), to_sq(move), bonus);
|
|
|
|
update_cm_stats(ss, pos.moved_piece(move), to_sq(move), bonus);
|
2015-01-31 02:43:47 -07:00
|
|
|
|
2016-08-26 11:47:40 -06:00
|
|
|
if ((ss-1)->counterMoves)
|
2014-01-05 06:08:26 -07:00
|
|
|
{
|
2016-08-24 08:52:05 -06:00
|
|
|
Square prevSq = to_sq((ss-1)->currentMove);
|
2015-10-23 23:27:24 -06:00
|
|
|
thisThread->counterMoves.update(pos.piece_on(prevSq), prevSq, move);
|
2014-01-05 06:08:26 -07:00
|
|
|
}
|
|
|
|
|
2015-03-15 03:05:57 -06:00
|
|
|
// Decrease all the other played quiet moves
|
|
|
|
for (int i = 0; i < quietsCnt; ++i)
|
2014-01-05 06:08:26 -07:00
|
|
|
{
|
2016-07-25 07:53:18 -06:00
|
|
|
thisThread->fromTo.update(c, quiets[i], -bonus);
|
2016-08-26 11:47:40 -06:00
|
|
|
thisThread->history.update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
|
|
|
update_cm_stats(ss, pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
2014-01-05 06:08:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-25 03:07:43 -07:00
|
|
|
// When playing with strength handicap, choose best move among a set of RootMoves
|
|
|
|
// using a statistical rule dependent on 'level'. Idea by Heinz van Saanen.
|
2010-07-15 03:00:20 -06:00
|
|
|
|
2015-01-25 03:07:43 -07:00
|
|
|
Move Skill::pick_best(size_t multiPV) {
|
2010-07-15 03:00:20 -06:00
|
|
|
|
2016-04-11 08:45:36 -06:00
|
|
|
const RootMoves& rootMoves = Threads.main()->rootMoves;
|
2015-10-25 01:30:07 -06:00
|
|
|
static PRNG rng(now()); // PRNG sequence should be non-deterministic
|
2010-07-15 03:00:20 -06:00
|
|
|
|
2012-07-15 01:14:25 -06:00
|
|
|
// RootMoves are already sorted by score in descending order
|
2015-10-25 01:30:07 -06:00
|
|
|
Value topScore = rootMoves[0].score;
|
|
|
|
int delta = std::min(topScore - rootMoves[multiPV - 1].score, PawnValueMg);
|
2012-10-24 04:05:20 -06:00
|
|
|
int weakness = 120 - 2 * level;
|
2014-12-07 16:53:33 -07:00
|
|
|
int maxScore = -VALUE_INFINITE;
|
2012-07-15 01:14:25 -06:00
|
|
|
|
2015-10-25 01:30:07 -06:00
|
|
|
// Choose best move. For each move score we add two terms, both dependent on
|
2016-01-16 01:03:56 -07:00
|
|
|
// weakness. One is deterministic and bigger for weaker levels, and one is
|
2016-01-16 14:34:29 -07:00
|
|
|
// random. Then we choose the move with the resulting highest score.
|
2015-01-25 03:07:43 -07:00
|
|
|
for (size_t i = 0; i < multiPV; ++i)
|
2012-07-15 01:14:25 -06:00
|
|
|
{
|
|
|
|
// This is our magic formula
|
2015-10-25 01:30:07 -06:00
|
|
|
int push = ( weakness * int(topScore - rootMoves[i].score)
|
|
|
|
+ delta * (rng.rand<unsigned>() % weakness)) / 128;
|
2012-07-15 01:14:25 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
if (rootMoves[i].score + push > maxScore)
|
2012-07-15 01:14:25 -06:00
|
|
|
{
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
maxScore = rootMoves[i].score + push;
|
|
|
|
best = rootMoves[i].pv[0];
|
2012-07-15 01:14:25 -06:00
|
|
|
}
|
|
|
|
}
|
2015-10-25 01:30:07 -06:00
|
|
|
|
2012-07-15 01:14:25 -06:00
|
|
|
return best;
|
2010-07-15 03:00:20 -06:00
|
|
|
}
|
|
|
|
|
Get rid of timer thread
Unfortunately std::condition_variable::wait_for()
is not accurate in general case and the timer thread
can wake up also after tens or even hundreds of
millisecs after time has elapsded. CPU load, process
priorities, number of concurrent threads, even from
other processes, will have effect upon it.
Even official documentation says: "This function may
block for longer than timeout_duration due to scheduling
or resource contention delays."
So retire timer and use a polling scheme based on a
local thread counter that counts search() calls and
a small trick to keep polling frequency constant,
independently from the number of threads.
Tested for no regression at very fast TC 2+0.05 th 7:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 32969 W: 6720 L: 6620 D: 19629
TC 2+0.05 th 1:
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 7765 W: 1917 L: 1765 D: 4083
And at STC TC, both single thread
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 15587 W: 3036 L: 2905 D: 9646
And with 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 8149 W: 1367 L: 1227 D: 5555
bench: 8639247
2015-11-03 03:15:14 -07:00
|
|
|
|
|
|
|
// check_time() is used to print debug info and, more importantly, to detect
|
|
|
|
// when we are out of available time and thus stop the search.
|
|
|
|
|
|
|
|
void check_time() {
|
|
|
|
|
|
|
|
static TimePoint lastInfoTime = now();
|
|
|
|
|
|
|
|
int elapsed = Time.elapsed();
|
|
|
|
TimePoint tick = Limits.startTime + elapsed;
|
|
|
|
|
|
|
|
if (tick - lastInfoTime >= 1000)
|
|
|
|
{
|
|
|
|
lastInfoTime = tick;
|
|
|
|
dbg_print();
|
|
|
|
}
|
|
|
|
|
|
|
|
// An engine may not stop pondering until told so by the GUI
|
|
|
|
if (Limits.ponder)
|
|
|
|
return;
|
|
|
|
|
2015-12-09 00:07:34 -07:00
|
|
|
if ( (Limits.use_time_management() && elapsed > Time.maximum() - 10)
|
|
|
|
|| (Limits.movetime && elapsed >= Limits.movetime)
|
|
|
|
|| (Limits.nodes && Threads.nodes_searched() >= Limits.nodes))
|
Get rid of timer thread
Unfortunately std::condition_variable::wait_for()
is not accurate in general case and the timer thread
can wake up also after tens or even hundreds of
millisecs after time has elapsded. CPU load, process
priorities, number of concurrent threads, even from
other processes, will have effect upon it.
Even official documentation says: "This function may
block for longer than timeout_duration due to scheduling
or resource contention delays."
So retire timer and use a polling scheme based on a
local thread counter that counts search() calls and
a small trick to keep polling frequency constant,
independently from the number of threads.
Tested for no regression at very fast TC 2+0.05 th 7:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 32969 W: 6720 L: 6620 D: 19629
TC 2+0.05 th 1:
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 7765 W: 1917 L: 1765 D: 4083
And at STC TC, both single thread
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 15587 W: 3036 L: 2905 D: 9646
And with 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 8149 W: 1367 L: 1227 D: 5555
bench: 8639247
2015-11-03 03:15:14 -07:00
|
|
|
Signals.stop = true;
|
|
|
|
}
|
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
} // namespace
|
2011-01-01 06:13:15 -07:00
|
|
|
|
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
/// UCI::pv() formats PV information according to the UCI protocol. UCI requires
|
|
|
|
/// that all (if any) unsearched PV lines are sent using a previous search score.
|
2011-01-01 06:13:15 -07:00
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) {
|
2011-06-22 00:03:28 -06:00
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
std::stringstream ss;
|
2015-04-02 01:07:17 -06:00
|
|
|
int elapsed = Time.elapsed() + 1;
|
2016-04-11 08:45:36 -06:00
|
|
|
const RootMoves& rootMoves = pos.this_thread()->rootMoves;
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
size_t PVIdx = pos.this_thread()->PVIdx;
|
|
|
|
size_t multiPV = std::min((size_t)Options["MultiPV"], rootMoves.size());
|
|
|
|
uint64_t nodes_searched = Threads.nodes_searched();
|
2011-06-22 00:03:28 -06:00
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
for (size_t i = 0; i < multiPV; ++i)
|
|
|
|
{
|
|
|
|
bool updated = (i <= PVIdx);
|
2011-12-14 01:21:00 -07:00
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
if (depth == ONE_PLY && !updated)
|
|
|
|
continue;
|
2011-12-14 01:21:00 -07:00
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
Depth d = updated ? depth : depth - ONE_PLY;
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
Value v = updated ? rootMoves[i].score : rootMoves[i].previousScore;
|
2015-01-18 00:05:05 -07:00
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
bool tb = TB::RootInTB && abs(v) < VALUE_MATE - MAX_PLY;
|
|
|
|
v = tb ? TB::Score : v;
|
2012-07-14 06:19:16 -06:00
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
if (ss.rdbuf()->in_avail()) // Not at first line
|
|
|
|
ss << "\n";
|
2015-01-03 02:51:38 -07:00
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
ss << "info"
|
|
|
|
<< " depth " << d / ONE_PLY
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
<< " seldepth " << pos.this_thread()->maxPly
|
2015-01-31 03:54:25 -07:00
|
|
|
<< " multipv " << i + 1
|
|
|
|
<< " score " << UCI::value(v);
|
2015-01-03 02:51:38 -07:00
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
if (!tb && i == PVIdx)
|
|
|
|
ss << (v >= beta ? " lowerbound" : v <= alpha ? " upperbound" : "");
|
2011-12-14 01:21:00 -07:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
ss << " nodes " << nodes_searched
|
|
|
|
<< " nps " << nodes_searched * 1000 / elapsed;
|
2015-01-25 00:57:51 -07:00
|
|
|
|
2015-01-31 05:04:15 -07:00
|
|
|
if (elapsed > 1000) // Earlier makes little sense
|
2015-01-31 05:22:06 -07:00
|
|
|
ss << " hashfull " << TT.hashfull();
|
2011-12-14 01:21:00 -07:00
|
|
|
|
2015-01-31 05:04:15 -07:00
|
|
|
ss << " tbhits " << TB::Hits
|
2015-01-31 03:54:25 -07:00
|
|
|
<< " time " << elapsed
|
|
|
|
<< " pv";
|
2012-07-14 06:19:16 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
for (Move m : rootMoves[i].pv)
|
2015-01-31 03:54:25 -07:00
|
|
|
ss << " " << UCI::move(m, pos.is_chess960());
|
2011-06-22 00:03:28 -06:00
|
|
|
}
|
|
|
|
|
2015-01-31 03:54:25 -07:00
|
|
|
return ss.str();
|
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2010-12-29 03:00:32 -07:00
|
|
|
|
2015-10-25 01:30:07 -06:00
|
|
|
/// RootMove::extract_ponder_from_tt() is called in case we have no ponder move
|
2016-01-16 14:34:29 -07:00
|
|
|
/// before exiting the search, for instance, in case we stop the search during a
|
2015-10-25 01:30:07 -06:00
|
|
|
/// fail high at root. We try hard to have a ponder move to return to the GUI,
|
|
|
|
/// otherwise in case of 'ponder on' we have nothing to think on.
|
2015-01-20 01:13:30 -07:00
|
|
|
|
2015-01-31 04:31:00 -07:00
|
|
|
bool RootMove::extract_ponder_from_tt(Position& pos)
|
2015-01-20 01:13:30 -07:00
|
|
|
{
|
|
|
|
StateInfo st;
|
2015-01-31 04:31:00 -07:00
|
|
|
bool ttHit;
|
2015-01-20 01:13:30 -07:00
|
|
|
|
|
|
|
assert(pv.size() == 1);
|
|
|
|
|
2016-07-03 02:35:44 -06:00
|
|
|
pos.do_move(pv[0], st, pos.gives_check(pv[0]));
|
2015-01-31 04:31:00 -07:00
|
|
|
TTEntry* tte = TT.probe(pos.key(), ttHit);
|
|
|
|
|
|
|
|
if (ttHit)
|
|
|
|
{
|
|
|
|
Move m = tte->move(); // Local copy to be SMP safe
|
|
|
|
if (MoveList<LEGAL>(pos).contains(m))
|
2016-07-09 13:01:42 -06:00
|
|
|
pv.push_back(m);
|
2015-01-31 04:31:00 -07:00
|
|
|
}
|
|
|
|
|
2016-07-09 13:01:42 -06:00
|
|
|
pos.undo_move(pv[0]);
|
|
|
|
return pv.size() > 1;
|
2015-01-20 01:13:30 -07:00
|
|
|
}
|
2016-06-03 23:53:29 -06:00
|
|
|
|
|
|
|
void Tablebases::filter_root_moves(Position& pos, Search::RootMoves& rootMoves) {
|
|
|
|
|
|
|
|
Hits = 0;
|
|
|
|
RootInTB = false;
|
|
|
|
UseRule50 = Options["Syzygy50MoveRule"];
|
|
|
|
ProbeDepth = Options["SyzygyProbeDepth"] * ONE_PLY;
|
|
|
|
Cardinality = Options["SyzygyProbeLimit"];
|
|
|
|
|
|
|
|
// Skip TB probing when no TB found: !TBLargest -> !TB::Cardinality
|
|
|
|
if (Cardinality > MaxCardinality)
|
|
|
|
{
|
|
|
|
Cardinality = MaxCardinality;
|
|
|
|
ProbeDepth = DEPTH_ZERO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cardinality < popcount(pos.pieces()) || pos.can_castle(ANY_CASTLING))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If the current root position is in the tablebases, then RootMoves
|
|
|
|
// contains only moves that preserve the draw or the win.
|
|
|
|
RootInTB = root_probe(pos, rootMoves, TB::Score);
|
|
|
|
|
|
|
|
if (RootInTB)
|
|
|
|
Cardinality = 0; // Do not probe tablebases during the search
|
|
|
|
|
|
|
|
else // If DTZ tables are missing, use WDL tables as a fallback
|
|
|
|
{
|
|
|
|
// Filter out moves that do not preserve the draw or the win.
|
|
|
|
RootInTB = root_probe_wdl(pos, rootMoves, TB::Score);
|
|
|
|
|
|
|
|
// Only probe during search if winning
|
2016-09-03 00:19:17 -06:00
|
|
|
if (RootInTB && TB::Score <= VALUE_DRAW)
|
2016-06-03 23:53:29 -06:00
|
|
|
Cardinality = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RootInTB)
|
|
|
|
{
|
|
|
|
Hits = rootMoves.size();
|
|
|
|
|
|
|
|
if (!UseRule50)
|
|
|
|
TB::Score = TB::Score > VALUE_DRAW ? VALUE_MATE - MAX_PLY - 1
|
|
|
|
: TB::Score < VALUE_DRAW ? -VALUE_MATE + MAX_PLY + 1
|
|
|
|
: VALUE_DRAW;
|
|
|
|
}
|
|
|
|
}
|