Skip to content

Commit

Permalink
chore: make the return of winner -> Option<Option<Color>>
Browse files Browse the repository at this point in the history
  • Loading branch information
raklaptudirm committed Dec 27, 2024
1 parent 507971a commit 4242003
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions games/src/ataxx/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl PositionType for Position {
white == BitBoard::EMPTY || black == BitBoard::EMPTY // No pieces left
}

fn winner(&self) -> Option<Color> {
fn winner(&self) -> Option<Option<Color>> {
if self.half_move_clock >= 100 {
// Draw by 50 move rule.
return None;
Expand All @@ -124,10 +124,10 @@ impl PositionType for Position {

if black == BitBoard::EMPTY {
// Black lost all its pieces, White won.
return Some(Color::White);
return Some(Some(Color::White));
} else if white == BitBoard::EMPTY {
// White lost all its pieces, Black won.
return Some(Color::Black);
return Some(Some(Color::Black));
}

debug_assert!(black | white | block == BitBoard::UNIVERSE);
Expand All @@ -139,12 +139,12 @@ impl PositionType for Position {
let white_n = white.len();

match black_n.cmp(&white_n) {
cmp::Ordering::Less => Some(Color::White),
cmp::Ordering::Greater => Some(Color::Black),
cmp::Ordering::Less => Some(Some(Color::White)),
cmp::Ordering::Greater => Some(Some(Color::Black)),
// Though there can't be an equal number of black and white pieces
// on an empty ataxx board, it is possible with an odd number of
// blocker pieces.
cmp::Ordering::Equal => None,
cmp::Ordering::Equal => Some(None),
}
}

Expand Down
2 changes: 1 addition & 1 deletion games/src/chess/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl PositionType for Position {
false
}

fn winner(&self) -> Option<Color> {
fn winner(&self) -> Option<Option<Color>> {
None
}

Expand Down
2 changes: 1 addition & 1 deletion games/src/interface/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where

/// Returns the side which has won in the current position, if any.
#[must_use]
fn winner(&self) -> Option<Color<Self>>;
fn winner(&self) -> Option<Option<Color<Self>>>;
/// Returns `true` if the game is over in the current position.
#[must_use]
fn is_game_over(&self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions games/src/isolation/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ impl PositionType for Position {
self.count_moves::<true, true>() == 0
}

fn winner(&self) -> Option<Color> {
fn winner(&self) -> Option<Option<Color>> {
if self.is_game_over() {
Some(!self.side_to_move)
Some(Some(!self.side_to_move))
} else {
None
}
Expand Down

0 comments on commit 4242003

Please sign in to comment.