aboutsummaryrefslogtreecommitdiff
path: root/src/board/color.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-21 14:19:34 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-21 14:48:06 +0300
commit69f3c48fb99d96f3fbc4ab49f5fb6d1d8e90e270 (patch)
tree57c53013f2742c3d05762c7fdd066f66bd631e09 /src/board/color.rs
parent5e9543dcc6a012aef73d342080bfec46690b5446 (diff)
downloadchessnost-69f3c48fb99d96f3fbc4ab49f5fb6d1d8e90e270.tar.gz
refactor: split Board module into submodules
Diffstat (limited to 'src/board/color.rs')
-rw-r--r--src/board/color.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/board/color.rs b/src/board/color.rs
new file mode 100644
index 0000000..80d5b4e
--- /dev/null
+++ b/src/board/color.rs
@@ -0,0 +1,24 @@
+use super::piece::Piece;
+
+#[derive(Debug, Clone, Copy, PartialEq, num_enum::FromPrimitive)]
+#[repr(u8)]
+pub enum Color {
+ #[default]
+ White,
+ Black,
+}
+impl Color {
+ pub fn flip(&self) -> Self {
+ match self {
+ Self::White => Self::Black,
+ Self::Black => Self::White,
+ }
+ }
+ pub fn from_piece(piece: Piece) -> Self {
+ if (piece as u8) < 6 {
+ Self::White
+ } else {
+ Self::Black
+ }
+ }
+}