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.
This commit is contained in:
2021-12-27 20:29:39 +01:00
parent 5916a054ad
commit 0e8eb7b767

View File

@@ -23,15 +23,10 @@ impl Engine {
&self, &self,
position: &board::Position, position: &board::Position,
) -> Result<impl Iterator<Item = board::Position> + '_, ()> { ) -> Result<impl Iterator<Item = board::Position> + '_, ()> {
if self.board.occupied(position) { Ok(self
Ok(self .board
.board .find_moves(position)?
.find_moves(position) .chain(self.board.find_captures(position)?))
.unwrap()
.chain(self.board.find_captures(position).unwrap()))
} else {
Err(())
}
} }
pub fn make_move( pub fn make_move(
&mut self, &mut self,