Skip to content

Commit

Permalink
Merge pull request #272 from kaorahi/komi_sgf
Browse files Browse the repository at this point in the history
Fix issues on komi and handicap in SGF reader
  • Loading branch information
featurecat authored Jun 2, 2018
2 parents a2873d6 + 153c4e7 commit 1912f4a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/featurecat/lizzie/rules/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,10 @@ public void flatten() {
Stone[] stones = history.getStones();
boolean blackToPlay = history.isBlacksTurn();
Zobrist zobrist = history.getZobrist().clone();
BoardHistoryList oldHistory = history;
history = new BoardHistoryList(new BoardData(stones, null, Stone.EMPTY, blackToPlay, zobrist,
0, new int[BOARD_SIZE * BOARD_SIZE], 0, 0, 0.0, 0));
history.setGameInfo(oldHistory.getGameInfo());
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/featurecat/lizzie/rules/BoardHistoryList.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public GameInfo getGameInfo() {
return gameInfo;
}

public void setGameInfo(GameInfo gameInfo) {
this.gameInfo = gameInfo;
}

/**
* Clear history.
*/
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/featurecat/lizzie/rules/SGFParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,14 @@ private static boolean parse(String value) {
} else if (tag.equals("PW")) {
whitePlayer = tagContent;
} else if (tag.equals("KM")) {
Lizzie.board.getHistory().getGameInfo().setKomi(Double.parseDouble(tagContent));
try {
if (tagContent.trim().isEmpty()) {
tagContent = "0.0";
}
Lizzie.board.getHistory().getGameInfo().setKomi(Double.parseDouble(tagContent));
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
break;
case ';':
Expand Down

0 comments on commit 1912f4a

Please sign in to comment.