Skip to content

Commit

Permalink
Option to opaquely paint grayscale territory prediction on board
Browse files Browse the repository at this point in the history
  • Loading branch information
TFiFiE committed Nov 3, 2019
1 parent ade7535 commit 89cbaba
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/main/java/featurecat/lizzie/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Config {
public boolean showKataGoEstimateOnSubboard = true;
public boolean showKataGoEstimateOnMainboard = true;
public String kataGoEstimateMode = "small+dead";
public boolean kataGoEstimateBlend = true;

public boolean showStatus = true;
public boolean showBranch = true;
Expand Down Expand Up @@ -241,6 +242,7 @@ public Config() throws IOException {
showKataGoEstimateOnSubboard = uiConfig.optBoolean("show-katago-estimate-onsubboard", true);
showKataGoEstimateOnMainboard = uiConfig.optBoolean("show-katago-estimate-onmainboard", true);
kataGoEstimateMode = uiConfig.optString("katago-estimate-mode", "small+dead");
kataGoEstimateBlend = uiConfig.optBoolean("katago-estimate-blend", true);
showWinrateInSuggestion = uiConfig.optBoolean("show-winrate-in-suggestion", true);
showPlayoutsInSuggestion = uiConfig.optBoolean("show-playouts-in-suggestion", true);
showScoremeanInSuggestion = uiConfig.optBoolean("show-scoremean-in-suggestion", true);
Expand Down Expand Up @@ -414,6 +416,11 @@ public void cycleKataGoEstimateMode() {
uiConfig.put("katago-estimate-mode", kataGoEstimateMode);
}

public void toggleKataGoEstimateBlend() {
kataGoEstimateBlend = !kataGoEstimateBlend;
uiConfig.put("katago-estimate-blend", kataGoEstimateBlend);
}

public void toggleShowStatus() {
this.showStatus = !this.showStatus;
Lizzie.config.uiConfig.put("show-status", showStatus);
Expand Down Expand Up @@ -546,6 +553,7 @@ private JSONObject createDefaultConfig() {
ui.put("show-katago-estimate-onsubboard", true);
ui.put("show-katago-estimate-onmainboard", true);
ui.put("katago-estimate-mode", "small");
ui.put("katago-estimate-blend", true);
config.put("ui", ui);
return config;
}
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/featurecat/lizzie/gui/BoardRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1789,13 +1789,20 @@ public void drawEstimateRect(ArrayList<Double> estimateArray, boolean isZen) {
int stoneY = scaledMarginHeight + squareHeight * y;
// g.setColor(Color.BLACK);

int grey = (estimate > 0) ? 0 : 255;
double alpha = 255 * Math.abs(estimate);
boolean blend = Lizzie.config.kataGoEstimateBlend;
int grey;
double alpha = 255;
if (blend) {
grey = (estimate > 0) ? 0 : 255;
alpha *= Math.abs(estimate);
} else {
grey = roundToInt((1 - estimate) * 255 / 2.0);
}

// Large rectangles (will go behind stones).

if (drawLarge) {
Color cl = new Color(grey, grey, grey, roundToInt(0.75 * alpha));
Color cl = new Color(grey, grey, grey, roundToInt(blend ? 0.75 * alpha : alpha));
gl.setColor(cl);
gl.fillRect(
(int) (stoneX - squareWidth * 0.5),
Expand All @@ -1818,7 +1825,7 @@ public void drawEstimateRect(ArrayList<Double> estimateArray, boolean isZen) {
if (drawSmall && allowed) {
double lengthFactor = drawSize ? 2 * convertLength(estimate) : 1.2;
int length = (int) (lengthFactor * stoneRadius);
int ialpha = drawSize ? 180 : roundToInt(alpha);
int ialpha = (blend && drawSize) ? 180 : roundToInt(alpha);
Color cl = new Color(grey, grey, grey, ialpha);
gs.setColor(cl);
gs.fillRect(stoneX - length / 2, stoneY - length / 2, length, length);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/featurecat/lizzie/gui/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ public void keyPressed(KeyEvent e) {
if (Lizzie.leelaz.isKataGo) {
if (e.isAltDown()) {
Lizzie.frame.toggleEstimateByZen();
} else if (e.isShiftDown()) {
if (Lizzie.config.showKataGoEstimate) Lizzie.config.toggleKataGoEstimateBlend();
} else {
if (e.isControlDown()) {
// ctrl-. cycles modes, but only if estimates being displayed
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/featurecat/lizzie/gui/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,22 @@ public void actionPerformed(ActionEvent e) {
}
});

final JCheckBoxMenuItem kataEstimateBlend =
new JCheckBoxMenuItem(resourceBundle.getString("Menu.view.kataGo.kataEstimate.blend"));
kataEstimateBlend.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Lizzie.config.toggleKataGoEstimateBlend();
try {
Lizzie.config.save();
} catch (IOException es) {
// TODO Auto-generated catch block
}
}
});
kataEstimate.add(kataEstimateBlend);

viewMenu.addMenuListener(
new MenuListener() {
public void menuSelected(MenuEvent e) {
Expand Down Expand Up @@ -960,6 +976,7 @@ public void menuSelected(MenuEvent e) {
kataEstimateModeLargeAndStones.setState(
Lizzie.config.kataGoEstimateMode.equals("large+stones"));
kataEstimateModeSize.setState(Lizzie.config.kataGoEstimateMode.equals("size"));
kataEstimateBlend.setState(Lizzie.config.kataGoEstimateBlend);
if (Lizzie.config.uiConfig.getBoolean("win-rate-always-black"))
winrateAlwaysBlack.setState(true);
else winrateAlwaysBlack.setState(false);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/DisplayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Menu.view.kataGo.kataEstimate.mode.largeAndSmall=Large + small everywhere
Menu.view.kataGo.kataEstimate.mode.largeAndDead=Large + small on "dead" stones
Menu.view.kataGo.kataEstimate.mode.largeAndStones=Large + small on all stones
Menu.view.kataGo.kataEstimate.mode.size=Small, of varying size
Menu.view.kataGo.kataEstimate.blend=Blend with board
Menu.game=Game
Menu.game.newGame=NewGame(N)
Menu.game.continueGameBlack=Continue(Play black)
Expand Down

0 comments on commit 89cbaba

Please sign in to comment.