Skip to content

Commit

Permalink
Fix up some analysis details and an analysis null ptr segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
lightvector committed Mar 14, 2019
1 parent b8b55db commit efa04e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cpp/gtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ int MainCmds::gtp(int argc, const char* const* argv) {
recentWinValues.clear();
bot->setKomiIfNew(newKomi);
};


bool currentlyAnalyzing = false;

vector<string> knownCommands = {
"protocol_version",
Expand Down Expand Up @@ -197,7 +198,6 @@ int MainCmds::gtp(int argc, const char* const* argv) {
bool hasId = false;
int id = 0;
{

//Filter down to only "normal" ascii characters. Also excludes carrage returns.
//Newlines are already handled by getline
size_t newLen = 0;
Expand Down Expand Up @@ -257,6 +257,11 @@ int MainCmds::gtp(int argc, const char* const* argv) {
pieces.erase(pieces.begin());
}

//Upon any command, stop any analysis and output a newline
if(currentlyAnalyzing) {
bot->stopAndWait();
cout << endl;
}

bool responseIsError = false;
bool shouldQuitAfterResponse = false;
Expand Down Expand Up @@ -897,6 +902,9 @@ int MainCmds::gtp(int argc, const char* const* argv) {
callback = [minMoves](Search* search) {
vector<AnalysisData> buf;
search->getAnalysisData(buf,minMoves);
if(buf.size() <= 0)
return;

const Board board = search->getRootBoard();
for(int i = 0; i<buf.size(); i++) {
if(i > 0)
Expand All @@ -905,7 +913,7 @@ int MainCmds::gtp(int argc, const char* const* argv) {
cout << "info";
cout << " move " << Location::toString(data.move,board);
cout << " visits " << data.numVisits;
cout << " winrate " << round(data.winLossValue * 10000.0);
cout << " winrate " << round((0.5 * (1.0 + data.winLossValue)) * 10000.0);
cout << " prior " << round(data.policyPrior * 10000.0);
cout << " order " << data.order;
cout << " pv";
Expand All @@ -919,6 +927,9 @@ int MainCmds::gtp(int argc, const char* const* argv) {
callback = [minMoves](Search* search) {
vector<AnalysisData> buf;
search->getAnalysisData(buf,minMoves);
if(buf.size() <= 0)
return;

const Board board = search->getRootBoard();
for(int i = 0; i<buf.size(); i++) {
if(i > 0)
Expand All @@ -928,7 +939,7 @@ int MainCmds::gtp(int argc, const char* const* argv) {
cout << " move " << Location::toString(data.move,board);
cout << " visits " << data.numVisits;
cout << " utility " << data.utility;
cout << " winrate " << data.winLossValue;
cout << " winrate " << (0.5 * (1.0 + data.winLossValue));
cout << " scoreMean " << data.scoreMean;
cout << " scoreStdev " << data.scoreStdev;
cout << " prior " << data.policyPrior;
Expand All @@ -946,6 +957,7 @@ int MainCmds::gtp(int argc, const char* const* argv) {

double searchFactor = 1e40; //go basically forever
bot->analyze(pla, searchFactor, lzAnalyzeInterval, callback);
currentlyAnalyzing = true;
}
}

Expand All @@ -972,7 +984,10 @@ int MainCmds::gtp(int argc, const char* const* argv) {
response = "=" + response;

cout << response << endl;
cout << endl; //GTP needs extra newline

//GTP needs extra newline, except if currently analyzing, defer the newline until we actually stop analysis
if(!currentlyAnalyzing)
cout << endl;

if(logAllGTPCommunication)
logger.write(response);
Expand Down
5 changes: 5 additions & 0 deletions cpp/search/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ void Search::fillPV(vector<Loc>& buf, const SearchNode* n, int maxDepth) {
buf.clear();
if(n == NULL)
return;
buf.push_back(n->prevMoveLoc);
for(int depth = 0; depth < maxDepth; depth++) {
const SearchNode& node = *n;
std::mutex& mutex = mutexPool->getMutex(node.lockIdx);
Expand Down Expand Up @@ -1763,6 +1764,9 @@ void Search::printTree(ostream& out, const SearchNode* node, PrintTreeOptions op

void Search::getAnalysisData(vector<AnalysisData>& buf, int minMovesToTryToGet) {
buf.clear();
if(rootNode == NULL)
return;

vector<SearchNode*> children;
children.reserve(rootBoard.x_size * rootBoard.y_size + 1);
const SearchNode& node = *rootNode;
Expand Down Expand Up @@ -1899,6 +1903,7 @@ void Search::getAnalysisData(vector<AnalysisData>& buf, int minMovesToTryToGet)
data.policyPrior = bestPolicy;
data.order = 0;
data.pv.clear();
data.pv.push_back(bestPos);
buf.push_back(data);
}
}
Expand Down

0 comments on commit efa04e8

Please sign in to comment.