Skip to content

Commit

Permalink
Merge #760
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed Sep 28, 2020
2 parents 013e796 + 63753f2 commit f400bf5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/featurecat/lizzie/rules/SGFParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ private static BoardHistoryList parseValue(
String tag = "";
StringBuilder tagBuilder = new StringBuilder();
StringBuilder tagContentBuilder = new StringBuilder();
// for Fox SGF
boolean isFox = false;
String rule = "";
// MultiGo 's branch: (Main Branch (Main Branch) (Branch) )
// Other 's branch: (Main Branch (Branch) Main Branch)
if (value.matches("(?s).*\\)\\s*\\)")) {
Expand Down Expand Up @@ -404,6 +407,14 @@ private static BoardHistoryList parseValue(
} catch (NumberFormatException e) {
e.printStackTrace();
}
} else if (tag.equals("AP")) {
if ("foxwq".equals(tagContent)) {
// Beware: Fox SGF has two AP[]. (2020-09-26)
// ...AP[GNU Go:3.8]RE[B+3.50]TM[10800]TC[5]TT[60]AP[foxwq]...
isFox = true;
}
} else if (tag.equals("RU")) {
rule = tagContent;
} else {
if (moveStart) {
// Other SGF node properties
Expand Down Expand Up @@ -523,9 +534,27 @@ private static BoardHistoryList parseValue(
}
}
}
if (isFox) {
fixFoxSGF(history, rule);
}
return history;
}

private static void fixFoxSGF(BoardHistoryList history, String rule) {
BoardHistoryList validHistory = (history == null ? Lizzie.board.getHistory() : history);
String lowerCaseRule = rule.toLowerCase();
// ref. https://github.com/sanderland/katrain/issues/177
double correctedKomi =
(validHistory.getGameInfo().getHandicap() >= 1)
? 0.5
: (lowerCaseRule.equals("chinese") || lowerCaseRule.equals("cn")) ? 7.5 : 6.5;
if (history == null) {
Lizzie.board.setKomi(correctedKomi);
} else {
history.getGameInfo().setKomi(correctedKomi);
}
}

public static String saveToString() throws IOException {
try (StringWriter writer = new StringWriter()) {
saveToStream(Lizzie.board, writer);
Expand Down

0 comments on commit f400bf5

Please sign in to comment.