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:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user