Skip to content

Commit

Permalink
Add "Set humanSL profile" to "Game" menu for the latest unreleased Ka…
Browse files Browse the repository at this point in the history
…taGo.
  • Loading branch information
kaorahi committed Jul 11, 2024
1 parent cd75f30 commit 7f6c672
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void switchEngine(int index) {
if (!newEng.isPondering()) {
newEng.togglePonder();
}
Lizzie.frame.enableHumanSLProfileMenu(newEng.hasHumanModel);
}
Lizzie.board.restoreMoveNumber();
this.currentEngineNo = index;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/featurecat/lizzie/analysis/Leelaz.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class Leelaz {
private ScheduledExecutorService executor;
private boolean isQuittingNormally = false;
private boolean isDown = false;
public boolean hasHumanModel = false;
public String humanSLProfile = null; // null = "no profile"

// dynamic komi and opponent komi as reported by dynamic-komi version of leelaz
private float dynamicKomi = Float.NaN;
Expand Down Expand Up @@ -477,6 +479,12 @@ private void parseLine(String line) {
Lizzie.initializeAfterVersionCheck(this);
}
}
if (line.startsWith("Human SL model name:")) {
// Read stderr to check humanSL model as a quick hack.
// FIXME: We should use kata-get-models instead to do this check correctly.
hasHumanModel = true;
Lizzie.frame.enableHumanSLProfileMenu(hasHumanModel);
}
}
}

Expand Down Expand Up @@ -623,7 +631,14 @@ public void playMove(Stone color, String move) {
}
}

private void setHumanSLProfile(boolean on) {
if (!hasHumanModel) return;
String profile = (on && humanSLProfile != null) ? humanSLProfile : "";
sendCommand("kata-set-param humanSLProfile " + profile);
}

public void genmove(String color) {
setHumanSLProfile(true);
String command = "genmove " + color;
/*
* We don't support displaying this while playing, so no reason to request it (for now)
Expand All @@ -636,6 +651,7 @@ public void genmove(String color) {
}

public void genmove_analyze(String color) {
setHumanSLProfile(true);
String command =
"lz-genmove_analyze "
+ color
Expand Down Expand Up @@ -722,6 +738,7 @@ public void analyzeAvoid(String parameters) {
public void ponder() {
isPondering = true;
startPonderTime = System.currentTimeMillis();
setHumanSLProfile(false);
if (Lizzie.board.isAvoding
&& Lizzie.board.isKeepingAvoid
&& !isKataGo
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,11 @@ protected void updateScoreMenuInEDT(boolean on) {
menu.updateScoreMenu(on);
}

protected void enableHumanSLProfileMenuInEDT(boolean enabled) {
Utils.mustBeEventDispatchThread();
menu.enableHumanSLProfileMenu(enabled);
}

public boolean openRightClickMenu(int x, int y) {
if (Lizzie.leelaz.isKataGo && !Lizzie.frame.isMouseOver) {
return false;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/featurecat/lizzie/gui/LizzieMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,11 @@ protected void updateScoreMenuInEDT(boolean on) {
menu.updateScoreMenu(on);
}

protected void enableHumanSLProfileMenuInEDT(boolean enabled) {
Utils.mustBeEventDispatchThread();
menu.enableHumanSLProfileMenu(enabled);
}

public boolean openRightClickMenu(int x, int y) {
if (Lizzie.leelaz.isKataGo && !Lizzie.frame.isMouseOver) {
return false;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/featurecat/lizzie/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ private void updateTitleInEDT() {
StringBuilder sb = new StringBuilder(DEFAULT_TITLE);
sb.append(playerTitle);
sb.append(visitsString);
if (Lizzie.leelaz.hasHumanModel && Lizzie.leelaz.humanSLProfile != null) {
sb.append(" (" + Lizzie.leelaz.humanSLProfile + ")");
}
sb.append(" [" + Lizzie.leelaz.nicknameOrEngineCommand() + "]");
setTitle(sb.toString());
}
Expand Down Expand Up @@ -533,6 +536,12 @@ public void run() {

protected abstract void updateScoreMenuInEDT(boolean on);

public void enableHumanSLProfileMenu(boolean enabled) {
SwingUtilities.invokeLater(() -> enableHumanSLProfileMenuInEDT(enabled));
}

protected abstract void enableHumanSLProfileMenuInEDT(boolean enabled);

public abstract boolean openRightClickMenu(int x, int y);

public abstract void clearBeforeMove();
Expand Down
110 changes: 110 additions & 0 deletions src/main/java/featurecat/lizzie/gui/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Menu extends JMenuBar {
private static final ResourceBundle resourceBundle = MainFrame.resourceBundle;

private static JMenu kataGoRuleMenu;
private static JMenu setHumanSLProfile;
private static final String[] kataGoRuleNames = {
"tromp-taylor",
"chinese",
Expand All @@ -41,6 +42,86 @@ public class Menu extends JMenuBar {
"new-zealand",
"aga-button",
};
private static final String[] humaSLProfilesRank = {
"rank_9d",
"rank_8d",
"rank_7d",
"rank_6d",
"rank_5d",
"rank_4d",
"rank_3d",
"rank_2d",
"rank_1d",
"rank_1k",
"rank_2k",
"rank_3k",
"rank_4k",
"rank_5k",
"rank_6k",
"rank_7k",
"rank_8k",
"rank_9k",
"rank_10k",
"rank_11k",
"rank_12k",
"rank_13k",
"rank_14k",
"rank_15k",
"rank_16k",
"rank_17k",
"rank_18k",
"rank_19k",
"rank_20k",
};
private static final String[] humaSLProfilesPreAZ = {
"preaz_9d",
"preaz_8d",
"preaz_7d",
"preaz_6d",
"preaz_5d",
"preaz_4d",
"preaz_3d",
"preaz_2d",
"preaz_1d",
"preaz_1k",
"preaz_2k",
"preaz_3k",
"preaz_4k",
"preaz_5k",
"preaz_6k",
"preaz_7k",
"preaz_8k",
"preaz_9k",
"preaz_10k",
"preaz_11k",
"preaz_12k",
"preaz_13k",
"preaz_14k",
"preaz_15k",
"preaz_16k",
"preaz_17k",
"preaz_18k",
"preaz_19k",
"preaz_20k",
};
private static final String[] humaSLProfilesProYear = {
"proyear_1800",
"proyear_1850",
"proyear_1900",
"proyear_1950",
"proyear_1960",
"proyear_1970",
"proyear_1980",
"proyear_1990",
"proyear_2000",
"proyear_2005",
"proyear_2010",
"proyear_2015",
"proyear_2017",
"proyear_2019",
"proyear_2021",
"proyear_2023",
};

public Menu() {
setBorder(new EmptyBorder(0, 0, 0, 0));
Expand Down Expand Up @@ -1185,6 +1266,15 @@ public void actionPerformed(ActionEvent e) {
});
gameMenu.add(setInfo);

setHumanSLProfile = new JMenu(resourceBundle.getString("Menu.game.setHumanSLProfile"));
setHumanSLProfile.setEnabled(false);
gameMenu.add(setHumanSLProfile);
addHumanSLProfileMenu("Rank", humaSLProfilesRank, setHumanSLProfile);
addHumanSLProfileMenu("PreAZ", humaSLProfilesPreAZ, setHumanSLProfile);
addHumanSLProfileMenu("ProYear", humaSLProfilesProYear, setHumanSLProfile);
addHumanSLProfileMenuItem(
resourceBundle.getString("Menu.game.resetHumanSLProfile"), null, setHumanSLProfile);

final JMenuItem bestOne = new JMenuItem(resourceBundle.getString("Menu.game.bestOne"));
bestOne.addActionListener(
new ActionListener() {
Expand Down Expand Up @@ -1512,6 +1602,22 @@ public void actionPerformed(ActionEvent e) {
helpMenu.add(keyboardControlsHelp);
}

private void addHumanSLProfileMenuItem(String label, String profile, JMenu parentMenu) {
final JMenuItem item = new JMenuItem(label);
item.addActionListener(
e -> {
Lizzie.leelaz.humanSLProfile = profile;
Lizzie.frame.updateTitle();
});
parentMenu.add(item);
}

private void addHumanSLProfileMenu(String label, String profiles[], JMenu parentMenu) {
final JMenu menu = new JMenu(label);
parentMenu.add(menu);
for (String profile : profiles) addHumanSLProfileMenuItem(profile, profile, menu);
}

private void browse(String uriString) {
if (Desktop.isDesktopSupported()) {
try {
Expand All @@ -1525,6 +1631,10 @@ public void updateScoreMenu(boolean on) {
scoreMode.setSelected(on);
}

public void enableHumanSLProfileMenu(boolean enabled) {
setHumanSLProfile.setEnabled(enabled);
}

public void updateEngineMenu(List<Leelaz> engineList) {
engine = new JMenuItem[engineList.size()];
engineMenu.removeAll();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/DisplayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ Menu.game.continueGameBlack=Continue(Play black)
Menu.game.continueGameWhite=Continue(Play white)
Menu.game.breakGame=Interrupt game(Space)
Menu.game.setInfo=Set gameInfo(I)
Menu.game.setHumanSLProfile=Set humanSL profile
Menu.game.resetHumanSLProfile=normal KataGo
Menu.game.bestOne=Play best move(,)
Menu.game.continueLadder=Continue ladder
Menu.game.continueLadderFail=Play at least %d ladder moves successively before auto-continuation.
Expand Down

0 comments on commit 7f6c672

Please sign in to comment.