Skip to content

Commit

Permalink
Fixed comment with [ bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zsalch authored and zsalch committed Oct 25, 2018
1 parent e74bef6 commit 2382ee1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/featurecat/lizzie/rules/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public void place(int x, int y, Stone color, boolean newBranch) {

// check to see if this coordinate is being replayed in history
BoardData next = history.getNext();
if (next != null && next.lastMove != null && next.lastMove[0] == x && next.lastMove[1] == y) {
if (next != null && next.lastMove != null && next.lastMove[0] == x && next.lastMove[1] == y && !newBranch) {
// this is the next coordinate in history. Just increment history so that we don't erase the
// redo's
history.next();
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/featurecat/lizzie/rules/BoardData.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class BoardData {
public int whiteCaptures;

// Comment in the Sgf move
public String comment;
public String comment = "";

// Node properties
private final Map<String, String> properties = new HashMap<String, String>();
Expand Down Expand Up @@ -61,6 +61,9 @@ public BoardData(
*/
public void addProperty(String key, String value) {
SGFParser.addProperty(properties, key, value);
if ("N".equals(key) && comment.isEmpty()) {
comment = value;
}
}

/**
Expand Down
42 changes: 27 additions & 15 deletions src/main/java/featurecat/lizzie/rules/SGFParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ private static boolean parse(String value) {
// Save the variation step count
Map<Integer, Integer> subTreeStepMap = new HashMap<Integer, Integer>();
// Comment of the AW/AB (Add White/Add Black) stone
String awabComment = null;
String awabComment = "";
// Game properties
Map<String, String> gameProperties = new HashMap<String, String>();
boolean inTag = false,
isMultiGo = false,
escaping = false,
moveStart = false,
addPassForAwAb = true;
String tag = null;
boolean inProp = false;
String tag = "";
StringBuilder tagBuilder = new StringBuilder();
StringBuilder tagContentBuilder = new StringBuilder();
// MultiGo 's branch: (Main Branch (Main Branch) (Branch) )
Expand All @@ -118,6 +119,7 @@ private static boolean parse(String value) {
subTreeDepth += 1;
// Initialize the step count
subTreeStepMap.put(subTreeDepth, 0);
addPassForAwAb = true;
} else {
if (i > 0) {
// Allow the comment tag includes '('
Expand All @@ -141,25 +143,31 @@ private static boolean parse(String value) {
}
break;
case '[':
if (subTreeDepth > 1 && !isMultiGo) {
break;
}
inTag = true;
String tagTemp = tagBuilder.toString();
if (!tagTemp.isEmpty()) {
// Ignore small letters in tags for the long format Smart-Go file.
// (ex) "PlayerBlack" ==> "PB"
// It is the default format of mgt, an old SGF tool.
// (Mgt is still supported in Debian and Ubuntu.)
tag = tagTemp.replaceAll("[a-z]", "");
if (!inProp) {
inProp = true;
if (subTreeDepth > 1 && !isMultiGo) {
break;
}
inTag = true;
String tagTemp = tagBuilder.toString();
if (!tagTemp.isEmpty()) {
// Ignore small letters in tags for the long format Smart-Go file.
// (ex) "PlayerBlack" ==> "PB"
// It is the default format of mgt, an old SGF tool.
// (Mgt is still supported in Debian and Ubuntu.)
tag = tagTemp.replaceAll("[a-z]", "");
}
tagContentBuilder = new StringBuilder();
} else {
tagContentBuilder.append(c);
}
tagContentBuilder = new StringBuilder();
break;
case ']':
if (subTreeDepth > 1 && !isMultiGo) {
break;
}
inTag = false;
inProp = false;
tagBuilder = new StringBuilder();
String tagContent = tagContentBuilder.toString();
// We got tag, we can parse this tag now.
Expand Down Expand Up @@ -190,6 +198,8 @@ private static boolean parse(String value) {
// add to node properties
Lizzie.board.addNodeProperty(tag, tagContent);
if (addPassForAwAb) {
// Save the step count
subTreeStepMap.put(subTreeDepth, subTreeStepMap.get(subTreeDepth) + 1);
Lizzie.board.pass(color);
addPassForAwAb = false;
}
Expand Down Expand Up @@ -226,6 +236,8 @@ private static boolean parse(String value) {
} else if ("AE".equals(tag)) {
// remove a stone
if (addPassForAwAb) {
// Save the step count
subTreeStepMap.put(subTreeDepth, subTreeStepMap.get(subTreeDepth) + 1);
Lizzie.board.pass(tag.equals("AB") ? Stone.BLACK : Stone.WHITE);
addPassForAwAb = false;
}
Expand Down Expand Up @@ -266,7 +278,7 @@ private static boolean parse(String value) {
while (Lizzie.board.previousMove()) ;

// Set AW/AB Comment
if (awabComment != null) {
if (!awabComment.isEmpty()) {
Lizzie.board.comment(awabComment);
}
if (gameProperties.size() > 0) {
Expand Down

0 comments on commit 2382ee1

Please sign in to comment.