From c0d4d9b5dfa847a773945e189103e8b1482011ca Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 23 Jan 2023 16:00:34 +0300 Subject: feat: implement castling --- src/square.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/square.rs') diff --git a/src/square.rs b/src/square.rs index 1adca83..efa682c 100644 --- a/src/square.rs +++ b/src/square.rs @@ -16,6 +16,10 @@ pub enum Square { A8, B8, C8, D8, E8, F8, G8, H8, } impl Square { + pub fn from_coords(rank: u8, file: u8) -> Self { + Self::from(rank * 8 + file) + } + pub fn to_bitboard(&self) -> Bitboard { 1u64 << *self as u8 } @@ -35,6 +39,16 @@ impl Square { pub fn sout_one(&self) -> Self { Self::from(*self as u8 - 8) } + + /// Warning: this wraps which is not what you might expect! + pub fn west_one(&self) -> Self { + Self::from(*self as u8 - 1) + } + + /// Warning: this wraps which is not what you might expect! + pub fn east_one(&self) -> Self { + Self::from(*self as u8 + 1) + } } -- cgit v1.2.3