wip: update MoveGen
This commit is contained in:
parent
a8b7b9ca63
commit
bc0422a53e
2 changed files with 27 additions and 24 deletions
12
src/moves.rs
12
src/moves.rs
|
|
@ -223,17 +223,15 @@ pub struct Moves<'l> {
|
||||||
|
|
||||||
impl<'l> MoveGen<Infallible> for Moves<'l> {
|
impl<'l> MoveGen<Infallible> for Moves<'l> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_check(&mut self) -> ControlFlow<Infallible> {
|
fn checkers(&mut self, b: Bitboard) -> ControlFlow<Infallible> {
|
||||||
self.is_check = true;
|
self.is_check = !b.is_empty();
|
||||||
ControlFlow::Continue(())
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn en_passant_is_legal(&mut self) -> ControlFlow<Infallible> {
|
|
||||||
self.en_passant_is_legal = true;
|
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn extend(&mut self, s: MoveSet) -> ControlFlow<Infallible> {
|
fn extend(&mut self, s: MoveSet) -> ControlFlow<Infallible> {
|
||||||
|
if let MoveSet::EnPassant { .. } = s {
|
||||||
|
self.en_passant_is_legal = true;
|
||||||
|
}
|
||||||
s.for_each(|raw| unsafe { self.array.push_unchecked(raw) });
|
s.for_each(|raw| unsafe { self.array.push_unchecked(raw) });
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,8 +130,10 @@ impl Position {
|
||||||
/// Returns `true` if the king is in check.
|
/// Returns `true` if the king is in check.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_check(&self) -> bool {
|
pub fn is_check(&self) -> bool {
|
||||||
struct MoveGenImpl;
|
struct MoveGenImpl {
|
||||||
impl MoveGen<()> for MoveGenImpl {
|
checkers: Bitboard,
|
||||||
|
}
|
||||||
|
impl MoveGen<core::convert::Infallible> for MoveGenImpl {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn roles(&self, _role: Role) -> bool {
|
fn roles(&self, _role: Role) -> bool {
|
||||||
false
|
false
|
||||||
|
|
@ -145,11 +147,16 @@ impl Position {
|
||||||
Bitboard::new()
|
Bitboard::new()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_check(&mut self) -> ControlFlow<()> {
|
fn checkers(&mut self, b: Bitboard) -> ControlFlow<core::convert::Infallible> {
|
||||||
ControlFlow::Break(())
|
self.checkers = b;
|
||||||
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.generate_moves(&mut MoveGenImpl).is_break()
|
let mut acc = MoveGenImpl {
|
||||||
|
checkers: Bitboard::new(),
|
||||||
|
};
|
||||||
|
let ControlFlow::Continue(()) = self.generate_moves(&mut acc);
|
||||||
|
!acc.checkers.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if there is no legal move on the position.
|
/// Returns `true` if there is no legal move on the position.
|
||||||
|
|
@ -184,8 +191,11 @@ impl Position {
|
||||||
self.to
|
self.to
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn en_passant_is_legal(&mut self) -> ControlFlow<()> {
|
fn extend(&mut self, s: MoveSet) -> ControlFlow<()> {
|
||||||
ControlFlow::Break(())
|
match s {
|
||||||
|
MoveSet::EnPassant { .. } => ControlFlow::Break(()),
|
||||||
|
_ => ControlFlow::Continue(()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut moves = MoveGenImpl {
|
let mut moves = MoveGenImpl {
|
||||||
|
|
@ -761,11 +771,7 @@ pub(crate) trait MoveGen<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_check(&mut self) -> ControlFlow<S> {
|
fn checkers(&mut self, _b: Bitboard) -> ControlFlow<S> {
|
||||||
ControlFlow::Continue(())
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn en_passant_is_legal(&mut self) -> ControlFlow<S> {
|
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -829,6 +835,8 @@ impl Position {
|
||||||
| x & theirs.bishop()
|
| x & theirs.bishop()
|
||||||
| y & theirs.rook();
|
| y & theirs.rook();
|
||||||
|
|
||||||
|
moves.checkers(checkers)?;
|
||||||
|
|
||||||
if moves.roles(Role::King) && global_mask_from.contains(king_square) {
|
if moves.roles(Role::King) && global_mask_from.contains(king_square) {
|
||||||
let attacked = {
|
let attacked = {
|
||||||
let blockers = blockers ^ ours.king();
|
let blockers = blockers ^ ours.king();
|
||||||
|
|
@ -887,7 +895,6 @@ impl Position {
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkers.len() > 1 {
|
if checkers.len() > 1 {
|
||||||
moves.is_check()?;
|
|
||||||
return ControlFlow::Continue(());
|
return ControlFlow::Continue(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -971,7 +978,6 @@ impl Position {
|
||||||
& candidates
|
& candidates
|
||||||
& (!pinned | lookup::segment(king_square, to))
|
& (!pinned | lookup::segment(king_square, to))
|
||||||
{
|
{
|
||||||
moves.en_passant_is_legal()?;
|
|
||||||
moves.extend(MoveSet::EnPassant { from, to })?;
|
moves.extend(MoveSet::EnPassant { from, to })?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1006,7 +1012,6 @@ impl Position {
|
||||||
}
|
}
|
||||||
|
|
||||||
if checker.is_some() {
|
if checker.is_some() {
|
||||||
moves.is_check()?;
|
|
||||||
return ControlFlow::Continue(());
|
return ControlFlow::Continue(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1233,8 +1238,8 @@ impl MateMoveGenImpl {
|
||||||
}
|
}
|
||||||
impl MoveGen<Infallible> for MateMoveGenImpl {
|
impl MoveGen<Infallible> for MateMoveGenImpl {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_check(&mut self) -> ControlFlow<Infallible> {
|
fn checkers(&mut self, b: Bitboard) -> ControlFlow<Infallible> {
|
||||||
self.is_check = true;
|
self.is_check = !b.is_empty();
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue