Skip to content

Commit

Permalink
Add "-config" in engine setting for KataGo (featurecat#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed Jan 14, 2023
1 parent 4e6994d commit 35afed8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
18 changes: 17 additions & 1 deletion src/main/java/featurecat/lizzie/gui/ConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class ConfigDialog extends JDialog {

public String enginePath = "";
public String weightPath = "";
public String configPath = "";
public String commandHelp = "";

private String osName;
Expand Down Expand Up @@ -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;
Expand All @@ -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!
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/featurecat/lizzie/gui/EngineParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 =
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 @@ -149,6 +149,7 @@ LizzieConfig.lizzie.contributorsTitle=<html><a href="https://github.com/featurec
LizzieConfig.lizzie.contributors=<html><table><tr><td><a href="https://github.com/cngoodboy">cngoodboy</a></td><td><a href="https://github.com/kaorahi">kaorahi</a></td><td><a href="https://github.com/zsalch">zsalch</a></td></tr><tr><td><a href="https://github.com/bittsitt">bittsitt</a></td><td><a href="https://github.com/OlivierBlanvillain">OlivierBlanvillain</a></td><td><a href="https://github.com/dfannius">dfannius</a></td></tr><tr><td><a href="https://github.com/toomasr">toomasr</a></td><td><a href="https://github.com/apetresc">apetresc</a></td><td><a href="https://github.com/TFiFiE">TFiFiE</a></td></tr><tr><td><a href="https://github.com/aerisnju">aerisnju</a></td><td><a href="https://github.com/kuba97531">kuba97531</a></td><td><a href="https://github.com/bvandenbon">bvandenbon</a></td></tr><tr><td><a href="https://github.com/Ka-zam">Ka-zam</a></td><td><a href="https://github.com/typohh">typohh</a></td><td><a href="https://github.com/alreadydone">alreadydone</a></td></tr><tr><td><a href="https://github.com/odCat">odCat</a></td><td><a href="https://github.com/tomasz-warniello">tomasz-warniello</a></td><td><a href="https://github.com/inohiroki">inohiroki</a></td></tr><tr><td><a href="https://github.com/ParmuzinAlexander">ParmuzinAlexander</a></td><td><a href="https://github.com/ygrek">ygrek</a></td><td><a href="https://github.com/pliuphys">pliuphys</a></td></tr><tr><td><a href="https://github.com/infinity0">infinity0</a></td><td><a href="https://github.com/yzyray">yzyray</a></td><td><a href="https://github.com/rexl2018">rexl2018</a></td></tr><tr><td><a href="https://github.com/gjm11">gjm11</a></td><td><a href="https://github.com/bvandenbon-objt">bvandenbon-objt</a></td><td><a href="https://github.com/Yi-Kai">Yi-Kai</a></td></tr><tr><td><a href="https://github.com/DuskEagle">DuskEagle</a></td><td><a href="https://github.com/njfox">njfox</a></td><td><a href="https://github.com/komu">komu</a></td></tr></table></html>
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
Expand Down

0 comments on commit 35afed8

Please sign in to comment.