Add 'Square::index'
This commit is contained in:
parent
61e7a4e8d1
commit
17b8ee5eb3
|
@ -60,6 +60,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 {
|
||||
|
@ -188,6 +194,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);
|
||||
|
|
Loading…
Reference in a new issue