added getter method bitboard::board::fen
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::bitboard::utils::notation_from_square_number;
|
||||||
|
|
||||||
use super::utils::try_get_square_number_from_notation;
|
use super::utils::try_get_square_number_from_notation;
|
||||||
|
|
||||||
pub struct Board {
|
pub struct Board {
|
||||||
@@ -169,6 +171,7 @@ impl Board {
|
|||||||
if let Some(piece) = self.get_piece_character(sq) {
|
if let Some(piece) = self.get_piece_character(sq) {
|
||||||
if empty > 0 {
|
if empty > 0 {
|
||||||
fen.push_str(&empty.to_string());
|
fen.push_str(&empty.to_string());
|
||||||
|
empty = 0;
|
||||||
}
|
}
|
||||||
fen.push(piece);
|
fen.push(piece);
|
||||||
} else {
|
} else {
|
||||||
@@ -178,8 +181,34 @@ impl Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if row > 0 {
|
||||||
|
fen.push('/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fen.push(' ');
|
||||||
|
if self.side_to_move() == 0 { fen.push('w'); } else { fen.push('b'); }
|
||||||
|
|
||||||
|
fen.push(' ');
|
||||||
|
if self.castling_rights() == 0 {
|
||||||
|
fen.push('-');
|
||||||
|
} else {
|
||||||
|
if self.castling_rights() & (1 << 3) != 0 { fen.push('K'); }
|
||||||
|
if self.castling_rights() & (1 << 2) != 0 { fen.push('Q'); }
|
||||||
|
if self.castling_rights() & (1 << 1) != 0 { fen.push('k'); }
|
||||||
|
if self.castling_rights() & (1 << 0) != 0 { fen.push('q'); }
|
||||||
|
}
|
||||||
|
|
||||||
|
fen.push(' ');
|
||||||
|
if self.en_passant_square() == 0 {
|
||||||
|
fen.push('-');
|
||||||
|
} else {
|
||||||
|
let sq = self.en_passant_square().trailing_zeros();
|
||||||
|
fen.push_str(¬ation_from_square_number(sq as u8));
|
||||||
|
}
|
||||||
|
|
||||||
|
fen.push_str(" 0 1");
|
||||||
|
|
||||||
return fen;
|
return fen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
server/Cargo.lock
generated
1
server/Cargo.lock
generated
@@ -768,7 +768,6 @@ dependencies = [
|
|||||||
"env_logger",
|
"env_logger",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
"futures-util",
|
|
||||||
"rand 0.9.2",
|
"rand 0.9.2",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|||||||
Reference in New Issue
Block a user