Move a bunch of stuff from the position::move module over to a new chessfriend_moves crate
This commit is contained in:
parent
1958c1a50e
commit
f69c7d4c96
6 changed files with 257 additions and 2 deletions
110
moves/src/castle.rs
Normal file
110
moves/src/castle.rs
Normal file
|
@ -0,0 +1,110 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use chessfriend_bitboard::BitBoard;
|
||||
use chessfriend_core::{Color, Square};
|
||||
|
||||
#[repr(u16)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum Castle {
|
||||
KingSide = 0b10,
|
||||
QueenSide = 0b11,
|
||||
}
|
||||
|
||||
pub(crate) struct CastlingParameters {
|
||||
clear_squares: BitBoard,
|
||||
check_squares: BitBoard,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Squares {
|
||||
pub king: Square,
|
||||
pub rook: Square,
|
||||
}
|
||||
|
||||
impl Castle {
|
||||
pub const ALL: [Castle; 2] = [Castle::KingSide, Castle::QueenSide];
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parameters(&self) -> CastlingParameters {
|
||||
match self {
|
||||
Castle::KingSide => CastlingParameters {
|
||||
clear_squares: BitBoard::new(0b01100000),
|
||||
check_squares: BitBoard::new(0b01110000),
|
||||
},
|
||||
Castle::QueenSide => CastlingParameters {
|
||||
clear_squares: BitBoard::new(0b00001110),
|
||||
check_squares: BitBoard::new(0b00011100),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CastlingParameters {
|
||||
pub fn clear_squares(&self) -> &BitBoard {
|
||||
&self.clear_squares
|
||||
}
|
||||
|
||||
pub fn check_squares(&self) -> &BitBoard {
|
||||
&self.check_squares
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue