Skip to content

Commit

Permalink
Show score like "W+1.2" on winrate bar (featurecat#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed Nov 8, 2020
1 parent 277a790 commit cd3b40f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 37 deletions.
30 changes: 12 additions & 18 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -967,25 +967,7 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
MoveData bestMove = Utils.getBestMove();
boolean validScore = (bestMove != null);
if (Lizzie.leelaz.isKataGo && validScore) {
double score = bestMove.scoreMean;
double stdev = bestMove.scoreStdev;
if (Lizzie.board.getHistory().isBlacksTurn()) {
if (Lizzie.config.showKataGoBoardScoreMean) {
score = score + Lizzie.board.getHistory().getGameInfo().getKomi();
}
} else {
if (Lizzie.config.showKataGoBoardScoreMean) {
score = score - Lizzie.board.getHistory().getGameInfo().getKomi();
}
if (Lizzie.config.kataGoScoreMeanAlwaysBlack) {
score = -score;
}
}
text =
resourceBundle.getString("LizzieFrame.katago.scoreMean")
+ ": "
+ String.format("%.1f", score)
+ " ";
text =
text
+ resourceBundle.getString("LizzieFrame.katago.scoreStdev")
Expand Down Expand Up @@ -1044,6 +1026,18 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
winString,
barPosxB + maxBarwidth - sw - 2 * strokeRadius,
posY + barHeight - 2 * strokeRadius);
String scoreTextWithLeadingColor = Utils.getScoreTextWithLeadingColor();
if (scoreTextWithLeadingColor != "") {
String scoreString =
resourceBundle.getString("LizzieFrame.katago.scoreMean")
+ ": "
+ scoreTextWithLeadingColor;
sw = g.getFontMetrics().stringWidth(scoreString);
g.drawString(
scoreString,
barPosxB + maxBarwidth / 2 - sw / 2 - strokeRadius,
posY + barHeight - 2 * strokeRadius);
}

g.setColor(Color.GRAY);
Stroke oldstroke = g.getStroke();
Expand Down
30 changes: 12 additions & 18 deletions src/main/java/featurecat/lizzie/gui/WinratePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,7 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
MoveData bestMove = Utils.getBestMove();
boolean validScore = (bestMove != null);
if (Lizzie.leelaz.isKataGo && validScore) {
double score = bestMove.scoreMean;
double stdev = bestMove.scoreStdev;
if (Lizzie.board.getHistory().isBlacksTurn()) {
if (Lizzie.config.showKataGoBoardScoreMean) {
score = score + Lizzie.board.getHistory().getGameInfo().getKomi();
}
} else {
if (Lizzie.config.showKataGoBoardScoreMean) {
score = score - Lizzie.board.getHistory().getGameInfo().getKomi();
}
if (Lizzie.config.kataGoScoreMeanAlwaysBlack) {
score = -score;
}
}
text =
LizzieMain.resourceBundle.getString("LizzieFrame.katago.scoreMean")
+ ":"
+ String.format("%.1f", score)
+ " ";
text =
text
+ LizzieMain.resourceBundle.getString("LizzieFrame.katago.scoreStdev")
Expand Down Expand Up @@ -267,6 +249,18 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
winString,
barPosxB + maxBarwidth - sw - 2 * strokeRadius,
posY + barHeight - 2 * strokeRadius);
String scoreTextWithLeadingColor = Utils.getScoreTextWithLeadingColor();
if (scoreTextWithLeadingColor != "") {
String scoreString =
Lizzie.frame.resourceBundle.getString("LizzieFrame.katago.scoreMean")
+ ": "
+ scoreTextWithLeadingColor;
sw = g.getFontMetrics().stringWidth(scoreString);
g.drawString(
scoreString,
barPosxB + maxBarwidth / 2 - sw / 2 - strokeRadius,
posY + barHeight - 2 * strokeRadius);
}

g.setColor(Color.GRAY);
Stroke oldstroke = g.getStroke();
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/featurecat/lizzie/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public static Color getBlunderNodeColor(BoardHistoryNode node) {
}

public static double actualScoreMean(double scoreMean) {
return actualScoreMean(scoreMean, Lizzie.config.kataGoScoreMeanAlwaysBlack);
}

private static double actualScoreMean(double scoreMean, boolean alwaysBlack) {
double score = scoreMean;
if (Lizzie.board.getHistory().isBlacksTurn()) {
if (Lizzie.config.showKataGoBoardScoreMean) {
Expand All @@ -174,7 +178,7 @@ public static double actualScoreMean(double scoreMean) {
if (Lizzie.config.showKataGoBoardScoreMean) {
score = score - Lizzie.board.getHistory().getGameInfo().getKomi();
}
if (Lizzie.config.kataGoScoreMeanAlwaysBlack) {
if (alwaysBlack) {
score = -score;
}
}
Expand All @@ -186,6 +190,19 @@ public static MoveData getBestMove() {
return (bestMoves.size() > 0) ? bestMoves.get(0) : null;
}

public static String getScoreTextWithLeadingColor() {
MoveData bestMove = getBestMove();
boolean validScore = Lizzie.leelaz.isKataGo && (bestMove != null);
if (!validScore) {
return "";
}
double blackScore = actualScoreMean(bestMove.scoreMean, true);
String leadingColor =
Lizzie.frame.resourceBundle.getString(
(blackScore >= 0) ? "CountDialog.bigBlack" : "CountDialog.bigWhite");
return leadingColor + "+" + String.format("%.1f", Math.abs(blackScore));
}

public static Integer txtFieldValue(JTextField txt) {
if (txt.getText().trim().isEmpty()
|| txt.getText().trim().length() >= String.valueOf(Integer.MAX_VALUE).length()) {
Expand Down

0 comments on commit cd3b40f

Please sign in to comment.