From 12cebf1f2bc9593c6bd57eb4f1ac1d5ee6873c8a Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 17 Jun 2025 16:24:28 -0700 Subject: [PATCH] WIP --- board/src/board.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/board/src/board.rs b/board/src/board.rs index 666488e..1a9cca7 100644 --- a/board/src/board.rs +++ b/board/src/board.rs @@ -326,6 +326,45 @@ impl Board { } } +impl Board { + #[must_use] + pub fn is_valid(&self) -> bool { + true + } + + /// Determines whether `self` is a repetition of the given [`Board`] + /// according to the standard chess rules. A position is considered + /// equal or a repetition of another position if: + /// + /// 1. The placement of all pieces of all colors is the same, i.e. same + /// pieces on same squares + /// 2. Castling rights are equal + /// 3. The target position does not have an en passant capture available + /// + /// ## See Also + /// + /// * The [Chess Programming][1] wiki page on repetitions + /// + /// [1]: https://www.chessprogramming.org/Repetitions + /// + #[must_use] + pub fn is_repetition(&self, other: &Board) -> bool { + if other.en_passant_target.is_some() { + return false; + } + + if self.castling_rights != other.castling_rights { + return false; + } + + if self.pieces != other.pieces { + return false; + } + + true + } +} + impl Board { pub fn display(&self) -> DiagramFormatter<'_> { DiagramFormatter::new(self)