From 8102b08cf0936bb530ad692cae631549e17d9c18 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 27 Jul 2022 23:26:39 +0200 Subject: [PATCH] Add 'CastleRights::with_{king,queen}_side' --- src/board/castle_rights.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/board/castle_rights.rs b/src/board/castle_rights.rs index d727fd8..b8d8f2b 100644 --- a/src/board/castle_rights.rs +++ b/src/board/castle_rights.rs @@ -53,6 +53,25 @@ impl CastleRights { (self.index() & 2) != 0 } + /// Add king-side castling rights. + #[inline(always)] + pub fn with_king_side(self) -> Self { + self.add(Self::KingSide) + } + + /// Add queen-side castling rights. + #[inline(always)] + pub fn with_queen_side(self) -> Self { + self.add(Self::QueenSide) + } + + /// Add some [CastleRights], and return the resulting [CastleRights]. + #[inline(always)] + pub fn add(self, to_remove: CastleRights) -> Self { + // SAFETY: we know the value is in-bounds + unsafe { Self::from_index_unchecked(self.index() | to_remove.index()) } + } + /// Remove king-side castling rights. #[inline(always)] pub fn without_king_side(self) -> Self {