Add 'Color::{forward,backward}_direction'
This commit is contained in:
parent
aa3b464bb8
commit
7c8dce8f49
|
@ -1,4 +1,4 @@
|
||||||
use super::Rank;
|
use super::{Direction, Rank};
|
||||||
|
|
||||||
/// An enum representing the color of a player.
|
/// An enum representing the color of a player.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
@ -65,6 +65,21 @@ impl Color {
|
||||||
Self::Black => Rank::Second,
|
Self::Black => Rank::Second,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Which way do pawns advance for this color.
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn forward_direction(self) -> Direction {
|
||||||
|
match self {
|
||||||
|
Self::White => Direction::North,
|
||||||
|
Self::Black => Direction::South,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Which way do the opponent's pawns advance for this color.
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn backward_direction(self) -> Direction {
|
||||||
|
(!self).forward_direction()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Not for Color {
|
impl std::ops::Not for Color {
|
||||||
|
|
Loading…
Reference in a new issue