From f3a83065dab4be42a365646fb431847024db460c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 18 Jul 2022 17:27:09 +0200 Subject: [PATCH] Add 'Color::{forward,backward}_direction' --- src/board/color.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/board/color.rs b/src/board/color.rs index ada896d..92fb4b5 100644 --- a/src/board/color.rs +++ b/src/board/color.rs @@ -1,4 +1,4 @@ -use super::Rank; +use super::{Direction, Rank}; /// An enum representing the color of a player. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -69,6 +69,21 @@ impl Color { 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 {