diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-23 16:00:34 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-23 16:00:34 +0300 |
commit | c0d4d9b5dfa847a773945e189103e8b1482011ca (patch) | |
tree | 29a14b5edb74299c10ccefc9959b6ee99b504222 /src/square.rs | |
parent | 2238b6eecdf01cfce6dfbfc785c2a35850595f55 (diff) | |
download | chessnost-c0d4d9b5dfa847a773945e189103e8b1482011ca.tar.gz |
feat: implement castling
Diffstat (limited to 'src/square.rs')
-rw-r--r-- | src/square.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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) + } } |