Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick hack to support #785 (<nickname> before the engine command) #787

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/main/java/featurecat/lizzie/analysis/Leelaz.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class Leelaz {

// for Multiple Engine
private String engineCommand;
private String engineNickname;
private List<String> commands;
private JSONObject config;
private String currentWeightFile = "";
Expand Down Expand Up @@ -128,7 +129,8 @@ public Leelaz(String engineCommand) throws JSONException {
// substitute in the weights file
engineCommand = engineCommand.replaceAll("%network-file", config.getString("network-file"));
}
this.engineCommand = engineCommand;
updateEngineCommandAndNickname(engineCommand);
engineCommand = this.engineCommand;
if (engineCommand.toLowerCase().contains("override-version")) {
this.isKataGo = true;
}
Expand Down Expand Up @@ -946,7 +948,8 @@ public List<String> splitCommand(String commandLine) {
}

public boolean isCommandChange(String command) {
List<String> newList = splitCommand(command);
updateEngineCommandAndNickname(command);
List<String> newList = splitCommand(engineCommand);
if (this.commands.size() != newList.size()) {
engineIndex++;
return true;
Expand All @@ -964,6 +967,17 @@ public boolean isCommandChange(String command) {
}
}

private void updateEngineCommandAndNickname(String command) {
Matcher nicknameMatcher = Pattern.compile("<(.*?)>\\s*(.*)").matcher(command);
if (nicknameMatcher.matches()) {
engineNickname = nicknameMatcher.group(1);
engineCommand = nicknameMatcher.group(2);
} else {
engineNickname = null;
engineCommand = command;
}
}

public boolean isStarted() {
return started;
}
Expand All @@ -987,6 +1001,10 @@ public boolean supportScoremean() {
return isKataGo || supportScoremean;
}

public String nicknameOrCurrentWeight() {
return (engineNickname == null) ? currentWeight : engineNickname;
}

public String currentWeight() {
return currentWeight;
}
Expand All @@ -1006,6 +1024,10 @@ public int currentEngineN() {
return currentEngineN;
}

public String nicknameOrEngineCommand() {
return (engineNickname == null) ? engineCommand : engineNickname;
}

public String engineCommand() {
return this.engineCommand;
}
Expand Down
47 changes: 25 additions & 22 deletions src/main/java/featurecat/lizzie/gui/ConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@ public class ConfigDialog extends JDialog {
public JButton okButton;

// Engine Tab
private JTextField txtEngine;
private JTextField txtEngine1;
private JTextField txtEngine2;
private JTextField txtEngine3;
private JTextField txtEngine4;
private JTextField txtEngine5;
private JTextField txtEngine6;
private JTextField txtEngine7;
private JTextField txtEngine8;
private JTextField txtEngine9;
private JTextField[] txts;
private LeftTextField txtEngine;
private LeftTextField txtEngine1;
private LeftTextField txtEngine2;
private LeftTextField txtEngine3;
private LeftTextField txtEngine4;
private LeftTextField txtEngine5;
private LeftTextField txtEngine6;
private LeftTextField txtEngine7;
private LeftTextField txtEngine8;
private LeftTextField txtEngine9;
private LeftTextField[] txts;
private JCheckBox chkPreload1;
private JCheckBox chkPreload2;
private JCheckBox chkPreload3;
Expand Down Expand Up @@ -270,7 +270,7 @@ public void actionPerformed(ActionEvent e) {
lblEngine.setHorizontalAlignment(SwingConstants.LEFT);
engineTab.add(lblEngine);

txtEngine = new JTextField();
txtEngine = new LeftTextField();
txtEngine.setBounds(87, 40, 481, 26);
engineTab.add(txtEngine);
txtEngine.setColumns(10);
Expand All @@ -285,7 +285,7 @@ public void actionPerformed(ActionEvent e) {
lblEngine1.setBounds(6, 80, 92, 16);
engineTab.add(lblEngine1);

txtEngine2 = new JTextField();
txtEngine2 = new LeftTextField();
txtEngine2.setColumns(10);
txtEngine2.setBounds(87, 105, 481, 26);
engineTab.add(txtEngine2);
Expand All @@ -298,7 +298,7 @@ public void actionPerformed(ActionEvent e) {
lblEngine2.setBounds(6, 110, 92, 16);
engineTab.add(lblEngine2);

txtEngine1 = new JTextField();
txtEngine1 = new LeftTextField();
txtEngine1.setColumns(10);
txtEngine1.setBounds(87, 75, 481, 26);
engineTab.add(txtEngine1);
Expand All @@ -311,7 +311,7 @@ public void actionPerformed(ActionEvent e) {
lblEngine3.setBounds(6, 140, 92, 16);
engineTab.add(lblEngine3);

txtEngine3 = new JTextField();
txtEngine3 = new LeftTextField();
txtEngine3.setColumns(10);
txtEngine3.setBounds(87, 135, 481, 26);
engineTab.add(txtEngine3);
Expand All @@ -324,7 +324,7 @@ public void actionPerformed(ActionEvent e) {
lblEngine4.setBounds(6, 170, 92, 16);
engineTab.add(lblEngine4);

txtEngine4 = new JTextField();
txtEngine4 = new LeftTextField();
txtEngine4.setColumns(10);
txtEngine4.setBounds(87, 165, 481, 26);
engineTab.add(txtEngine4);
Expand All @@ -337,7 +337,7 @@ public void actionPerformed(ActionEvent e) {
lblEngine5.setBounds(6, 200, 92, 16);
engineTab.add(lblEngine5);

txtEngine5 = new JTextField();
txtEngine5 = new LeftTextField();
txtEngine5.setColumns(10);
txtEngine5.setBounds(87, 195, 481, 26);
engineTab.add(txtEngine5);
Expand All @@ -350,7 +350,7 @@ public void actionPerformed(ActionEvent e) {
lblEngine6.setBounds(6, 230, 92, 16);
engineTab.add(lblEngine6);

txtEngine6 = new JTextField();
txtEngine6 = new LeftTextField();
txtEngine6.setColumns(10);
txtEngine6.setBounds(87, 225, 481, 26);
engineTab.add(txtEngine6);
Expand All @@ -363,7 +363,7 @@ public void actionPerformed(ActionEvent e) {
lblEngine7.setBounds(6, 260, 92, 16);
engineTab.add(lblEngine7);

txtEngine7 = new JTextField();
txtEngine7 = new LeftTextField();
txtEngine7.setColumns(10);
txtEngine7.setBounds(87, 255, 481, 26);
engineTab.add(txtEngine7);
Expand All @@ -376,15 +376,15 @@ public void actionPerformed(ActionEvent e) {
lblEngine8.setBounds(6, 290, 92, 16);
engineTab.add(lblEngine8);

txtEngine8 = new JTextField();
txtEngine8 = new LeftTextField();
txtEngine8.setColumns(10);
txtEngine8.setBounds(87, 285, 481, 26);
engineTab.add(txtEngine8);
chkPreload8 = new JCheckBox();
chkPreload8.setBounds(570, 286, 23, 23);
engineTab.add(chkPreload8);

txtEngine9 = new JTextField();
txtEngine9 = new LeftTextField();
txtEngine9.setColumns(10);
txtEngine9.setBounds(87, 315, 481, 26);
engineTab.add(txtEngine9);
Expand Down Expand Up @@ -738,7 +738,7 @@ protected DocumentFilter getDocumentFilter() {

// Engines
txts =
new JTextField[] {
new LeftTextField[] {
txtEngine1,
txtEngine2,
txtEngine3,
Expand All @@ -761,6 +761,9 @@ protected DocumentFilter getDocumentFilter() {
txts[i].setText(a.getString(i));
});
});
Arrays.asList(txts)
.stream()
.forEach(t -> t.setToolTipText("Engine Command or <Label> Engine Command"));

chkPreloads =
new JCheckBox[] {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/featurecat/lizzie/gui/LeftTextField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package featurecat.lizzie.gui;

import javax.swing.JTextField;

// Ensure that the beginning of long text is visible after setText.

public class LeftTextField extends JTextField {

public void setText(String t) {
super.setText(t);
setCaretPosition(0);
}
}
2 changes: 1 addition & 1 deletion src/main/java/featurecat/lizzie/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public void setPlayers(String whitePlayer, String blackPlayer) {
public void updateTitle() {
StringBuilder sb = new StringBuilder(DEFAULT_TITLE);
sb.append(playerTitle);
sb.append(" [" + Lizzie.leelaz.engineCommand() + "]");
sb.append(visitsString);
sb.append(" [" + Lizzie.leelaz.nicknameOrEngineCommand() + "]");
setTitle(sb.toString());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/featurecat/lizzie/gui/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -1384,8 +1384,8 @@ public void updateEngineMenu(List<Leelaz> engineList) {
engine[i].setVisible(false);
Leelaz engineDt = engineList.get(i);
if (engineDt != null) {
if (engineDt.currentWeight() != "")
engine[i].setText(engine[i].getText() + " : " + engineDt.currentWeight());
if (engineDt.nicknameOrCurrentWeight() != "")
engine[i].setText(engine[i].getText() + " : " + engineDt.nicknameOrCurrentWeight());
engine[i].setVisible(true);
int a = i;
engine[i].addActionListener(
Expand Down