Skip to content

Commit

Permalink
Modify default options depending on the engine (featurecat#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed Jan 14, 2023
1 parent 1cacd75 commit 03bfd1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
13 changes: 12 additions & 1 deletion src/main/java/featurecat/lizzie/gui/ConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,8 @@ private String getEngineLine() {
weightFile = chooserw.getSelectedFile();
if (weightFile != null) {
weightPath = relativizePath(weightFile.toPath(), this.curPath);
EngineParameter ep = new EngineParameter(enginePath, weightPath, this);
EngineParameter ep =
new EngineParameter(enginePath, weightPath, guessedEngineType(), this);
ep.setVisible(true);
if (!ep.commandLine.isEmpty()) {
engineLine = ep.commandLine;
Expand All @@ -1860,6 +1861,13 @@ private String getEngineLine() {
return engineLine;
}

private String guessedEngineType() {
String engineFileName = (new File(enginePath)).toPath().getFileName().toString();
// fixme: ad hoc!
Boolean isKataGo = engineFileName.toLowerCase().contains("katago");
return isKataGo ? "katago" : "leelaz";
}

private String getImagePath() {
String imagePath = "";
File imageFile = null;
Expand Down Expand Up @@ -1903,6 +1911,9 @@ private void getCommandHelp() {

List<String> commands = new ArrayList<String>();
commands.add(enginePath);
if (guessedEngineType().equals("katago")) {
commands.add("gtp");
}
commands.add("-h");

try {
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/featurecat/lizzie/gui/EngineParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class EngineParameter extends JDialog {
private Color oriColor;

/** Create the dialog. */
public EngineParameter(String enginePath, String weightPath, ConfigDialog configDialog) {
public EngineParameter(
String enginePath, String weightPath, String engineType, ConfigDialog configDialog) {
setTitle(configDialog.resourceBundle.getString("LizzieConfig.title.parameterConfig"));
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
setModal(true);
Expand All @@ -48,7 +49,8 @@ public EngineParameter(String enginePath, String weightPath, ConfigDialog config
txtCommandLine = new JTextField();
txtCommandLine.setEditable(false);
txtCommandLine.setBounds(89, 12, 565, 26);
txtCommandLine.setText(enginePath + " --weights " + weightPath);
String weightOption = (engineType.equals("leelaz")) ? " --weights " : " gtp -model ";
txtCommandLine.setText(enginePath + weightOption + weightPath);
contentPanel.add(txtCommandLine);
txtCommandLine.setColumns(10);
JLabel lblParameter =
Expand All @@ -67,7 +69,9 @@ public void focusLost(FocusEvent e) {
});
txtParameter.setColumns(10);
txtParameter.setBounds(89, 44, 565, 26);
txtParameter.setText("-g --lagbuffer 0 ");
if (engineType.equals("leelaz")) {
txtParameter.setText("-g --lagbuffer 0 ");
}
oriColor = txtParameter.getBackground();
contentPanel.add(txtParameter);

Expand Down Expand Up @@ -95,7 +99,7 @@ public void focusLost(FocusEvent e) {
okButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtParameter.getText().isEmpty()) {
if (txtParameter.getText().isEmpty() && engineType.equals("leelaz")) {
txtParameter.setBackground(Color.RED);
} else {
parameters = txtParameter.getText().trim();
Expand Down

0 comments on commit 03bfd1a

Please sign in to comment.