From 814cfd3b005d088ea1f65c1c19b60d66075da35e Mon Sep 17 00:00:00 2001 From: Jakub Straszewski Date: Thu, 12 Jul 2018 09:57:37 +0200 Subject: [PATCH 1/5] Improve parsing of MoveData to allow for unknown tags --- .../featurecat/lizzie/analysis/MoveData.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/featurecat/lizzie/analysis/MoveData.java b/src/main/java/featurecat/lizzie/analysis/MoveData.java index 0ba3ef154..4ae9c2490 100644 --- a/src/main/java/featurecat/lizzie/analysis/MoveData.java +++ b/src/main/java/featurecat/lizzie/analysis/MoveData.java @@ -22,13 +22,30 @@ public MoveData(String line) throws ArrayIndexOutOfBoundsException { String[] data = line.trim().split(" "); // Todo: Proper tag parsing in case gtp protocol is extended(?)/changed - coordinate = data[1]; - playouts = Integer.parseInt(data[3]); - winrate = Integer.parseInt(data[5])/100.0; - order = Integer.parseInt(data[7]); - variation = new ArrayList<>(Arrays.asList(data)); - variation = variation.subList(9, variation.size()); + for (int i=0; i(Arrays.asList(data)); + variation = variation.subList(i+1, data.length); + break; + } else { + String value = data[++i]; + if (key.equals("move")) { + coordinate = value; + } + if (key.equals("visits")) { + playouts = Integer.parseInt(value); + } + if (key.equals("winrate")) { + winrate = Integer.parseInt(value)/100.0; + } + if (key.equals("order")) { + order = Integer.parseInt(value); + } + } + } } public int compareTo(MoveData b) { From 20611dbfdd3349204bfc14792544b62f95d97b26 Mon Sep 17 00:00:00 2001 From: Jakub Straszewski Date: Thu, 12 Jul 2018 09:58:16 +0200 Subject: [PATCH 2/5] Print dynamic komi if present --- .../featurecat/lizzie/analysis/Leelaz.java | 29 ++++++++++++++++++- .../featurecat/lizzie/gui/LizzieFrame.java | 10 +++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/java/featurecat/lizzie/analysis/Leelaz.java b/src/main/java/featurecat/lizzie/analysis/Leelaz.java index fd69e6c49..0d08328e4 100644 --- a/src/main/java/featurecat/lizzie/analysis/Leelaz.java +++ b/src/main/java/featurecat/lizzie/analysis/Leelaz.java @@ -60,6 +60,8 @@ public class Leelaz { private boolean isLoaded = false; private boolean isCheckingVersion; + // dynamic komi and opponent komi as reported by dynamic-komi version of leelaz + private float dynamicKomi = Float.NaN, dynamicOppKomi = Float.NaN; /** * Initializes the leelaz process and starts reading output * @@ -180,7 +182,25 @@ private void parseInfo(String line) { */ private void parseLine(String line) { synchronized (this) { - if (line.equals("\n")) { + if (line.startsWith("komi=")) + { + try { + dynamicKomi = Float.parseFloat(line.substring("komi=".length()).trim()); + } + catch (NumberFormatException nfe) { + dynamicKomi = Float.NaN; + } + } + else if (line.startsWith("opp_komi=")) + { + try { + dynamicOppKomi = Float.parseFloat(line.substring("opp_komi=".length()).trim()); + } + catch (NumberFormatException nfe) { + dynamicOppKomi = Float.NaN; + } + } + else if (line.equals("\n")) { // End of response } else if (line.startsWith("info")) { isLoaded = true; @@ -425,6 +445,13 @@ public List getBestMoves() { } } + public String getDynamicKomi() { + if (Float.isNaN(dynamicKomi) || Float.isNaN(dynamicOppKomi)) { + return null; + } + return String.format("%.1f / %.1f", dynamicKomi, dynamicOppKomi); + } + public boolean isPondering() { return isPondering; } diff --git a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java index 37cd07366..d4df3fa2c 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java @@ -322,6 +322,12 @@ public void paint(Graphics g0) { int ponderingY = boardY + (int) (maxSize*0.93); double ponderingSize = .02; + // dynamic komi + int dynamicKomiX = this.getInsets().left; + int dynamicKomiY = boardY + (int) (maxSize*0.86); + double dynamicKomiSize = .02; + + // loading message int loadingX = ponderingX; int loadingY = ponderingY; @@ -390,6 +396,10 @@ public void paint(Graphics g0) { ponderingX, ponderingY, ponderingSize); } + if (Lizzie.leelaz.getDynamicKomi() != null) { + drawPonderingState(g, Lizzie.leelaz.getDynamicKomi(), dynamicKomiX, dynamicKomiY, dynamicKomiSize); + } + // Todo: Make board move over when there is no space beside the board if (Lizzie.config.showWinrate) { drawWinrateGraphContainer(backgroundG, contx, conty, contw, conth); From c0707b26c510002586e1217f871208e94fe0dfcf Mon Sep 17 00:00:00 2001 From: Jakub Straszewski Date: Fri, 20 Jul 2018 15:00:09 +0200 Subject: [PATCH 3/5] add a label for dynamic komi --- src/main/java/featurecat/lizzie/gui/LizzieFrame.java | 6 +++++- src/main/resources/l10n/DisplayStrings.properties | 1 + src/main/resources/l10n/DisplayStrings_zh_CN.properties | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java index d4df3fa2c..fd1803f5d 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java @@ -323,8 +323,11 @@ public void paint(Graphics g0) { double ponderingSize = .02; // dynamic komi + int dynamicKomiLabelX = this.getInsets().left; + int dynamicKomiLabelY = boardY + (int) (maxSize*0.86); + int dynamicKomiX = this.getInsets().left; - int dynamicKomiY = boardY + (int) (maxSize*0.86); + int dynamicKomiY = boardY + (int) (maxSize*0.89); double dynamicKomiSize = .02; @@ -397,6 +400,7 @@ public void paint(Graphics g0) { } if (Lizzie.leelaz.getDynamicKomi() != null) { + drawPonderingState(g, resourceBundle.getString("LizzieFrame.display.dynamic-komi"), dynamicKomiLabelX, dynamicKomiLabelY, dynamicKomiSize); drawPonderingState(g, Lizzie.leelaz.getDynamicKomi(), dynamicKomiX, dynamicKomiY, dynamicKomiSize); } diff --git a/src/main/resources/l10n/DisplayStrings.properties b/src/main/resources/l10n/DisplayStrings.properties index 421a2ecd3..63c898f8d 100644 --- a/src/main/resources/l10n/DisplayStrings.properties +++ b/src/main/resources/l10n/DisplayStrings.properties @@ -51,3 +51,4 @@ LizzieFrame.display.loading=Leela Zero is loading... LizzieFrame.display.download-latest-network-prompt=Download the latest network file? This may take some time. LizzieFrame.display.leelaz-missing=Did not find Leela Zero, update config.txt or download from Leela Zero homepage LizzieFrame.display.network-missing=Did not find network/weights.\nUpdate config.txt (network-file) or download from Leela Zero homepage +LizzieFrame.display.dynamic-komi=dyn. komi: \ No newline at end of file diff --git a/src/main/resources/l10n/DisplayStrings_zh_CN.properties b/src/main/resources/l10n/DisplayStrings_zh_CN.properties index 7d5069288..59cf0e710 100644 --- a/src/main/resources/l10n/DisplayStrings_zh_CN.properties +++ b/src/main/resources/l10n/DisplayStrings_zh_CN.properties @@ -39,3 +39,4 @@ LizzieFrame.display.loading=Leela Zero\u6B63\u5728\u8F7D\u5165\u4E2D... LizzieFrame.display.download-latest-network-prompt=Download the latest network file? This may take some time. LizzieFrame.display.leelaz-missing=Did not find Leela Zero, update config.txt or download from Leela Zero homepage LizzieFrame.display.network-missing=Did not find network/weights.\nUpdate config.txt (network-file) or download from Leela Zero homepage +LizzieFrame.display.dynamic-komi=dyn. komi: \ No newline at end of file From da5357cb643d7d0831bacfb1900e946b52f8a8d6 Mon Sep 17 00:00:00 2001 From: Kuba Date: Sat, 21 Jul 2018 10:32:56 +0200 Subject: [PATCH 4/5] make showing dynamic komi optional --- src/main/java/featurecat/lizzie/Config.java | 3 +++ .../java/featurecat/lizzie/gui/Input.java | 8 +++++++ .../featurecat/lizzie/gui/LizzieFrame.java | 22 +++++++++++++------ .../resources/l10n/DisplayStrings.properties | 3 ++- .../l10n/DisplayStrings_zh_CN.properties | 1 + 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/java/featurecat/lizzie/Config.java b/src/main/java/featurecat/lizzie/Config.java index b6cb578cc..ba25e3330 100644 --- a/src/main/java/featurecat/lizzie/Config.java +++ b/src/main/java/featurecat/lizzie/Config.java @@ -18,6 +18,7 @@ public class Config { public boolean showRawBoard = false; public boolean showCaptured = true; public boolean handicapInsteadOfWinrate = false; + public boolean showDynamicKomi = true; public boolean showStatus = true; public boolean showBranch = true; @@ -146,6 +147,7 @@ public Config() throws IOException { largeSubBoard = uiConfig.getBoolean("large-subboard"); handicapInsteadOfWinrate = uiConfig.getBoolean("handicap-instead-of-winrate"); startMaximized = uiConfig.getBoolean("window-maximized"); + showDynamicKomi = uiConfig.getBoolean("show-dynamic-komi"); } // Modifies config by adding in values from default_config that are missing. @@ -269,6 +271,7 @@ private JSONObject createDefaultConfig() { ui.put("board-size", 19); ui.put("window-size", new JSONArray("[1024, 768]")); ui.put("window-maximized", false); + ui.put("show-dynamic-komi", true); config.put("ui", ui); return config; diff --git a/src/main/java/featurecat/lizzie/gui/Input.java b/src/main/java/featurecat/lizzie/gui/Input.java index 94e76d87b..ee32f376a 100644 --- a/src/main/java/featurecat/lizzie/gui/Input.java +++ b/src/main/java/featurecat/lizzie/gui/Input.java @@ -160,6 +160,10 @@ private boolean controlIsPressed(KeyEvent e) { return e.isControlDown() || (mac && e.isMetaDown()); } + private void toggleShowDynamicKomi() { + Lizzie.config.showDynamicKomi = !Lizzie.config.showDynamicKomi; + } + @Override public void keyPressed(KeyEvent e) { @@ -358,6 +362,10 @@ public void keyPressed(KeyEvent e) { } break; + case VK_D: + toggleShowDynamicKomi(); + break; + default: shouldDisableAnalysis = false; } diff --git a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java index fd1803f5d..3bb067a5d 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java @@ -35,6 +35,7 @@ import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage; import java.io.*; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.ResourceBundle; @@ -399,7 +400,7 @@ public void paint(Graphics g0) { ponderingX, ponderingY, ponderingSize); } - if (Lizzie.leelaz.getDynamicKomi() != null) { + if (Lizzie.config.showDynamicKomi && Lizzie.leelaz.getDynamicKomi() != null) { drawPonderingState(g, resourceBundle.getString("LizzieFrame.display.dynamic-komi"), dynamicKomiLabelX, dynamicKomiLabelY, dynamicKomiSize); drawPonderingState(g, Lizzie.leelaz.getDynamicKomi(), dynamicKomiX, dynamicKomiY, dynamicKomiSize); } @@ -531,17 +532,22 @@ void drawControls() { // redraw background createBackground(); + List commandsToShow = new ArrayList<>(Arrays.asList(commands)); + if (Lizzie.leelaz.getDynamicKomi() != null) { + commandsToShow.add(resourceBundle.getString("LizzieFrame.commands.keyD")); + } + Graphics2D g = cachedImage.createGraphics(); int maxSize = Math.min(getWidth(), getHeight()); Font font = new Font(systemDefaultFontName, Font.PLAIN, (int) (maxSize * 0.034)); g.setFont(font); FontMetrics metrics = g.getFontMetrics(font); - int maxCommandWidth = Arrays.asList(commands).stream().reduce(0, (Integer i, String command) -> Math.max(i, metrics.stringWidth(command)), (Integer a, Integer b) -> Math.max(a, b)); + int maxCommandWidth = commandsToShow.stream().reduce(0, (Integer i, String command) -> Math.max(i, metrics.stringWidth(command)), (Integer a, Integer b) -> Math.max(a, b)); int lineHeight = (int) (font.getSize() * 1.15); int boxWidth = Util.clamp((int) (maxCommandWidth * 1.4), 0, getWidth()); - int boxHeight = Util.clamp(commands.length * lineHeight, 0, getHeight()); + int boxHeight = Util.clamp(commandsToShow.size() * lineHeight, 0, getHeight()); int commandsX = Util.clamp(getWidth() / 2 - boxWidth / 2, 0, getWidth()); int commandsY = Util.clamp(getHeight() / 2 - boxHeight / 2, 0, getHeight()); @@ -567,10 +573,12 @@ void drawControls() { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.WHITE); - for (int i = 0; i < commands.length; i++) { - String[] split = commands[i].split("\\|"); - g.drawString(split[0], verticalLineX - metrics.stringWidth(split[0]) - strokeRadius * 4, font.getSize() + (commandsY + i * lineHeight)); - g.drawString(split[1], verticalLineX + strokeRadius * 4, font.getSize() + (commandsY + i * lineHeight)); + int lineOffset = commandsY; + for (String command : commandsToShow) { + String[] split = command.split("\\|"); + g.drawString(split[0], verticalLineX - metrics.stringWidth(split[0]) - strokeRadius * 4, font.getSize() + lineOffset); + g.drawString(split[1], verticalLineX + strokeRadius * 4, font.getSize() + lineOffset); + lineOffset += lineHeight; } refreshBackground(); diff --git a/src/main/resources/l10n/DisplayStrings.properties b/src/main/resources/l10n/DisplayStrings.properties index 63c898f8d..a807ba8bd 100644 --- a/src/main/resources/l10n/DisplayStrings.properties +++ b/src/main/resources/l10n/DisplayStrings.properties @@ -19,6 +19,7 @@ LizzieFrame.commands.keyAltC=ctrl-c|copy SGF to clipboard LizzieFrame.commands.keyAltV=ctrl-v|paste SGF from clipboard LizzieFrame.commands.keyC=c|toggle coordinates LizzieFrame.commands.keyControl=ctrl|undo/redo 10 moves +LizzieFrame.commands.keyD=d|show/hide dynamic komi LizzieFrame.commands.keyDownArrow=down arrow|redo LizzieFrame.commands.keyEnd=end|go to end LizzieFrame.commands.keyEnter=enter|force Leela Zero move @@ -51,4 +52,4 @@ LizzieFrame.display.loading=Leela Zero is loading... LizzieFrame.display.download-latest-network-prompt=Download the latest network file? This may take some time. LizzieFrame.display.leelaz-missing=Did not find Leela Zero, update config.txt or download from Leela Zero homepage LizzieFrame.display.network-missing=Did not find network/weights.\nUpdate config.txt (network-file) or download from Leela Zero homepage -LizzieFrame.display.dynamic-komi=dyn. komi: \ No newline at end of file +LizzieFrame.display.dynamic-komi=dyn. komi: diff --git a/src/main/resources/l10n/DisplayStrings_zh_CN.properties b/src/main/resources/l10n/DisplayStrings_zh_CN.properties index 59cf0e710..6a39c6660 100644 --- a/src/main/resources/l10n/DisplayStrings_zh_CN.properties +++ b/src/main/resources/l10n/DisplayStrings_zh_CN.properties @@ -6,6 +6,7 @@ LizzieFrame.commands.keyAltC=ctrl-c|\u62F7\u8D1DSGF\u5230\u526A\u8D34\u677F LizzieFrame.commands.keyAltV=ctrl-v|\u4ECE\u526A\u8D34\u677F\u7C98\u8D34SGF\u5C40\u9762 LizzieFrame.commands.keyC=c|\u663E\u793A/\u9690\u85CF\u5750\u6807 +LizzieFrame.commands.keyD=d|show/hide dynamic komi LizzieFrame.commands.keyControl=ctrl|\u5411\u524D/\u5411\u540E10\u6B65 LizzieFrame.commands.keyDownArrow=\u4E0B\u65B9\u5411\u952E|\u5411\u540E\u4E00\u6B65 LizzieFrame.commands.keyEnd=end|\u8DF3\u5230\u68CB\u8C31\u672B\u5C3E From 965e198b24b16d17e03f668abfd7790b34cc7444 Mon Sep 17 00:00:00 2001 From: Kuba Date: Sat, 21 Jul 2018 10:33:52 +0200 Subject: [PATCH 5/5] bring back trailing space after 'Pondering' in DisplayStrings --- src/main/resources/l10n/DisplayStrings.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/l10n/DisplayStrings.properties b/src/main/resources/l10n/DisplayStrings.properties index a807ba8bd..3efe45210 100644 --- a/src/main/resources/l10n/DisplayStrings.properties +++ b/src/main/resources/l10n/DisplayStrings.properties @@ -45,7 +45,7 @@ LizzieFrame.prompt.failedToSaveFile=Failed to save file. LizzieFrame.prompt.sgfExists=The SGF file already exists, do you want to replace it? LizzieFrame.prompt.showControlsHint=hold x = view controls LizzieFrame.display.lastMove=Last move -LizzieFrame.display.pondering=Pondering +LizzieFrame.display.pondering=Pondering LizzieFrame.display.on=on LizzieFrame.display.off=off LizzieFrame.display.loading=Leela Zero is loading...