1
0
Fork 0
This commit is contained in:
Paul-Nicolas Madelaine 2025-09-06 15:32:05 +02:00
parent 192aef1ce7
commit 808cde1c42
2 changed files with 68 additions and 67 deletions

View file

@ -1296,63 +1296,6 @@ impl Position {
}
}
struct WithPromotion<I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator> {
inner: I,
cur: std::mem::MaybeUninit<RawMove>,
role: Role,
}
impl<I> WithPromotion<I>
where
I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator,
{
#[inline]
fn new(inner: I) -> Self {
Self {
inner,
cur: std::mem::MaybeUninit::uninit(),
role: Role::King,
}
}
}
impl<I> Iterator for WithPromotion<I>
where
I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator,
{
type Item = RawMove;
#[inline]
fn next(&mut self) -> Option<RawMove> {
if self.role == Role::King {
self.cur.write(self.inner.next()?);
self.role = Role::Knight;
}
let raw = unsafe { self.cur.assume_init() };
let res = RawMove {
role: self.role,
..raw
};
self.role = unsafe { Role::transmute((self.role as u8).unchecked_add(1)) };
Some(res)
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.len();
(len, Some(len))
}
}
impl<I> FusedIterator for WithPromotion<I> where
I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator
{
}
impl<I> ExactSizeIterator for WithPromotion<I>
where
I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator,
{
#[inline]
fn len(&self) -> usize {
unsafe { self.inner.len().unchecked_mul(4) }
}
}
#[inline]
fn aux_play_normal(setup: &mut Setup, role: Role, from: Square, target: Square) {
let from = from.bitboard();
@ -1487,3 +1430,60 @@ impl Visitor for MateCollector {
self.is_mate &= iter.len() == 0;
}
}
struct WithPromotion<I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator> {
inner: I,
cur: std::mem::MaybeUninit<RawMove>,
role: Role,
}
impl<I> WithPromotion<I>
where
I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator,
{
#[inline]
fn new(inner: I) -> Self {
Self {
inner,
cur: std::mem::MaybeUninit::uninit(),
role: Role::King,
}
}
}
impl<I> Iterator for WithPromotion<I>
where
I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator,
{
type Item = RawMove;
#[inline]
fn next(&mut self) -> Option<RawMove> {
if self.role == Role::King {
self.cur.write(self.inner.next()?);
self.role = Role::Knight;
}
let raw = unsafe { self.cur.assume_init() };
let res = RawMove {
role: self.role,
..raw
};
self.role = unsafe { Role::transmute((self.role as u8).unchecked_add(1)) };
Some(res)
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.len();
(len, Some(len))
}
}
impl<I> FusedIterator for WithPromotion<I> where
I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator
{
}
impl<I> ExactSizeIterator for WithPromotion<I>
where
I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator,
{
#[inline]
fn len(&self) -> usize {
unsafe { self.inner.len().unchecked_mul(4) }
}
}