Skip to content

Commit

Permalink
Merge pull request #712 from kaorahi/fix707_flip
Browse files Browse the repository at this point in the history
Maybe fix #707 (score/win-rate flips)
  • Loading branch information
featurecat authored May 26, 2020
2 parents aa77210 + af2ac8c commit 6432172
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/java/featurecat/lizzie/analysis/Leelaz.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class Leelaz {
private int cmdNumber;
private int currentCmdNum;
private ArrayDeque<String> cmdQueue;
private boolean isModifyingBoard = false;

private Process process;

Expand Down Expand Up @@ -305,7 +306,7 @@ private void parseLine(String line) {
switching = false;
// Display engine command in the title
Lizzie.frame.updateTitle();
if (isResponseUpToDate()) {
if (isAnalysisUpToDate()) {
// This should not be stale data when the command number match
if (isKataGo) {
this.bestMoves = parseInfoKatago(line.substring(5));
Expand Down Expand Up @@ -537,6 +538,22 @@ private boolean isResponseUpToDate() {
return currentCmdNum >= cmdNumber - 1;
}

private boolean isAnalysisUpToDate() {
return !isModifyingBoard && isResponseUpToDate();
}

public void beginModifyingBoard() {
synchronized (this) {
isModifyingBoard = true;
}
}

public void endModifyingBoard() {
synchronized (this) {
isModifyingBoard = false;
}
}

/**
* @param color color of stone to play
* @param move coordinate of the coordinate
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/featurecat/lizzie/rules/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ public void place(int x, int y, Stone color, boolean newBranch, boolean changeMo
&& !changeMove) {
// this is the next coordinate in history. Just increment history so that we don't erase the
// redo's
Lizzie.leelaz.beginModifyingBoard();
history.next();
// should be opposite from the bottom case
if (Lizzie.frame.isPlayingAgainstLeelaz
Expand All @@ -510,6 +511,7 @@ public void place(int x, int y, Stone color, boolean newBranch, boolean changeMo
} else if (!Lizzie.frame.isPlayingAgainstLeelaz) {
Lizzie.leelaz.playMove(color, convertCoordinatesToName(x, y));
}
Lizzie.leelaz.endModifyingBoard();
return;
}

Expand Down Expand Up @@ -572,6 +574,7 @@ public void place(int x, int y, Stone color, boolean newBranch, boolean changeMo
if (isSuicidal > 0 || history.violatesKoRule(newState)) return;

// update leelaz with board position
Lizzie.leelaz.beginModifyingBoard();
if (Lizzie.frame.isPlayingAgainstLeelaz
&& Lizzie.frame.playerIsBlack == getData().blackToPlay) {
Lizzie.leelaz.playMove(color, convertCoordinatesToName(x, y));
Expand All @@ -582,6 +585,7 @@ public void place(int x, int y, Stone color, boolean newBranch, boolean changeMo

// update history with this coordinate
history.addOrGoto(newState, newBranch, changeMove);
Lizzie.leelaz.endModifyingBoard();

Lizzie.frame.refresh();
}
Expand Down Expand Up @@ -759,6 +763,7 @@ public boolean nextMove() {
}
synchronized (this) {
updateWinrate();
Lizzie.leelaz.beginModifyingBoard();
if (history.next().isPresent()) {
// update leelaz board position, before updating to next node
Optional<int[]> lastMoveOpt = history.getData().lastMove;
Expand All @@ -770,8 +775,10 @@ public boolean nextMove() {
Lizzie.leelaz.playMove(history.getLastMoveColor(), "pass");
}
Lizzie.frame.refresh();
Lizzie.leelaz.endModifyingBoard();
return true;
}
Lizzie.leelaz.endModifyingBoard();
return false;
}
}
Expand Down Expand Up @@ -1115,11 +1122,14 @@ public boolean previousMove() {
synchronized (this) {
if (inScoreMode()) setScoreMode(false);
updateWinrate();
Lizzie.leelaz.beginModifyingBoard();
if (history.previous().isPresent()) {
Lizzie.leelaz.undo();
Lizzie.frame.refresh();
Lizzie.leelaz.endModifyingBoard();
return true;
}
Lizzie.leelaz.endModifyingBoard();
return false;
}
}
Expand Down

0 comments on commit 6432172

Please sign in to comment.