231 lines
4.3 KiB
Rust
231 lines
4.3 KiB
Rust
use super::{piece::PieceVariant, square::Square};
|
|
|
|
use serde::Serialize;
|
|
#[cfg(feature = "custom_pieces")]
|
|
use serde_derive::Deserialize;
|
|
|
|
pub struct Move {
|
|
from: Square,
|
|
to: Square,
|
|
promotion: Option<PieceVariant>
|
|
}
|
|
|
|
impl Move {
|
|
pub fn from(self) -> Square {
|
|
self.from
|
|
}
|
|
|
|
pub fn to(self) -> Square {
|
|
self.to
|
|
}
|
|
|
|
pub fn promotion(self) -> Option<PieceVariant> {
|
|
self.promotion
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "custom_pieces")]
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct Change {
|
|
x: i8,
|
|
y: i8
|
|
}
|
|
|
|
#[cfg(not(feature = "custom_pieces"))]
|
|
pub struct Change {
|
|
x: i8,
|
|
y: i8
|
|
}
|
|
|
|
impl Change {
|
|
pub fn new(x: i8, y: i8) -> Self {
|
|
Self { x, y }
|
|
}
|
|
}
|
|
|
|
|
|
pub enum MoveVariant {
|
|
King,
|
|
KingCastle,
|
|
Queen,
|
|
Rook,
|
|
Bishop,
|
|
Knight,
|
|
PawnWhite,
|
|
PawnWhiteDouble,
|
|
PawnWhiteEnPassent,
|
|
PawnWhiteCaptureLeft,
|
|
PawnWhiteCaptureRight,
|
|
PawnBlack,
|
|
PawnBlackDouble,
|
|
PawnBlackEnPassent,
|
|
PawnBlackCaptureLeft,
|
|
PawnBlackCaptureRight,
|
|
}
|
|
|
|
impl MoveVariant {
|
|
pub fn king() -> [Change; 8] {
|
|
[
|
|
Change { x: 0, y: 1 },
|
|
Change { x: 0, y: -1 },
|
|
Change { x: 1, y: 0 },
|
|
Change { x: 1, y: 1 },
|
|
Change { x: 1, y: -1 },
|
|
Change { x: -1, y: 0 },
|
|
Change { x: -1, y: 1 },
|
|
Change { x: -1, y: -1 },
|
|
]
|
|
}
|
|
|
|
pub fn queen() -> [Change; 8] {
|
|
[
|
|
Change { x: 0, y: 1 },
|
|
Change { x: 0, y: -1 },
|
|
Change { x: 1, y: 0 },
|
|
Change { x: 1, y: 1 },
|
|
Change { x: 1, y: -1 },
|
|
Change { x: -1, y: 0 },
|
|
Change { x: -1, y: 1 },
|
|
Change { x: -1, y: -1 },
|
|
]
|
|
}
|
|
|
|
pub fn rook() -> [Change; 4] {
|
|
[
|
|
Change { x: 0, y: -1 },
|
|
Change { x: 0, y: 1 },
|
|
Change { x: 1, y: 0 },
|
|
Change { x: -1, y: 0 }
|
|
]
|
|
}
|
|
|
|
pub fn bishop() -> [Change; 4] {
|
|
[
|
|
Change { x: -1, y: -1 },
|
|
Change { x: -1, y: 1 },
|
|
Change { x: 1, y: -1 },
|
|
Change { x: 1, y: 1 }
|
|
]
|
|
}
|
|
|
|
pub fn knight() -> [Change; 8] {
|
|
[
|
|
Change { x: 1, y: 2 },
|
|
Change { x: 2, y: 1 },
|
|
Change { x: 2, y: -1 },
|
|
Change { x: 1, y: -2 },
|
|
Change { x: -1, y: -2 },
|
|
Change { x: -2, y: -1},
|
|
Change { x: -2, y: 1},
|
|
Change { x: -1, y: 2},
|
|
]
|
|
}
|
|
|
|
pub fn pawn_white() -> [Change; 1] {
|
|
[ Change { x: 0, y: -1 } ]
|
|
}
|
|
|
|
pub fn pawn_white_double() -> [Change; 1] {
|
|
[ Change { x: 0, y: -2 } ]
|
|
}
|
|
|
|
pub fn pawn_white_en_passent() -> [Change; 2] {
|
|
[
|
|
Change { x: -1, y: -1 },
|
|
Change { x: 1, y: -1 },
|
|
]
|
|
}
|
|
|
|
pub fn pawn_white_capture_left() -> [Change; 1] {
|
|
[ Change { x: -1, y: -1 } ]
|
|
}
|
|
|
|
pub fn pawn_white_capture_right() -> [Change; 1] {
|
|
[ Change { x: 1, y: -1 } ]
|
|
}
|
|
|
|
pub fn pawn_black() -> [Change; 1] {
|
|
[ Change { x: 0, y: 1 } ]
|
|
}
|
|
|
|
pub fn pawn_black_double() -> [Change; 1] {
|
|
[ Change { x: 0, y: 2 } ]
|
|
}
|
|
|
|
pub fn pawn_black_en_passent() -> [Change; 2] {
|
|
[
|
|
Change { x: -1, y: 1 },
|
|
Change { x: 1, y: 1 },
|
|
]
|
|
}
|
|
|
|
pub fn pawn_black_capture_left() -> [Change; 1] {
|
|
[ Change { x: 1, y: 1 } ]
|
|
}
|
|
|
|
pub fn pawn_black_capture_right() -> [Change; 1] {
|
|
[ Change { x: -1, y: 1 } ]
|
|
}
|
|
|
|
|
|
pub fn number_king() -> u8 {
|
|
8
|
|
}
|
|
|
|
pub fn number_queen() -> u8 {
|
|
8
|
|
}
|
|
|
|
pub fn number_rook() -> u8 {
|
|
4
|
|
}
|
|
|
|
pub fn number_bishop() -> u8 {
|
|
4
|
|
}
|
|
|
|
pub fn number_knight() -> u8 {
|
|
8
|
|
}
|
|
|
|
pub fn number_pawn_white() -> u8 {
|
|
1
|
|
}
|
|
|
|
pub fn number_pawn_white_double() -> u8 {
|
|
1
|
|
}
|
|
|
|
pub fn number_pawn_white_en_passent() -> u8 {
|
|
2
|
|
}
|
|
|
|
pub fn number_pawn_white_capture_left() -> u8 {
|
|
1
|
|
}
|
|
|
|
pub fn number_pawn_white_capture_right() -> u8 {
|
|
1
|
|
}
|
|
|
|
pub fn number_pawn_black() -> u8 {
|
|
1
|
|
}
|
|
|
|
pub fn number_pawn_black_double() -> u8 {
|
|
1
|
|
}
|
|
|
|
pub fn number_pawn_black_en_passent() -> u8 {
|
|
2
|
|
}
|
|
|
|
pub fn number_pawn_black_capture_left() -> u8 {
|
|
1
|
|
}
|
|
|
|
pub fn number_pawn_black_capture_right() -> u8 {
|
|
1
|
|
}
|
|
}
|