From a3bef6f93a960ad51d7601ed8e53c6a83a532f71 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 22 Aug 2023 02:59:20 +0300 Subject: feat: improve UCI position fen moves case --- src/board/io.rs | 18 +++++++++++++----- src/board/move_generation.rs | 2 -- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'src/board') diff --git a/src/board/io.rs b/src/board/io.rs index 15d7744..78651d5 100644 --- a/src/board/io.rs +++ b/src/board/io.rs @@ -49,7 +49,9 @@ impl IO for Board { let mut rank = 7; let mut file = 0i32; - for character in fen.chars() { + let mut chars = fen.chars(); + + for character in chars.by_ref() { let index = rank * 8 + file; let position = 1 << index.clamp(0, 63); @@ -79,20 +81,26 @@ impl IO for Board { rank -= 1; file = -1; // So it becomes 0 }, - ' ' => { break }, // TODO: break for now, parse everything else later - '-' => {}, // TODO - 'w' => {}, // TODO + ' ' => { break }, _ => todo!("Unexpected character!"), } file += 1; } } + let ply = match chars.next() { + Some(char) => match char { + 'w' => 0, + 'b' => 1, + _ => panic!("Expected side to move"), + } + None => panic!("Expected side to move"), + }; let mut board = Self { piece_sets, occupancy: 0, - ply: 0, + ply, attacks: Attacks::new(), castling_rights: [[true; 2]; 2], // TODO: actualy parse from FEN ep_target: None, // TODO: parse from FEN diff --git a/src/board/move_generation.rs b/src/board/move_generation.rs index 77714c8..98df056 100644 --- a/src/board/move_generation.rs +++ b/src/board/move_generation.rs @@ -165,7 +165,6 @@ mod tests { fn generate_pseudolegal_moves_starting_position() { let mut board = Board::new(); let moves = board.generate_pseudolegal_moves(); - board.ply += 1; let black_moves = board.generate_pseudolegal_moves(); assert_eq!(moves.len(), 20); @@ -181,7 +180,6 @@ mod tests { fn moved_king_castle() { let fen = String::from("4k2r/ppp1n3/8/4R1Pp/5P2/q1P5/P1P1BP2/1K1R4 b - - 2 22"); let mut board = Board::from_FEN(fen); - board.ply += 1; // Shuffle kings around, returning to the same position board.make_move(Move { source: Square::E8, target: Square::F8, kind: MoveKind::Quiet }); -- cgit v1.2.3