Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some of the issues in #808 and #810 (score text etc.) #811

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,6 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
Leelaz.WinrateStats stats = Lizzie.leelaz.getWinrateStats();
double curWR = stats.maxWinrate; // winrate on this move
boolean validWinrate = (stats.totalPlayouts > 0); // and whether it was actually calculated
boolean validScore = validWinrate;
if (!validWinrate) {
curWR = Lizzie.board.getHistory().getData().winrate;
validWinrate = Lizzie.board.getHistory().getData().getPlayouts() > 0;
Expand Down Expand Up @@ -965,8 +964,11 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
setPanelFont(g, (int) (min(width, height) * 0.2));

String text = "";
MoveData bestMove = Utils.getBestMove();
boolean validScore = (bestMove != null);
if (Lizzie.leelaz.isKataGo && validScore) {
double score = Lizzie.leelaz.scoreMean;
double score = bestMove.scoreMean;
double stdev = bestMove.scoreStdev;
if (Lizzie.board.getHistory().isBlacksTurn()) {
if (Lizzie.config.showKataGoBoardScoreMean) {
score = score + Lizzie.board.getHistory().getGameInfo().getKomi();
Expand All @@ -988,7 +990,7 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
text
+ resourceBundle.getString("LizzieFrame.katago.scoreStdev")
+ ": "
+ String.format("%.1f", Lizzie.leelaz.scoreStdev)
+ String.format("%.1f", stdev)
+ " ";
}
// Last move
Expand All @@ -1007,13 +1009,10 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
+ resourceBundle.getString("LizzieFrame.display.lastMove")
+ String.format(": %.1f%%", 100 - lastWR - curWR);
}
}
if (text != "") {
g.drawString(
text, posX + 2 * strokeRadius, posY + height - 2 * strokeRadius); // - font.getSize());
} else {
// I think it's more elegant to just not display anything when we don't have
// valid data --dfannius
// g.drawString(resourceBundle.getString("LizzieFrame.display.lastMove") + ": ?%",
// posX + 2 * strokeRadius, posY + height - 2 * strokeRadius);
}

if (validWinrate || validLastWinrate) {
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/featurecat/lizzie/gui/WinrateGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,6 @@ public void draw(Graphics2D g, int posx, int posy, int width, int height) {
g.setStroke(dashed);
g.setColor(Color.white);
g.drawLine(x, posy, x, posy + height);
// Show move number
String moveNumString = "" + node.getData().moveNumber;
int mw = g.getFontMetrics().stringWidth(moveNumString);
int margin = strokeRadius;
int mx = x - posx < width / 2 ? x + margin : x - mw - margin;
g.setColor(Color.black);
g.drawString(moveNumString, mx, posy + height - margin);
g.setStroke(previousStroke);
}
if (playouts > 0 && node.getData().moveNumber - 1 <= numMoves) {
Expand Down Expand Up @@ -305,6 +298,7 @@ public void draw(Graphics2D g, int posx, int posy, int width, int height) {
movenum--;
}
if (curMovenum > 0) {
Font origFont = g.getFont();
g.setColor(Color.WHITE);
Font f = new Font("", Font.BOLD, 15);
g.setFont(f);
Expand All @@ -315,9 +309,21 @@ public void draw(Graphics2D g, int posx, int posy, int width, int height) {
+ height / 2
- (int) (convertScoreMean(curCurscoreMean) * height / 2 / maxcoreMean)
+ 2 * DOT_RADIUS);
g.setFont(origFont);
}
}

// Show move number
int moveNumber = curMove.getData().moveNumber;
String moveNumString = "" + moveNumber;
movenum = moveNumber - 1;
int x = posx + (movenum * width / numMoves);
int mw = g.getFontMetrics().stringWidth(moveNumString);
int margin = strokeRadius;
int mx = x - posx < width / 2 ? x + margin : x - mw - margin;
g.setColor(Color.black);
g.drawString(moveNumString, mx, posy + height - margin);

// record parameters for calculating moveNumber
params[0] = posx;
params[1] = posy;
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/featurecat/lizzie/gui/WinratePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import featurecat.lizzie.Lizzie;
import featurecat.lizzie.analysis.Leelaz;
import featurecat.lizzie.analysis.MoveData;
import featurecat.lizzie.rules.BoardData;
import featurecat.lizzie.util.Utils;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
Expand Down Expand Up @@ -135,7 +137,6 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
curWR = Lizzie.board.getHistory().getData().winrate;
validWinrate = Lizzie.board.getHistory().getData().getPlayouts() > 0;
}
boolean validScore = validWinrate;
if (Lizzie.frame.isPlayingAgainstLeelaz
&& Lizzie.frame.playerIsBlack == !Lizzie.board.getHistory().getData().blackToPlay) {
validWinrate = false;
Expand Down Expand Up @@ -185,8 +186,11 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
setPanelFont(g, (int) (min(width, height) * 0.2));

String text = "";
MoveData bestMove = Utils.getBestMove();
boolean validScore = (bestMove != null);
if (Lizzie.leelaz.isKataGo && validScore) {
double score = Lizzie.leelaz.scoreMean;
double score = bestMove.scoreMean;
double stdev = bestMove.scoreStdev;
if (Lizzie.board.getHistory().isBlacksTurn()) {
if (Lizzie.config.showKataGoBoardScoreMean) {
score = score + Lizzie.board.getHistory().getGameInfo().getKomi();
Expand All @@ -208,7 +212,7 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
text
+ LizzieMain.resourceBundle.getString("LizzieFrame.katago.scoreStdev")
+ ":"
+ String.format("%.1f", Lizzie.leelaz.scoreStdev)
+ String.format("%.1f", stdev)
+ " ";
}
// Last move
Expand All @@ -227,14 +231,10 @@ private void drawMoveStatistics(Graphics2D g, int posX, int posY, int width, int
+ LizzieMain.resourceBundle.getString("LizzieFrame.display.lastMove")
+ String.format(":%.1f%%", 100 - lastWR - curWR);
}

}
if (text != "") {
g.drawString(
text, posX + 2 * strokeRadius, posY + height - 2 * strokeRadius); // - font.getSize());
} else {
// I think it's more elegant to just not display anything when we don't have
// valid data --dfannius
// g.drawString(resourceBundle.getString("LizzieFrame.display.lastMove") + ": ?%",
// posX + 2 * strokeRadius, posY + height - 2 * strokeRadius);
}

if (validWinrate || validLastWinrate) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/featurecat/lizzie/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import featurecat.lizzie.Lizzie;
import featurecat.lizzie.analysis.Leelaz;
import featurecat.lizzie.analysis.MoveData;
import featurecat.lizzie.gui.BoardRenderer;
import featurecat.lizzie.rules.BoardData;
import featurecat.lizzie.rules.BoardHistoryNode;
Expand Down Expand Up @@ -180,6 +181,11 @@ public static double actualScoreMean(double scoreMean) {
return score;
}

public static MoveData getBestMove() {
List<MoveData> bestMoves = Lizzie.board.getHistory().getData().bestMoves;
return (bestMoves.size() > 0) ? bestMoves.get(0) : null;
}

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