Skip to content

Commit b179258

Browse files
authored
3.2.2: show pv from the best smp thread (#269)
http://chess.grantnet.us/test/30094/ ELO | 1.38 +- 2.92 (95%) SPRT | 10.0+0.10s Threads=1 Hash=8MB LLR | 2.97 (-2.94, 2.94) [-3.00, 1.00] GAMES | N: 28216 W: 7391 L: 7279 D: 13546 http://chess.grantnet.us/test/30100/ ELO | -0.06 +- 2.11 (95%) SPRT | 5.0+0.05s Threads=8 Hash=64MB LLR | 1.82 (-2.94, 2.94) [-3.00, 1.00] GAMES | N: 52650 W: 13349 L: 13358 D: 25943 BENCH: 3925018
1 parent c491dc7 commit b179258

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

src/search.cpp

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ Search::Search() :
5555
m_depth(0),
5656
m_syzygyDepth(0),
5757
m_selDepth(0),
58-
m_iterPVSize(0),
5958
m_principalSearcher(false),
6059
m_thc(0),
6160
m_threads(nullptr),
@@ -964,7 +963,6 @@ void Search::startPrincipalSearch(Time time, bool ponder)
964963

965964
uint64_t Search::startSearch(Time time, int depth, bool ponderSearch, bool bench)
966965
{
967-
m_iterPVSize = 0;
968966
m_nodes = 0;
969967
m_selDepth = 0;
970968
m_tbHits = 0;
@@ -989,6 +987,8 @@ uint64_t Search::startSearch(Time time, int depth, bool ponderSearch, bool bench
989987
}
990988
}
991989

990+
memset(m_pvPrev, 0, sizeof(m_pvPrev));
991+
memset(m_pvSizePrev, 0, sizeof(m_pvSizePrev));
992992
memset(&m_pv, 0, sizeof(m_pv));
993993
m_time.resetAdjustment();
994994

@@ -1067,8 +1067,7 @@ uint64_t Search::startSearch(Time time, int depth, bool ponderSearch, bool bench
10671067
uint64_t sumHits = 0;
10681068
uint64_t nps = 0;
10691069

1070-
for (m_depth = depth; m_depth < maxDepth; ++m_depth)
1071-
{
1070+
for (m_depth = depth; m_depth < maxDepth; ++m_depth) {
10721071
//
10731072
// Make a search
10741073
//
@@ -1085,14 +1084,15 @@ uint64_t Search::startSearch(Time time, int depth, bool ponderSearch, bool bench
10851084
break;
10861085

10871086
m_score = score;
1088-
memcpy(m_iterPV, m_pv[0], m_pvSize[0] * sizeof(Move));
1089-
m_iterPVSize = m_pvSize[0];
10901087

1091-
if (m_iterPVSize && m_pv[0][0]) {
1088+
if (m_pvSize[0] && m_pv[0][0]) {
10921089
m_best = m_pv[0][0];
10931090

1094-
if (m_iterPVSize > 1 && m_pv[0][1])
1091+
if (m_pvSize[0] > 1 && m_pv[0][1]) {
10951092
m_ponder = m_pv[0][1];
1093+
memcpy(m_pvPrev, m_pv, sizeof(m_pv));
1094+
memcpy(m_pvSizePrev, m_pvSize, sizeof(m_pvSize));
1095+
}
10961096
else
10971097
m_ponder = 0;
10981098
}
@@ -1160,10 +1160,7 @@ uint64_t Search::startSearch(Time time, int depth, bool ponderSearch, bool bench
11601160
// Pickup the best thread based on eval/depth
11611161
//
11621162

1163-
std::map<Move, std::pair<int64_t, Move>> votes;
11641163
auto worst = m_score;
1165-
int64_t bestSoFar = (static_cast<int64_t>(m_score) - static_cast<int64_t>(worst) + 20) * static_cast<int64_t>(m_depth);
1166-
votes[m_best] = std::make_pair(bestSoFar, m_ponder);
11671164

11681165
//
11691166
// Calculate worst score yet
@@ -1172,37 +1169,63 @@ uint64_t Search::startSearch(Time time, int depth, bool ponderSearch, bool bench
11721169
for (unsigned int i = 0; i < m_thc; ++i)
11731170
worst = std::min(worst, m_threadParams[i].m_score);
11741171

1172+
int64_t bestSoFar = (static_cast<int64_t>(m_score) - static_cast<int64_t>(worst) + 20) * static_cast<int64_t>(m_depth);
1173+
1174+
typedef struct tagStat {
1175+
tagStat(Move p, EVAL s, int d, int sd, const Move* pv_, int pvSize_) {
1176+
ponder = p;
1177+
score = s;
1178+
depth = d;
1179+
selDepth = sd;
1180+
pvSize = pvSize_;
1181+
memcpy(pv, pv_, pvSize * sizeof(Move));
1182+
}
1183+
tagStat() {
1184+
ponder = 0;
1185+
score = 0;
1186+
depth = 0;
1187+
selDepth = 0;
1188+
pvSize = 0;
1189+
memset(pv, 0, sizeof(pv));
1190+
}
1191+
Move ponder;
1192+
EVAL score;
1193+
int depth;
1194+
int selDepth;
1195+
Move pv[MAX_PLY];
1196+
int pvSize;
1197+
}Stat;
1198+
1199+
std::map<Move, std::pair<int64_t, Stat>> votes;
1200+
votes[m_best] = std::make_pair(bestSoFar, Stat{ m_ponder, m_score, m_depth, m_selDepth, m_pvPrev[0], m_pvSizePrev[0] });
1201+
11751202
//
11761203
// Calculate the voting map
11771204
//
11781205

11791206
for (unsigned int i = 0; i < m_thc; ++i) {
11801207
votes[m_threadParams[i].m_best].first += (static_cast<int64_t>(m_threadParams[i].m_score) - static_cast<int64_t>(worst) + 20) * static_cast<int64_t>(m_threadParams[i].m_depth);
1181-
votes[m_threadParams[i].m_best].second = m_threadParams[i].m_ponder;
1208+
votes[m_threadParams[i].m_best].second = Stat{ m_threadParams[i].m_ponder , m_threadParams[i].m_score, m_threadParams[i].m_depth, m_threadParams[i].m_selDepth, m_threadParams[i].m_pvPrev[0], m_threadParams[i].m_pvSizePrev[0] };
11821209
}
11831210

11841211
//
11851212
// Democracy in action: pick-up the most voted best based on highest score
11861213
//
11871214

11881215
for (const auto & vote : votes) {
1189-
if (vote.second.first > bestSoFar) { // select move with highest score
1190-
bestSoFar = vote.second.first; // memorize highest score so far
1191-
m_best = vote.first; // store the best move
1192-
m_ponder = vote.second.second; // store the best ponder
1216+
if (vote.first && (vote.second.first > bestSoFar)) { // select move with highest score
1217+
bestSoFar = vote.second.first; // memorize highest score so far
1218+
m_best = vote.first; // store the best move
1219+
m_ponder = vote.second.second.ponder; // store the best ponder
1220+
m_score = vote.second.second.score; // store statistics
1221+
m_depth = std::max(m_depth, vote.second.second.depth);
1222+
m_selDepth = std::max(m_selDepth, vote.second.second.selDepth);
1223+
m_pvSizePrev[0] = vote.second.second.pvSize;
1224+
memcpy(m_pvPrev[0], vote.second.second.pv, m_pvSizePrev[0] * sizeof(Move));
11931225
}
11941226
}
11951227

1196-
//
1197-
// In case bestmove changes, print pv/depth/score from a better thread
1198-
//
1199-
1200-
for (unsigned int i = 1; i < m_thc; ++i) {
1201-
if (m_best == m_threadParams[i].m_best && m_ponder == m_threadParams[i].m_ponder) {
1202-
printPV(m_position, std::max(m_depth, m_threadParams[i].m_depth), std::max(m_selDepth, m_threadParams[i].m_selDepth), m_threadParams[i].m_score, m_threadParams[i].m_pv[0], m_threadParams[i].m_pvSize[0], m_threadParams[i].m_best, sumNodes, sumHits, nps);
1203-
break;
1204-
}
1205-
}
1228+
printPV(m_position, m_depth, m_selDepth, m_score, m_pvPrev[0], m_pvSizePrev[0], m_best, sumNodes, sumHits, nps);
12061229
}
12071230

12081231
//

src/search.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ class Search
111111
int m_depth;
112112
int m_syzygyDepth;
113113
int m_selDepth;
114-
int m_iterPVSize;
115114
MoveList m_lists[MAX_PLY];
116115
Move m_pv[MAX_PLY][MAX_PLY];
117116
int m_pvSize[MAX_PLY];
118-
Move m_iterPV[MAX_PLY];
117+
Move m_pvPrev[MAX_PLY][MAX_PLY];
118+
int m_pvSizePrev[MAX_PLY];
119119
Move m_killerMoves[MAX_PLY][2];
120120
int m_history[2][64][64];
121121
Move m_moveStack[MAX_PLY + 4];

src/uci.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <iostream>
3232
#include <sstream>
3333

34-
const std::string VERSION = "3.2.1";
34+
const std::string VERSION = "3.2.2";
3535

3636
#if defined(ENV64BIT)
3737
#if defined(_BTYPE)

0 commit comments

Comments
 (0)