Compare commits
1 commit
main
...
board-is-v
Author | SHA1 | Date | |
---|---|---|---|
12cebf1f2b |
1 changed files with 39 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue