From 35afed8ec8aa255aeb65a5c26f32a870a1c17b10 Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Sun, 15 Jan 2023 06:10:09 +0900 Subject: [PATCH] Add "-config" in engine setting for KataGo (#914) --- .../featurecat/lizzie/gui/ConfigDialog.java | 18 +++++++++++++++++- .../featurecat/lizzie/gui/EngineParameter.java | 12 +++++++++--- .../resources/l10n/DisplayStrings.properties | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java index aa13e52c5..798d4c59b 100644 --- a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java +++ b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java @@ -104,6 +104,7 @@ public class ConfigDialog extends JDialog { public String enginePath = ""; public String weightPath = ""; + public String configPath = ""; public String commandHelp = ""; private String osName; @@ -1848,8 +1849,9 @@ private String getEngineLine() { weightFile = chooserw.getSelectedFile(); if (weightFile != null) { weightPath = relativizePath(weightFile.toPath(), this.curPath); + configPath = selectConfigFile(); EngineParameter ep = - new EngineParameter(enginePath, weightPath, guessedEngineType(), this); + new EngineParameter(enginePath, weightPath, configPath, guessedEngineType(), this); ep.setVisible(true); if (!ep.commandLine.isEmpty()) { engineLine = ep.commandLine; @@ -1861,6 +1863,20 @@ private String getEngineLine() { return engineLine; } + private String selectConfigFile() { + if (!guessedEngineType().equals("katago")) return ""; + String titleKey = "LizzieConfig.prompt.selectConfig"; + // dare to copy code redundantly to keep the original code as much as possible + JFileChooser chooser = new JFileChooser("."); + chooser.setMultiSelectionEnabled(false); + chooser.setDialogTitle(resourceBundle.getString(titleKey)); + int result = chooser.showOpenDialog(this); + if (result != JFileChooser.APPROVE_OPTION) return ""; + File file = chooser.getSelectedFile(); + if (file == null) return ""; + return relativizePath(file.toPath(), this.curPath); + } + private String guessedEngineType() { String engineFileName = (new File(enginePath)).toPath().getFileName().toString(); // fixme: ad hoc! diff --git a/src/main/java/featurecat/lizzie/gui/EngineParameter.java b/src/main/java/featurecat/lizzie/gui/EngineParameter.java index a56ac573b..fdf5b01cb 100644 --- a/src/main/java/featurecat/lizzie/gui/EngineParameter.java +++ b/src/main/java/featurecat/lizzie/gui/EngineParameter.java @@ -31,7 +31,11 @@ public class EngineParameter extends JDialog { /** Create the dialog. */ public EngineParameter( - String enginePath, String weightPath, String engineType, ConfigDialog configDialog) { + String enginePath, + String weightPath, + String configPath, + String engineType, + ConfigDialog configDialog) { setTitle(configDialog.resourceBundle.getString("LizzieConfig.title.parameterConfig")); setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); setModal(true); @@ -49,8 +53,10 @@ public EngineParameter( txtCommandLine = new JTextField(); txtCommandLine.setEditable(false); txtCommandLine.setBounds(89, 12, 565, 26); - String weightOption = (engineType.equals("leelaz")) ? " --weights " : " gtp -model "; - txtCommandLine.setText(enginePath + weightOption + weightPath); + String weightOption = engineType.equals("leelaz") ? " --weights " : " gtp -model "; + String configArgs = + (engineType.equals("leelaz") || configPath.isEmpty()) ? "" : " -config " + configPath + " "; + txtCommandLine.setText(enginePath + weightOption + weightPath + configArgs); contentPanel.add(txtCommandLine); txtCommandLine.setColumns(10); JLabel lblParameter = diff --git a/src/main/resources/l10n/DisplayStrings.properties b/src/main/resources/l10n/DisplayStrings.properties index 04dfb56ff..3be3952c7 100644 --- a/src/main/resources/l10n/DisplayStrings.properties +++ b/src/main/resources/l10n/DisplayStrings.properties @@ -149,6 +149,7 @@ LizzieConfig.lizzie.contributorsTitle=cngoodboykaorahizsalchbittsittOlivierBlanvillaindfanniustoomasrapetrescTFiFiEaerisnjukuba97531bvandenbonKa-zamtypohhalreadydoneodCattomasz-warnielloinohirokiParmuzinAlexanderygrekpliuphysinfinity0yzyrayrexl2018gjm11bvandenbon-objtYi-KaiDuskEaglenjfoxkomu LizzieConfig.prompt.selectEngine=Please select a engine LizzieConfig.prompt.selectWeight=Please select a weight file +LizzieConfig.prompt.selectConfig=Please select a config file LizzieConfig.button.ok=OK LizzieConfig.button.cancel=Cancel LizzieConfig.button.add=Add