diff --git a/src/board/square.rs b/src/board/square.rs index 3fb23ac..04e2300 100644 --- a/src/board/square.rs +++ b/src/board/square.rs @@ -64,6 +64,12 @@ impl Square { std::mem::transmute(index as u8) } + /// Return the index of a given [Square]. + #[inline(always)] + pub fn index(self) -> usize { + self as usize + } + /// Return the index of the rank of this square (0 -> rank 1, ..., 7 -> rank 8). #[inline(always)] pub fn rank_index(self) -> usize { @@ -194,6 +200,14 @@ mod test { assert_eq!(Square::new(File::H, Rank::Eighth), Square::H8); } + #[test] + fn index() { + assert_eq!(Square::A1.index(), 0); + assert_eq!(Square::A2.index(), 1); + assert_eq!(Square::B1.index(), 8); + assert_eq!(Square::H8.index(), 63); + } + #[test] fn file() { assert_eq!(Square::A1.file(), File::A);