Skip to content

Commit

Permalink
Add color and piece enums
Browse files Browse the repository at this point in the history
  • Loading branch information
bsamseth committed Oct 31, 2024
1 parent d488c5b commit 6441a7f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions goldchess/src/color.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// Represents the color of a piece, or the side to move.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Color {
White,
Black,
}

impl Color {
pub const ALL: [Color; 2] = [Color::White, Color::Black];
}

impl std::ops::Not for Color {
type Output = Self;

fn not(self) -> Self {
match self {
Color::White => Color::Black,
Color::Black => Color::White,
}
}
}
21 changes: 21 additions & 0 deletions goldchess/src/piece.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// Representation of a chess piece.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Piece {
Pawn,
Knight,
Bishop,
Rook,
Queen,
King,
}

impl Piece {
pub const ALL: [Piece; 6] = [
Piece::Pawn,
Piece::Knight,
Piece::Bishop,
Piece::Rook,
Piece::Queen,
Piece::King,
];
}

0 comments on commit 6441a7f

Please sign in to comment.