[board] Derive a bunch of traits for Color, Shape, Piece, and Square
This commit is contained in:
parent
1da827a3bb
commit
e0f1e1f6ff
2 changed files with 26 additions and 4 deletions
|
@ -1,12 +1,20 @@
|
||||||
// Eryn Wells <eryn@erynwells.me>
|
// Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
use crate::square::Square;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
pub enum Color {
|
pub enum Color {
|
||||||
White = 0,
|
White = 0,
|
||||||
Black = 1,
|
Black = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
impl Color {
|
||||||
|
pub fn iter() -> impl Iterator<Item = Color> {
|
||||||
|
[Color::White, Color::Black].into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
pub enum Shape {
|
pub enum Shape {
|
||||||
Pawn = 0,
|
Pawn = 0,
|
||||||
Knight = 1,
|
Knight = 1,
|
||||||
|
@ -16,12 +24,26 @@ pub enum Shape {
|
||||||
King = 5,
|
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)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum PiecePlacementError {
|
pub enum PiecePlacementError {
|
||||||
PieceExistsOnSquare,
|
PieceExistsOnSquare,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
pub struct Piece {
|
pub struct Piece {
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
pub shape: Shape,
|
pub shape: Shape,
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub struct ParseSquareError;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SquareOutOfBoundsError;
|
pub struct SquareOutOfBoundsError;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
pub struct Square {
|
pub struct Square {
|
||||||
pub rank: u8,
|
pub rank: u8,
|
||||||
pub file: u8,
|
pub file: u8,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue