From 2375f28ee390fb2a3a9b3543dc885d125347c656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Varga=20D=C3=A1vid=20Lajos?= Date: Thu, 27 Nov 2025 23:05:01 +0200 Subject: [PATCH] added getter method bitboard::board::fen --- engine/src/bitboard/board.rs | 29 +++++++++++++++++++++++++++++ server/Cargo.lock | 1 - 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/engine/src/bitboard/board.rs b/engine/src/bitboard/board.rs index 78c96e2..75ac76b 100644 --- a/engine/src/bitboard/board.rs +++ b/engine/src/bitboard/board.rs @@ -1,3 +1,5 @@ +use crate::bitboard::utils::notation_from_square_number; + use super::utils::try_get_square_number_from_notation; pub struct Board { @@ -169,6 +171,7 @@ impl Board { if let Some(piece) = self.get_piece_character(sq) { if empty > 0 { fen.push_str(&empty.to_string()); + empty = 0; } fen.push(piece); } 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; } diff --git a/server/Cargo.lock b/server/Cargo.lock index 027f4a3..1037c3d 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -768,7 +768,6 @@ dependencies = [ "env_logger", "futures-util", "log", - "futures-util", "rand 0.9.2", "serde", "serde_json",