lizzie
lizzie copied to clipboard
Avoid use recursion
Recursion is slow and lead to StackOverflowError when saving extremly big analyed game like: test52_52.zip
It seems that (
and )
are missing for variations. (;B[aa](;W[ba])(;W[ab]))
is saved as (;B[aa];W[ba];W[ab])
wrongly.
- Paste the first SGF to Lizzie.
- Type Ctrl-C.
- Type Ctrl-V.
Then the variation tree is changed with this PR. It is not changed in the original Lizzie 0.7.4.
a crude fix?
--- a/src/main/java/featurecat/lizzie/rules/SGFParser.java
+++ b/src/main/java/featurecat/lizzie/rules/SGFParser.java
@@ -684,14 +684,28 @@ public class SGFParser {
// * with 'xy' = coordinates ; or 'tt' for pass.
// Write variation tree
+ BoardHistoryNode markerBeg = new BoardHistoryNode(null);
+ BoardHistoryNode markerEnd = new BoardHistoryNode(null);
Stack<BoardHistoryNode> stack = new Stack<>();
stack.push(history.getCurrentHistoryNode());
while (!stack.isEmpty()) {
BoardHistoryNode cur = stack.pop();
+ if (cur == markerBeg) {
+ builder.append('(');
+ continue;
+ }
+ if (cur == markerEnd) {
+ builder.append(')');
+ continue;
+ }
builder.append(generateNode(board, cur));
+ boolean hasBrothers = (cur.numberOfChildren() > 1);
if (cur.numberOfChildren() >= 1) {
- for (int i = cur.numberOfChildren() - 1; i >= 0; i--)
+ for (int i = cur.numberOfChildren() - 1; i >= 0; i--) {
+ if (hasBrothers) stack.push(markerEnd);
stack.push(cur.getVariations().get(i));
+ if (hasBrothers) stack.push(markerBeg);
+ }
}
}
// close file
Yes, I forgot the important "()",I think your fix is great.