add test position
This commit is contained in:
parent
ce7866df09
commit
2d4f6981ba
@ -2,6 +2,7 @@
|
|||||||
#[cfg(feature = "custom_pieces")]
|
#[cfg(feature = "custom_pieces")]
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum PieceVariant {
|
pub enum PieceVariant {
|
||||||
King,
|
King,
|
||||||
Queen,
|
Queen,
|
||||||
@ -11,11 +12,36 @@ pub enum PieceVariant {
|
|||||||
Pawn
|
Pawn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Piece {
|
pub struct Piece {
|
||||||
white: bool,
|
white: bool,
|
||||||
variant: PieceVariant
|
variant: PieceVariant
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Piece {
|
||||||
|
pub fn new(white: bool, variant: PieceVariant) -> Self {
|
||||||
|
Self { white, variant }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_fen(c: char) -> Option<Self> {
|
||||||
|
match c {
|
||||||
|
'K' => Some(Self::new(true, PieceVariant::King)),
|
||||||
|
'Q' => Some(Self::new(true, PieceVariant::Queen)),
|
||||||
|
'R' => Some(Self::new(true, PieceVariant::Rook)),
|
||||||
|
'B' => Some(Self::new(true, PieceVariant::Bishop)),
|
||||||
|
'N' => Some(Self::new(true, PieceVariant::Knight)),
|
||||||
|
'P' => Some(Self::new(true, PieceVariant::Pawn)),
|
||||||
|
'k' => Some(Self::new(false, PieceVariant::King)),
|
||||||
|
'q' => Some(Self::new(false, PieceVariant::Queen)),
|
||||||
|
'r' => Some(Self::new(false, PieceVariant::Rook)),
|
||||||
|
'b' => Some(Self::new(false, PieceVariant::Bishop)),
|
||||||
|
'n' => Some(Self::new(false, PieceVariant::Knight)),
|
||||||
|
'p' => Some(Self::new(false, PieceVariant::Pawn)),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "custom_pieces")]
|
#[cfg(feature = "custom_pieces")]
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|||||||
@ -1,13 +1,16 @@
|
|||||||
use crate::chess::piece::Piece;
|
use crate::chess::piece::Piece;
|
||||||
use crate::chess::square::Square;
|
use crate::chess::square::Square;
|
||||||
use crate::chess::moves::Move;
|
use crate::chess::moves::Move;
|
||||||
|
use log::trace;
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Castling {
|
pub struct Castling {
|
||||||
king_side: bool,
|
king_side: bool,
|
||||||
queen_side: bool,
|
queen_side: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Position {
|
pub struct Position {
|
||||||
rows: [[Option<Piece>; 8]; 8],
|
rows: [[Option<Piece>; 8]; 8],
|
||||||
whites_turn: bool,
|
whites_turn: bool,
|
||||||
@ -68,8 +71,29 @@ impl Position {
|
|||||||
Position::default()
|
Position::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_fen(_fen: String) -> Self {
|
pub fn from_fen(fen: String) -> Self {
|
||||||
todo!("Implement this function")
|
trace!("{fen}");
|
||||||
|
let mut pos = Position::default();
|
||||||
|
let mut parts = fen.split_ascii_whitespace();
|
||||||
|
|
||||||
|
trace!("{:?}", parts);
|
||||||
|
// parse board
|
||||||
|
parts.next().unwrap().split('/').enumerate().for_each(|(y, row)| {
|
||||||
|
let mut x = 0;
|
||||||
|
row.chars().for_each(|c| {
|
||||||
|
if c.is_ascii_digit() {
|
||||||
|
x += c.to_digit(10).unwrap();
|
||||||
|
} else {
|
||||||
|
pos.rows[y][x as usize] = Piece::from_fen(c);
|
||||||
|
x += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// parse active color
|
||||||
|
parts.next().unwrap();
|
||||||
|
trace!("{:?}", parts);
|
||||||
|
pos
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#[derive(Debug)]
|
||||||
pub struct Square {
|
pub struct Square {
|
||||||
x: u8,
|
x: u8,
|
||||||
y: u8,
|
y: u8,
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
)]
|
)]
|
||||||
|
|
||||||
|
|
||||||
use crate::config::get_config;
|
use crate::{chess::position::Position, config::get_config};
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
mod chess;
|
mod chess;
|
||||||
@ -16,4 +16,7 @@ mod logging;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let config = get_config().unwrap();
|
let config = get_config().unwrap();
|
||||||
trace!("{:?}", config);
|
trace!("{:?}", config);
|
||||||
|
|
||||||
|
let board = Position::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1".to_string());
|
||||||
|
trace!("{:?}", board);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user