Skip to content

Commit 9df78fe

Browse files
committed
Introduce getCompleteWhiteBonus
1 parent 1a51ddf commit 9df78fe

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

cpp/game/boardhistory.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ int BoardHistory::numberOfKoHashOccurrencesInHistory(Hash128 koHash, const KoHas
604604
return count;
605605
}
606606

607+
float BoardHistory::getCompleteWhiteBonus() const {
608+
return whiteBonusScore + whiteHandicapBonusScore + rules.komi;
609+
}
610+
607611
float BoardHistory::whiteKomiAdjustmentForDraws(double drawEquivalentWinsForWhite) const {
608612
//We fold the draw utility into the komi, for input into things like the neural net.
609613
//Basically we model it as if the final score were jittered by a uniform draw from [-0.5,0.5].
@@ -614,7 +618,7 @@ float BoardHistory::whiteKomiAdjustmentForDraws(double drawEquivalentWinsForWhit
614618
}
615619

616620
float BoardHistory::currentSelfKomi(Player pla, double drawEquivalentWinsForWhite) const {
617-
float whiteKomiAdjusted = whiteBonusScore + whiteHandicapBonusScore + rules.komi + whiteKomiAdjustmentForDraws(drawEquivalentWinsForWhite);
621+
float whiteKomiAdjusted = getCompleteWhiteBonus() + whiteKomiAdjustmentForDraws(drawEquivalentWinsForWhite);
618622

619623
if(pla == P_WHITE)
620624
return whiteKomiAdjusted;
@@ -750,7 +754,7 @@ void BoardHistory::endAndScoreGameNow(const Board& board, Color area[Board::MAX_
750754
whiteBonusScore += (presumedNextMovePla == P_WHITE ? 0.5f : -0.5f);
751755
}
752756

753-
setFinalScoreAndWinner(static_cast<float>(boardScore) + whiteBonusScore + whiteHandicapBonusScore + rules.komi);
757+
setFinalScoreAndWinner(static_cast<float>(boardScore) + getCompleteWhiteBonus());
754758
isScored = true;
755759
isNoResult = false;
756760
isResignation = false;
@@ -786,7 +790,7 @@ bool BoardHistory::endGameIfReasonable(const Board& board, const bool checkAllPa
786790
}
787791

788792
if (!reasonableMoveExist) {
789-
finalWhiteScore = board.numBlackCaptures - board.numWhiteCaptures + whiteBonusScore + whiteHandicapBonusScore + rules.komi;
793+
finalWhiteScore = board.numBlackCaptures - board.numWhiteCaptures + getCompleteWhiteBonus();
790794
}
791795
}
792796

@@ -834,7 +838,7 @@ bool BoardHistory::endGameIfReasonable(const Board& board, const bool checkAllPa
834838
hasButton = false;
835839
whiteBonusScore += (presumedNextMovePla == P_WHITE ? 0.5f : -0.5f);
836840
}
837-
setFinalScoreAndWinner(boardScore + whiteBonusScore + whiteHandicapBonusScore + rules.komi);
841+
setFinalScoreAndWinner(boardScore + getCompleteWhiteBonus());
838842
isScored = true;
839843
isNoResult = false;
840844
isResignation = false;
@@ -1100,7 +1104,7 @@ void BoardHistory::makeBoardMoveAssumeLegal(Board& board, Loc moveLoc, Player mo
11001104
isGameFinished = true;
11011105
isPastNormalPhaseEnd = false;
11021106
const auto whiteMinusBlackScore = static_cast<float>(board.numBlackCaptures - board.numWhiteCaptures);
1103-
setFinalScoreAndWinner(whiteMinusBlackScore + whiteBonusScore + whiteHandicapBonusScore + rules.komi);
1107+
setFinalScoreAndWinner(whiteMinusBlackScore + getCompleteWhiteBonus());
11041108
}
11051109
} else {
11061110
if(moveLoc != Board::PASS_LOC)

cpp/game/boardhistory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ struct BoardHistory {
131131
//(such as setInitialTurnNumber, setAssumeMultipleStartingBlackMovesAreHandicap) set identically.
132132
BoardHistory copyToInitial() const;
133133

134+
float getCompleteWhiteBonus() const;
135+
134136
float whiteKomiAdjustmentForDraws(double drawEquivalentWinsForWhite) const;
137+
135138
float currentSelfKomi(Player pla, double drawEquivalentWinsForWhite) const;
136139

137140
//Returns a reference a recent board state, where 0 is the current board, 1 is 1 move ago, etc.

cpp/game/dotsboardhistory.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ float BoardHistory::whiteScoreIfNotCapturingGroundingAlive(const Board& board, c
3434
float BoardHistory::whiteScoreIfGroundingAlive(const Board& board, const Color groundColor) const {
3535
assert(rules.isDots);
3636

37-
const auto extraWhiteScore = whiteBonusScore + whiteHandicapBonusScore + rules.komi;
37+
const auto completeWhiteBonus = getCompleteWhiteBonus();
3838

3939
const int blackWhiteCapturesDiff = board.numBlackCaptures - board.numWhiteCaptures;
4040

4141
if (board.blackScoreIfWhiteGrounds == -board.whiteScoreIfBlackGrounds) {
4242
// All dots are grounded -> draw or win by extra bonus
4343
assert(board.whiteScoreIfBlackGrounds == blackWhiteCapturesDiff);
44-
return static_cast<float>(blackWhiteCapturesDiff) + extraWhiteScore;
44+
return static_cast<float>(blackWhiteCapturesDiff) + completeWhiteBonus;
4545
}
4646

4747
// In case of non-capturing grounding, the winner still can ground if only all its dots are grounded (ungrounded opp dots don't matter)
48-
if (const float fullWhiteScoreIfBlackGrounds = static_cast<float>(board.whiteScoreIfBlackGrounds) + extraWhiteScore;
48+
if (const float fullWhiteScoreIfBlackGrounds = static_cast<float>(board.whiteScoreIfBlackGrounds) + completeWhiteBonus;
4949
fullWhiteScoreIfBlackGrounds < 0.0F) {
5050
// Black already won the game by grounding considering white extra bonus
5151
if (groundColor == C_EMPTY || (blackWhiteCapturesDiff == board.whiteScoreIfBlackGrounds && groundColor == P_BLACK)) {
5252
return fullWhiteScoreIfBlackGrounds;
5353
}
54-
} else if (const float fullBlackScoreIfWhiteGrounds = static_cast<float>(board.blackScoreIfWhiteGrounds) - extraWhiteScore;
54+
} else if (const float fullBlackScoreIfWhiteGrounds = static_cast<float>(board.blackScoreIfWhiteGrounds) - completeWhiteBonus;
5555
fullBlackScoreIfWhiteGrounds < 0.0F) {
5656
// White already won the game by grounding considering white extra bonus
5757
if (groundColor == C_EMPTY || (-blackWhiteCapturesDiff == board.blackScoreIfWhiteGrounds && groundColor == P_WHITE)) {

0 commit comments

Comments
 (0)