add optional 'custom_pieces' feature
This commit is contained in:
+88
-16
@@ -1,5 +1,8 @@
|
||||
use super::{piece::PieceVariant, square::Square};
|
||||
|
||||
#[cfg(feature = "custom_pieces")]
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
pub struct Move {
|
||||
from: Square,
|
||||
to: Square,
|
||||
@@ -20,28 +23,36 @@ impl Move {
|
||||
}
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
pub enum MoveVariant {
|
||||
King([Change; 8]),
|
||||
KingCastle([Change; 2]),
|
||||
Queen([Change; 8]),
|
||||
Rook([Change; 4]),
|
||||
Bishop([Change; 4]),
|
||||
Knight([Change; 8]),
|
||||
PawnWhite([Change; 1]),
|
||||
PawnWhiteDouble([Change; 1]),
|
||||
PawnWhiteEnPassent([Change; 2]),
|
||||
PawnWhiteCaptureLeft([Change; 1]),
|
||||
PawnWhiteCaptureRight([Change; 1]),
|
||||
PawnBlack([Change; 1]),
|
||||
PawnBlackDouble([Change; 1]),
|
||||
PawnBlackEnPassent([Change; 2]),
|
||||
PawnBlackCaptureLeft([Change; 1]),
|
||||
PawnBlackCaptureRight([Change; 1]),
|
||||
King,
|
||||
KingCastle,
|
||||
Queen,
|
||||
Rook,
|
||||
Bishop,
|
||||
Knight,
|
||||
PawnWhite,
|
||||
PawnWhiteDouble,
|
||||
PawnWhiteEnPassent,
|
||||
PawnWhiteCaptureLeft,
|
||||
PawnWhiteCaptureRight,
|
||||
PawnBlack,
|
||||
PawnBlackDouble,
|
||||
PawnBlackEnPassent,
|
||||
PawnBlackCaptureLeft,
|
||||
PawnBlackCaptureRight,
|
||||
}
|
||||
|
||||
impl MoveVariant {
|
||||
@@ -147,4 +158,65 @@ impl MoveVariant {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+23
-2
@@ -1,3 +1,8 @@
|
||||
use super::moves::Change;
|
||||
|
||||
#[cfg(feature = "custom_pieces")]
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
pub enum PieceVariant {
|
||||
King,
|
||||
Queen,
|
||||
@@ -8,6 +13,22 @@ pub enum PieceVariant {
|
||||
}
|
||||
|
||||
pub struct Piece {
|
||||
pub white: bool,
|
||||
pub variant: PieceVariant
|
||||
white: bool,
|
||||
variant: PieceVariant
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "custom_pieces")]
|
||||
enum Iterablity {
|
||||
Infinite(u8),
|
||||
ForcedNum(u8),
|
||||
Range([u8; 2])
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "custom_pieces")]
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct CustomPiece {
|
||||
change: Vec<Change>,
|
||||
iterable: Vec<Vec<u8>>
|
||||
}
|
||||
|
||||
+27
-2
@@ -3,8 +3,10 @@ use crate::chess::square::Square;
|
||||
use crate::chess::moves::Move;
|
||||
use crate::chess::moves::MoveVariant;
|
||||
|
||||
use super::moves::Change;
|
||||
|
||||
struct Castling {
|
||||
|
||||
pub struct Castling {
|
||||
king_side: bool,
|
||||
queen_side: bool,
|
||||
}
|
||||
@@ -62,6 +64,8 @@ impl Default for Position {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Creating Position
|
||||
impl Position {
|
||||
pub fn new() -> Self {
|
||||
Position::default()
|
||||
@@ -70,8 +74,29 @@ impl Position {
|
||||
pub fn from_fen(fen: String) -> Self {
|
||||
todo!("Implement this function")
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: Decide if Position should be mutable or not
|
||||
pub fn set_rows(mut self, rows: [[Option<Piece>; 8]; 8]) -> Self {
|
||||
self.rows = rows;
|
||||
self
|
||||
}
|
||||
pub fn set_whites_turn(mut self, whites_turn: bool) -> Self {
|
||||
self.whites_turn = whites_turn;
|
||||
self
|
||||
}
|
||||
pub fn set_castling(mut self, castling: [Castling; 2]) -> Self {
|
||||
self.castling = castling;
|
||||
self
|
||||
}
|
||||
pub fn set_en_passent(mut self, en_passent: Option<Square>) -> Self {
|
||||
self.en_pessant = en_passent;
|
||||
self
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/// Exposing position fields
|
||||
impl Position {
|
||||
pub fn rows(self) -> [[Option<Piece>; 8]; 8] {
|
||||
self.rows
|
||||
@@ -90,9 +115,9 @@ impl Position {
|
||||
}
|
||||
}
|
||||
|
||||
/// Use position
|
||||
impl Position {
|
||||
pub fn get_moves(self) -> Vec<Move> {
|
||||
let king_moves = MoveVariant::king();
|
||||
todo!("finish")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
|
||||
use chess::position::Position;
|
||||
|
||||
mod chess;
|
||||
|
||||
Reference in New Issue
Block a user