control flow
This commit is contained in:
parent
34df546eaa
commit
89e77fb977
2 changed files with 101 additions and 124 deletions
31
src/moves.rs
31
src/moves.rs
|
|
@ -7,8 +7,9 @@ use crate::position::*;
|
|||
use crate::san::*;
|
||||
use crate::uci::*;
|
||||
|
||||
use std::iter::ExactSizeIterator;
|
||||
use std::iter::FusedIterator;
|
||||
use std::convert::Infallible;
|
||||
use std::iter::{ExactSizeIterator, FusedIterator};
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
/// A legal move.
|
||||
#[must_use]
|
||||
|
|
@ -101,7 +102,7 @@ impl<'l> Move<'l> {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl<const ROLE: u8> MoveGen for MoveGenImpl<ROLE> {
|
||||
impl<const ROLE: u8> MoveGen<Infallible> for MoveGenImpl<ROLE> {
|
||||
#[inline]
|
||||
fn roles(&self, role: Role) -> bool {
|
||||
role as u8 == ROLE
|
||||
|
|
@ -111,11 +112,7 @@ impl<'l> Move<'l> {
|
|||
self.to
|
||||
}
|
||||
#[inline]
|
||||
fn is_check(&mut self) {}
|
||||
#[inline]
|
||||
fn en_passant_is_legal(&mut self) {}
|
||||
#[inline]
|
||||
fn extend<I>(&mut self, iter: I)
|
||||
fn extend<I>(&mut self, iter: I) -> ControlFlow<Infallible>
|
||||
where
|
||||
I: Iterator<Item = RawMove> + ExactSizeIterator,
|
||||
{
|
||||
|
|
@ -124,6 +121,7 @@ impl<'l> Move<'l> {
|
|||
debug_assert!(self.to.contains(raw.to()));
|
||||
self.candidates.insert(raw.from);
|
||||
});
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
}
|
||||
San {
|
||||
|
|
@ -153,7 +151,7 @@ impl<'l> Move<'l> {
|
|||
_ => {
|
||||
fn aux<const ROLE: u8>(m: &Move) -> SanInner {
|
||||
let mut moves = MoveGenImpl::<ROLE>::new(m.to());
|
||||
m.position().generate_moves(&mut moves);
|
||||
let ControlFlow::Continue(()) = m.position().generate_moves(&mut moves);
|
||||
let candidates = moves.candidates;
|
||||
let (file, rank) = if candidates == m.from().bitboard() {
|
||||
(None, None)
|
||||
|
|
@ -186,7 +184,7 @@ impl<'l> Move<'l> {
|
|||
suffix: {
|
||||
let pos = self.make();
|
||||
let mut moves = MateMoveGenImpl::new();
|
||||
pos.generate_moves(&mut moves);
|
||||
let ControlFlow::Continue(()) = pos.generate_moves(&mut moves);
|
||||
let MateMoveGenImpl { is_check, is_mate } = moves;
|
||||
match (is_check, is_mate) {
|
||||
(false, _) => None,
|
||||
|
|
@ -210,21 +208,24 @@ pub struct Moves<'l> {
|
|||
array: ArrayVec<RawMove, MAX_LEGAL_MOVES>,
|
||||
}
|
||||
|
||||
impl<'l> MoveGen for Moves<'l> {
|
||||
impl<'l> MoveGen<Infallible> for Moves<'l> {
|
||||
#[inline]
|
||||
fn is_check(&mut self) {
|
||||
fn is_check(&mut self) -> ControlFlow<Infallible> {
|
||||
self.is_check = true;
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
#[inline]
|
||||
fn en_passant_is_legal(&mut self) {
|
||||
fn en_passant_is_legal(&mut self) -> ControlFlow<Infallible> {
|
||||
self.en_passant_is_legal = true;
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
#[inline]
|
||||
fn extend<I>(&mut self, iter: I)
|
||||
fn extend<I>(&mut self, iter: I) -> ControlFlow<Infallible>
|
||||
where
|
||||
I: Iterator<Item = RawMove> + ExactSizeIterator,
|
||||
{
|
||||
iter.for_each(|raw| unsafe { self.array.push_unchecked(raw) });
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +233,7 @@ impl<'l> Moves<'l> {
|
|||
#[inline]
|
||||
pub(crate) fn compute(position: &'l Position) -> Moves<'l> {
|
||||
fn aux(position: &Position, moves: &mut Moves) {
|
||||
position.generate_moves(moves);
|
||||
let ControlFlow::Continue(()) = position.generate_moves(moves);
|
||||
}
|
||||
let mut moves = Moves {
|
||||
position,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue