Skip to content

Commit

Permalink
Don't mark a position as decided of the winner would flip
Browse files Browse the repository at this point in the history
  • Loading branch information
ujh committed Dec 17, 2015
1 parent 8c0c9dd commit 45b44ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/ownership/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ impl OwnershipStatistics {
.all(|coord| self.owner(coord) != Empty)
}

pub fn winner(&self) -> Color {
let mut bs = 0.0;
let mut ws = self.komi;
for coord in Coord::for_board_size(self.size) {
match self.owner(&coord) {
Black => { bs += 1.0; },
White => { ws += 1.0; },
Empty => {}
}
}
if ws == bs {
Empty
} else if ws > bs {
White
} else {
Black
}
}

fn value_for_coord(&self, coord: Coord) -> f64 {
match self.owner(&coord) {
Black => 1.0,
Expand Down
3 changes: 2 additions & 1 deletion src/score/final_score/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ impl FinalScore {
for coord in &dead {
board.remove_dead_stone(coord);
}
let decided = ownership.decided() && board.winner() == ownership.winner();
FinalScore {
board: board,
decided: ownership.decided(),
decided: decided,
dead: dead,
}
} else {
Expand Down

0 comments on commit 45b44ba

Please sign in to comment.