From 42420031d0dabb5c0e655e5bc11a75880ab022c5 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Fri, 27 Dec 2024 22:56:05 +0530 Subject: [PATCH] chore: make the return of winner -> Option> --- games/src/ataxx/position.rs | 12 ++++++------ games/src/chess/position.rs | 2 +- games/src/interface/position.rs | 2 +- games/src/isolation/position.rs | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/games/src/ataxx/position.rs b/games/src/ataxx/position.rs index d114a29..356f3c7 100644 --- a/games/src/ataxx/position.rs +++ b/games/src/ataxx/position.rs @@ -112,7 +112,7 @@ impl PositionType for Position { white == BitBoard::EMPTY || black == BitBoard::EMPTY // No pieces left } - fn winner(&self) -> Option { + fn winner(&self) -> Option> { if self.half_move_clock >= 100 { // Draw by 50 move rule. return None; @@ -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); @@ -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), } } diff --git a/games/src/chess/position.rs b/games/src/chess/position.rs index 49f8e91..c480949 100644 --- a/games/src/chess/position.rs +++ b/games/src/chess/position.rs @@ -123,7 +123,7 @@ impl PositionType for Position { false } - fn winner(&self) -> Option { + fn winner(&self) -> Option> { None } diff --git a/games/src/interface/position.rs b/games/src/interface/position.rs index 100453e..6329c70 100644 --- a/games/src/interface/position.rs +++ b/games/src/interface/position.rs @@ -63,7 +63,7 @@ where /// Returns the side which has won in the current position, if any. #[must_use] - fn winner(&self) -> Option>; + fn winner(&self) -> Option>>; /// Returns `true` if the game is over in the current position. #[must_use] fn is_game_over(&self) -> bool { diff --git a/games/src/isolation/position.rs b/games/src/isolation/position.rs index 4f40721..c3242b2 100644 --- a/games/src/isolation/position.rs +++ b/games/src/isolation/position.rs @@ -103,9 +103,9 @@ impl PositionType for Position { self.count_moves::() == 0 } - fn winner(&self) -> Option { + fn winner(&self) -> Option> { if self.is_game_over() { - Some(!self.side_to_move) + Some(Some(!self.side_to_move)) } else { None }