Make moves::castle::Parameters public
Rename this struct CastlingParameters → Parameters Implement getter methods for private properties
This commit is contained in:
parent
b3e55f6dcd
commit
b5d4069751
1 changed files with 40 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
// Eryn Wells <eryn@erynwells.me>
|
// Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
use chessfriend_bitboard::BitBoard;
|
use chessfriend_bitboard::BitBoard;
|
||||||
use chessfriend_core::Square;
|
use chessfriend_core::{Color, Square};
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
|
@ -10,7 +10,7 @@ pub enum Castle {
|
||||||
QueenSide = 1,
|
QueenSide = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct CastlingParameters {
|
pub struct Parameters {
|
||||||
/// Origin squares of the king and rook.
|
/// Origin squares of the king and rook.
|
||||||
origin_squares: Squares,
|
origin_squares: Squares,
|
||||||
|
|
||||||
|
@ -24,19 +24,45 @@ pub(crate) struct CastlingParameters {
|
||||||
check_squares: BitBoard,
|
check_squares: BitBoard,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parameters {
|
||||||
|
pub fn king_origin_square(&self) -> Square {
|
||||||
|
self.origin_squares.king
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn rook_origin_square(&self) -> Square {
|
||||||
|
self.origin_squares.rook
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn king_target_square(&self) -> Square {
|
||||||
|
self.target_squares.king
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn rook_target_square(&self) -> Square {
|
||||||
|
self.target_squares.rook
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_squares(&self) -> &BitBoard {
|
||||||
|
&self.clear_squares
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check_squares(&self) -> &BitBoard {
|
||||||
|
&self.check_squares
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct Squares {
|
struct Squares {
|
||||||
pub king: Square,
|
king: Square,
|
||||||
pub rook: Square,
|
rook: Square,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Castle {
|
impl Castle {
|
||||||
pub const ALL: [Castle; 2] = [Castle::KingSide, Castle::QueenSide];
|
pub const ALL: [Castle; 2] = [Castle::KingSide, Castle::QueenSide];
|
||||||
|
|
||||||
/// Parameters for each castling move, organized by color and board-side.
|
/// Parameters for each castling move, organized by color and board-side.
|
||||||
const PARAMETERS: [[CastlingParameters; 2]; 2] = [
|
const PARAMETERS: [[Parameters; 2]; 2] = [
|
||||||
[
|
[
|
||||||
CastlingParameters {
|
Parameters {
|
||||||
origin_squares: Squares {
|
origin_squares: Squares {
|
||||||
king: Square::E1,
|
king: Square::E1,
|
||||||
rook: Square::H1,
|
rook: Square::H1,
|
||||||
|
@ -48,7 +74,7 @@ impl Castle {
|
||||||
clear_squares: BitBoard::new(0b01100000),
|
clear_squares: BitBoard::new(0b01100000),
|
||||||
check_squares: BitBoard::new(0b01110000),
|
check_squares: BitBoard::new(0b01110000),
|
||||||
},
|
},
|
||||||
CastlingParameters {
|
Parameters {
|
||||||
origin_squares: Squares {
|
origin_squares: Squares {
|
||||||
king: Square::E1,
|
king: Square::E1,
|
||||||
rook: Square::A1,
|
rook: Square::A1,
|
||||||
|
@ -62,7 +88,7 @@ impl Castle {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
CastlingParameters {
|
Parameters {
|
||||||
origin_squares: Squares {
|
origin_squares: Squares {
|
||||||
king: Square::E8,
|
king: Square::E8,
|
||||||
rook: Square::H8,
|
rook: Square::H8,
|
||||||
|
@ -74,7 +100,7 @@ impl Castle {
|
||||||
clear_squares: BitBoard::new(0b01100000 << 8 * 7),
|
clear_squares: BitBoard::new(0b01100000 << 8 * 7),
|
||||||
check_squares: BitBoard::new(0b01110000 << 8 * 7),
|
check_squares: BitBoard::new(0b01110000 << 8 * 7),
|
||||||
},
|
},
|
||||||
CastlingParameters {
|
Parameters {
|
||||||
origin_squares: Squares {
|
origin_squares: Squares {
|
||||||
king: Square::E8,
|
king: Square::E8,
|
||||||
rook: Square::A8,
|
rook: Square::A8,
|
||||||
|
@ -88,4 +114,8 @@ impl Castle {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
pub fn parameters(&self, color: Color) -> &'static Parameters {
|
||||||
|
&Castle::PARAMETERS[color as usize][*self as usize]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue