diff options
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) + } } |