From 0e8eb7b767ea1878ed88e70d0f6d9d708f7fb2c9 Mon Sep 17 00:00:00 2001 From: Pavel Lutskov Date: Mon, 27 Dec 2021 20:29:39 +0100 Subject: [PATCH] Simplify the get_legal_moves method It's cheap (and gets rid of boilerplate) to check for the field occupancy inside the get_moves and get_captures funcitons. --- rs/src/engine.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/rs/src/engine.rs b/rs/src/engine.rs index 3c0082c..f2073b0 100644 --- a/rs/src/engine.rs +++ b/rs/src/engine.rs @@ -23,15 +23,10 @@ impl Engine { &self, position: &board::Position, ) -> Result + '_, ()> { - if self.board.occupied(position) { - Ok(self - .board - .find_moves(position) - .unwrap() - .chain(self.board.find_captures(position).unwrap())) - } else { - Err(()) - } + Ok(self + .board + .find_moves(position)? + .chain(self.board.find_captures(position)?)) } pub fn make_move( &mut self,