From 0c5d28b724756cc3a83bfe1030121ea7fd69c271 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 20 Oct 2024 15:22:57 -0400 Subject: [PATCH] refactor: have movegen traits use iterables instead of vectors --- src/movegen.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/movegen.rs b/src/movegen.rs index 02cdaa5..0e05e8e 100644 --- a/src/movegen.rs +++ b/src/movegen.rs @@ -290,8 +290,7 @@ impl FromUCIAlgebraic for Move { /// "Pseudo-legal" here means that moving into check is allowed, and capturing friendly pieces is /// allowed. These will be filtered out in the legal move generation step. pub trait PseudoMoveGen { - type MoveIterable; - fn gen_pseudo_moves(self) -> Self::MoveIterable; + fn gen_pseudo_moves(self) -> impl IntoIterator; } const DIRS_STRAIGHT: [(isize, isize); 4] = [(0, 1), (1, 0), (-1, 0), (0, -1)]; @@ -379,9 +378,7 @@ fn move_slider( } impl PseudoMoveGen for BoardState { - type MoveIterable = Vec; - - fn gen_pseudo_moves(self) -> Self::MoveIterable { + fn gen_pseudo_moves(self) -> impl IntoIterator { let mut ret = Vec::new(); let pl = self.pl(self.turn); macro_rules! squares { @@ -540,8 +537,7 @@ impl PseudoMoveGen for BoardState { /// Legal move generation. pub trait LegalMoveGen { - type MoveIterable; - fn gen_moves(self) -> Self::MoveIterable; + fn gen_moves(self) -> impl IntoIterator; } #[cfg(test)] @@ -777,7 +773,7 @@ mod tests { for (fen, expected) in test_cases { let board = BoardState::from_fen(fen).unwrap(); - let mut moves = board.gen_pseudo_moves(); + let mut moves: Vec = board.gen_pseudo_moves().into_iter().collect(); moves.sort_unstable(); let moves = moves;