From ab21cd2bcf9eff78bf2ba54e5b2f073258f31371 Mon Sep 17 00:00:00 2001 From: Traveler <83190545+HarangPanul@users.noreply.github.com> Date: Mon, 9 Nov 2026 19:43:11 +0900 Subject: [PATCH 1/2] Simple Refactoring for Improving the Readability of cpp/neuralnet/nninputs.h --- cpp/neuralnet/nninputs.cpp | 89 ++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/cpp/neuralnet/nninputs.cpp b/cpp/neuralnet/nninputs.cpp index c52c711b71..5722b9a3c4 100644 --- a/cpp/neuralnet/nninputs.cpp +++ b/cpp/neuralnet/nninputs.cpp @@ -50,8 +50,8 @@ double ScoreValue::whiteScoreValueOfScoreSmooth( double scale, double drawEquivalentWinsForWhite, double sqrtBoardArea, - const BoardHistory& hist) -{ + const BoardHistory& hist +) { double adjustedScore = finalWhiteMinusBlackScore + hist.whiteKomiAdjustmentForDraws(drawEquivalentWinsForWhite) - center; return atan(adjustedScore / (scale * sqrtBoardArea)) * twoOverPi; } @@ -141,6 +141,7 @@ void ScoreValue::initTables() { for(int stdevIdx = 0; stdevIdx < svTableStdevLen; stdevIdx++) { double wSum = 0.0; double wsvSum = 0.0; + for(int i = minStdevSteps; i <= maxStdevSteps; i++) { int xSteps = meanSteps + stdevIdx * i; double w = normalPDF[i-minStdevSteps]; @@ -170,8 +171,8 @@ double ScoreValue::expectedWhiteScoreValue(double whiteScoreMean, double whiteSc double stdevFloored = floor(stdevScaled); int meanIdx0 = (int)meanRounded + svTableMeanRadius; int stdevIdx0 = (int)stdevFloored; - int meanIdx1 = meanIdx0+1; - int stdevIdx1 = stdevIdx0+1; + int meanIdx1 = meanIdx0 + 1; + int stdevIdx1 = stdevIdx0 + 1; if(meanIdx0 < 0) { meanIdx0 = 0; meanIdx1 = 0; } if(meanIdx1 >= svTableMeanLen) { meanIdx0 = svTableMeanLen-1; meanIdx1 = svTableMeanLen-1; } @@ -193,9 +194,7 @@ double ScoreValue::expectedWhiteScoreValue(double whiteScoreMean, double whiteSc double ScoreValue::getScoreStdev(double scoreMean, double scoreMeanSq) { double variance = scoreMeanSq - scoreMean * scoreMean; - if(variance <= 0.0) - return 0.0; - return sqrt(variance); + return (variance <= 0.0) ? 0.0 : sqrt(variance); } //----------------------------------------------------------------------------------------------------------- @@ -212,15 +211,17 @@ void NNInputs::fillScoring( for(int y = 0; y>& others) { int len = (int)others.size(); float floatLen = (float)len; testAssert(len > 0); - for(int i = 1; innHash == others[0]->nnHash); - } nnHash = others[0]->nnHash; whiteWinProb = 0.0f; @@ -340,7 +337,7 @@ NNOutput::NNOutput(const vector>& others) { varTimeLeft = 0.0f; shorttermWinlossError = 0.0f; shorttermScoreError = 0.0f; - for(int i = 0; i>& others) { { float whiteOwnerMapCount = 0.0f; whiteOwnerMap = NULL; - for(int i = 0; i>& others) { std::fill(whiteOwnerMap, whiteOwnerMap + nnXLen * nnYLen, 0.0f); } whiteOwnerMapCount += 1.0f; - for(int pos = 0; pos 0); - for(int pos = 0; pos>& others) { std::copy(other.policyProbs, other.policyProbs + NNPos::MAX_NN_POLICY_SIZE, policyProbs); } else { - for(int pos = 0; pospolicyOptimismUsed != others[0]->policyOptimismUsed) { allOptimismsMatch = false; break; @@ -426,7 +423,7 @@ NNOutput::NNOutput(const vector>& others) { } else { policyOptimismUsed = 0.0; - for(int i = 0; ipolicyOptimismUsed / (float)len; } } @@ -2327,8 +2324,8 @@ void NNInputs::fillRowV7( posStride = 1; } - for(int y = 0; y Date: Wed, 11 Nov 2026 18:55:53 +0900 Subject: [PATCH 2/2] enhance Readability --- cpp/neuralnet/nninputs.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cpp/neuralnet/nninputs.h b/cpp/neuralnet/nninputs.h index 2899172f72..d901dc8c17 100644 --- a/cpp/neuralnet/nninputs.h +++ b/cpp/neuralnet/nninputs.h @@ -22,11 +22,14 @@ namespace NNPos { inline int xyToPos(int x, int y, int nnXLen) { return y * nnXLen + x; } inline int locToPos(Loc loc, int boardXSize, int nnXLen, int nnYLen) { - if(loc == Board::PASS_LOC) + switch(loc) { + case Board::PASS_LOC: return nnXLen * nnYLen; - else if(loc == Board::NULL_LOC) + case Board::NULL_LOC: return nnXLen * (nnYLen + 1); - return Location::getY(loc,boardXSize) * nnXLen + Location::getX(loc,boardXSize); + default: + return Location::getY(loc,boardXSize) * nnXLen + Location::getX(loc,boardXSize); + } } inline Loc posToLoc(int pos, int boardXSize, int boardYSize, int nnXLen, int nnYLen) { if(pos == nnXLen * nnYLen)