Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed Dec 29, 2020
2 parents a4209d7 + d72005d commit 2009f93
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/featurecat/lizzie/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class Config {
public boolean showKataGoEstimateOnMainboard = true;
public String kataGoEstimateMode = "small+dead";
public boolean kataGoEstimateBlend = true;
public String kataGoRule = "tromp-taylor";

public boolean showStatus = true;
public boolean showBranch = true;
Expand Down Expand Up @@ -283,6 +284,7 @@ public Config() throws IOException {
showKataGoEstimateOnMainboard = uiConfig.optBoolean("show-katago-estimate-onmainboard", true);
kataGoEstimateMode = uiConfig.optString("katago-estimate-mode", "small+dead");
kataGoEstimateBlend = uiConfig.optBoolean("katago-estimate-blend", true);
kataGoRule = uiConfig.optString("katago-rule", "tromp-taylor");
showWinrateInSuggestion = uiConfig.optBoolean("show-winrate-in-suggestion", true);
showPlayoutsInSuggestion = uiConfig.optBoolean("show-playouts-in-suggestion", true);
showScoremeanInSuggestion = uiConfig.optBoolean("show-scoremean-in-suggestion", true);
Expand Down Expand Up @@ -468,6 +470,11 @@ public void toggleKataGoEstimateBlend() {
uiConfig.put("katago-estimate-blend", kataGoEstimateBlend);
}

public void setKataGoRule(String rule) {
kataGoRule = rule;
uiConfig.put("katago-rule", kataGoRule);
}

public void toggleShowStatus() {
this.showStatus = toggleUIConfig("show-status");
}
Expand Down Expand Up @@ -608,6 +615,7 @@ private JSONObject createDefaultConfig() {
ui.put("show-katago-estimate-onmainboard", true);
ui.put("katago-estimate-mode", "small");
ui.put("katago-estimate-blend", true);
ui.put("katago-rule", "tromp-taylor");
config.put("ui", ui);
return config;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/featurecat/lizzie/Lizzie.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static void initializeEngineManager() {
}

public static void initializeAfterVersionCheck(Leelaz lz) {
lz.updateKataGoRule();
if (config.handicapInsteadOfWinrate) {
lz.estimatePassWinrate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void switchEngine(int index) {
if (!newEng.isStarted()) {
newEng.startEngine();
} else {
newEng.updateKataGoRule();
if (!newEng.isPondering()) {
newEng.togglePonder();
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/featurecat/lizzie/analysis/Leelaz.java
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,16 @@ public void setWeightName() {
}
}

public void updateKataGoRule() {
updateKataGoRule(false);
}

public void updateKataGoRule(boolean keepPondering) {
if (!isKataGo) return;
sendCommand("kata-set-rules " + Lizzie.config.kataGoRule);
if (isPondering && keepPondering) ponder();
}

// Writer thread for avoiding deadlock (#752)
class WriterThread extends Thread {
public ArrayDeque<String> writerQueue = new ArrayDeque<>();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/featurecat/lizzie/gui/BasicInfoPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ private void drawCaptured(Graphics2D g, int posX, int posY, int width, int heigh
g.drawString(bTime, posX + width / 10, posY + height / 6);
g.drawString(wTime, posX + width * 3 / 5, posY + height / 6);

// Rule
if (Lizzie.leelaz.isKataGo) {
String rule = Lizzie.config.kataGoRule;
int rw = g.getFontMetrics().stringWidth(rule);
g.drawString(rule, posX - strokeRadius + width / 2 - rw / 2, posY + height * 5 / 16);
}

// Komi
String komi =
GameInfoDialog.FORMAT_KOMI.format(Lizzie.board.getHistory().getGameInfo().getKomi());
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/featurecat/lizzie/gui/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ public class Menu extends JMenuBar {
public static JMenu engineMenu;
private static final ResourceBundle resourceBundle = MainFrame.resourceBundle;

private static JMenu kataGoRuleMenu;
private static final String[] kataGoRuleNames = {
"tromp-taylor",
"chinese",
"chinese-ogs",
"chinese-kgs",
"japanese",
"korean",
"stone-scoring",
"aga",
"bga",
"new-zealand",
"aga-button",
};

public Menu() {
setBorder(new EmptyBorder(0, 0, 0, 0));
final JMenu fileMenu = new JMenu(resourceBundle.getString("Menu.file"));
Expand Down Expand Up @@ -1316,6 +1331,35 @@ public void actionPerformed(ActionEvent e) {
});
analyzeMenu.add(estimate);

kataGoRuleMenu = new JMenu("Rule");
kataGoRuleMenu.setEnabled(false);
analyzeMenu.add(kataGoRuleMenu);

final ButtonGroup kataGoRuleGroup = new ButtonGroup();

for (String rule : kataGoRuleNames) {
boolean selected = rule.equals(Lizzie.config.kataGoRule);
JRadioButtonMenuItem item = new JRadioButtonMenuItem(rule, selected);
item.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (rule.equals(Lizzie.config.kataGoRule)) return;
Lizzie.config.setKataGoRule(rule);
Lizzie.leelaz.updateKataGoRule(true);
Lizzie.board.clearAnalysis();
Lizzie.frame.refresh();
try {
Lizzie.config.save();
} catch (IOException es) {
// TODO Auto-generated catch block
}
}
});
kataGoRuleGroup.add(item);
kataGoRuleMenu.add(item);
}

analyzeMenu.addMenuListener(
new MenuListener() {
public void menuSelected(MenuEvent e) {
Expand Down Expand Up @@ -1452,6 +1496,7 @@ public void updateEngineIcon(List<Leelaz> engineList, int currentEngineNo) {
if (i == currentEngineNo) {
engine[i].setIcon(running);
engineMenu.setText(engine[i].getText());
kataGoRuleMenu.setEnabled(engineDt.isKataGo);
} else if (engineDt.isLoaded()) engine[i].setIcon(ready);
else if (engine[i].getIcon() != null) engine[i].setIcon(null);
}
Expand Down

0 comments on commit 2009f93

Please sign in to comment.