[board] Remove BoardSide enum; use Castle everywhere
Move Castle to a castle module inside the move module. Implement into_index() on Castle to turn it into a usize.
This commit is contained in:
parent
21b5266789
commit
fa1c6b452e
8 changed files with 95 additions and 63 deletions
|
@ -2,12 +2,12 @@
|
|||
|
||||
use crate::{
|
||||
piece::{Piece, PlacedPiece, Shape},
|
||||
position::BoardSide,
|
||||
square::Rank,
|
||||
Square,
|
||||
};
|
||||
use std::fmt;
|
||||
|
||||
pub use castle::Castle;
|
||||
pub(crate) use move_formatter::AlgebraicMoveFormatter;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
|
@ -18,18 +18,81 @@ pub enum MakeMoveError {
|
|||
IllegalCastle,
|
||||
}
|
||||
|
||||
#[repr(u16)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum Castle {
|
||||
KingSide = 0b10,
|
||||
QueenSide = 0b11,
|
||||
}
|
||||
mod castle {
|
||||
use crate::{Color, Square};
|
||||
|
||||
impl From<BoardSide> for Castle {
|
||||
fn from(value: BoardSide) -> Self {
|
||||
match value {
|
||||
BoardSide::King => Castle::KingSide,
|
||||
BoardSide::Queen => Castle::QueenSide,
|
||||
#[repr(u16)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum Castle {
|
||||
KingSide = 0b10,
|
||||
QueenSide = 0b11,
|
||||
}
|
||||
|
||||
pub(crate) struct Squares {
|
||||
pub king: Square,
|
||||
pub rook: Square,
|
||||
}
|
||||
|
||||
impl Castle {
|
||||
const STARTING_SQUARES: [[Squares; 2]; 2] = [
|
||||
[
|
||||
Squares {
|
||||
king: Square::E1,
|
||||
rook: Square::H1,
|
||||
},
|
||||
Squares {
|
||||
king: Square::E1,
|
||||
rook: Square::A1,
|
||||
},
|
||||
],
|
||||
[
|
||||
Squares {
|
||||
king: Square::E8,
|
||||
rook: Square::H8,
|
||||
},
|
||||
Squares {
|
||||
king: Square::E8,
|
||||
rook: Square::A8,
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
const TARGET_SQUARES: [[Squares; 2]; 2] = [
|
||||
[
|
||||
Squares {
|
||||
king: Square::G1,
|
||||
rook: Square::F1,
|
||||
},
|
||||
Squares {
|
||||
king: Square::C1,
|
||||
rook: Square::D1,
|
||||
},
|
||||
],
|
||||
[
|
||||
Squares {
|
||||
king: Square::G8,
|
||||
rook: Square::F8,
|
||||
},
|
||||
Squares {
|
||||
king: Square::C8,
|
||||
rook: Square::D8,
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
pub(crate) fn starting_squares(&self, color: Color) -> &'static Squares {
|
||||
&Castle::STARTING_SQUARES[color as usize][self.into_index()]
|
||||
}
|
||||
|
||||
pub(crate) fn target_squares(&self, color: Color) -> &'static Squares {
|
||||
&Castle::TARGET_SQUARES[color as usize][self.into_index()]
|
||||
}
|
||||
|
||||
pub(crate) fn into_index(&self) -> usize {
|
||||
match self {
|
||||
Castle::KingSide => 0,
|
||||
Castle::QueenSide => 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue