misc
This commit is contained in:
parent
faccfbc1c5
commit
ad3c6d0cfa
3 changed files with 75 additions and 74 deletions
21
src/board.rs
21
src/board.rs
|
@ -263,7 +263,7 @@ impl Square {
|
|||
|
||||
#[inline]
|
||||
pub fn new(file: File, rank: Rank) -> Self {
|
||||
unsafe { Self::transmute(((rank as u8) << 3) + file as u8) }
|
||||
unsafe { Self::transmute(((rank as u8) << 3) | file as u8) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -389,18 +389,19 @@ impl std::str::FromStr for Square {
|
|||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[allow(unused)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[repr(u8)]
|
||||
#[rustfmt::skip]
|
||||
pub(crate) enum OptionSquare {
|
||||
_A1, _B1, _C1, _D1, _E1, _F1, _G1, _H1,
|
||||
_A2, _B2, _C2, _D2, _E2, _F2, _G2, _H2,
|
||||
_A3, _B3, _C3, _D3, _E3, _F3, _G3, _H3,
|
||||
_A4, _B4, _C4, _D4, _E4, _F4, _G4, _H4,
|
||||
_A5, _B5, _C5, _D5, _E5, _F5, _G5, _H5,
|
||||
_A6, _B6, _C6, _D6, _E6, _F6, _G6, _H6,
|
||||
_A7, _B7, _C7, _D7, _E7, _F7, _G7, _H7,
|
||||
_A8, _B8, _C8, _D8, _E8, _F8, _G8, _H8,
|
||||
A1, B1, C1, D1, E1, F1, G1, H1,
|
||||
A2, B2, C2, D2, E2, F2, G2, H2,
|
||||
A3, B3, C3, D3, E3, F3, G3, H3,
|
||||
A4, B4, C4, D4, E4, F4, G4, H4,
|
||||
A5, B5, C5, D5, E5, F5, G5, H5,
|
||||
A6, B6, C6, D6, E6, F6, G6, H6,
|
||||
A7, B7, C7, D7, E7, F7, G7, H7,
|
||||
A8, B8, C8, D8, E8, F8, G8, H8,
|
||||
None,
|
||||
}
|
||||
|
||||
|
|
114
src/position.rs
114
src/position.rs
|
@ -1295,63 +1295,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();
|
||||
|
@ -1486,3 +1429,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) }
|
||||
}
|
||||
}
|
||||
|
|
14
src/setup.rs
14
src/setup.rs
|
@ -403,14 +403,14 @@ impl Setup {
|
|||
Color::White => w,
|
||||
Color::Black => !w,
|
||||
};
|
||||
ByRole::new(|kind| {
|
||||
mask & match kind {
|
||||
Role::King => k,
|
||||
Role::Queen => q,
|
||||
Role::Bishop => b,
|
||||
Role::Knight => n,
|
||||
Role::Rook => r,
|
||||
ByRole::new(|role| {
|
||||
mask & match role {
|
||||
Role::Pawn => p,
|
||||
Role::Knight => n,
|
||||
Role::Bishop => b,
|
||||
Role::Rook => r,
|
||||
Role::Queen => q,
|
||||
Role::King => k,
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue