75 lines
1.4 KiB
Rust
75 lines
1.4 KiB
Rust
// Eryn Wells <eryn@erynwells.me>
|
|
|
|
use crate::square::Square;
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
|
pub enum Color {
|
|
White = 0,
|
|
Black = 1,
|
|
}
|
|
|
|
impl Color {
|
|
pub fn iter() -> impl Iterator<Item = Color> {
|
|
[Color::White, Color::Black].into_iter()
|
|
}
|
|
|
|
pub fn other(&self) -> Color {
|
|
match self {
|
|
Color::White => Color::Black,
|
|
Color::Black => Color::White,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
|
pub enum Shape {
|
|
Pawn = 0,
|
|
Knight = 1,
|
|
Bishop = 2,
|
|
Rook = 3,
|
|
Queen = 4,
|
|
King = 5,
|
|
}
|
|
|
|
impl Shape {
|
|
pub fn iter() -> impl Iterator<Item = Shape> {
|
|
[
|
|
Shape::Pawn,
|
|
Shape::Knight,
|
|
Shape::Bishop,
|
|
Shape::Rook,
|
|
Shape::Queen,
|
|
Shape::King,
|
|
]
|
|
.into_iter()
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
pub enum PiecePlacementError {
|
|
PieceExistsOnSquare,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
|
pub struct Piece {
|
|
pub color: Color,
|
|
pub shape: Shape,
|
|
}
|
|
|
|
impl Piece {
|
|
pub fn new(color: Color, shape: Shape) -> Piece {
|
|
Piece { color, shape }
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
|
pub struct PlacedPiece {
|
|
pub piece: Piece,
|
|
pub square: Square,
|
|
}
|
|
|
|
impl PlacedPiece {
|
|
pub fn new(piece: Piece, square: Square) -> PlacedPiece {
|
|
PlacedPiece { piece, square }
|
|
}
|
|
}
|