check evasions

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

tomitank
Posts: 276
Joined: Sat Mar 04, 2017 12:24 pm
Location: Hungary

check evasions

Post by tomitank »

Hi all!

Code from Stockfish:

Code: Select all

  Color us = pos.side_to_move();
  Square ksq = pos.square<KING>&#40;us&#41;;
  Bitboard sliderAttacks = 0;
  Bitboard sliders = pos.checkers&#40;) & ~pos.pieces&#40;KNIGHT, PAWN&#41;;

  // Find all the squares attacked by slider checkers. We will remove them from
  // the king evasions in order to skip known illegal moves, which avoids any
  // useless legality checks later on.
  while &#40;sliders&#41;
  &#123;
      Square checksq = pop_lsb&#40;&sliders&#41;;
      sliderAttacks |= LineBB&#91;checksq&#93;&#91;ksq&#93; ^ checksq;
  &#125;

  // Generate evasions for king, capture and non capture moves
  Bitboard b = pos.attacks_from<KING>&#40;ksq&#41; & ~pos.pieces&#40;us&#41; & ~sliderAttacks;
  while &#40;b&#41;
      *moveList++ = make_move&#40;ksq, pop_lsb&#40;&b&#41;);
Why not exclude the squares that attacked by non-sliding pieces?

Code: Select all

  Bitboard sliders = pos.checkers&#40;) & ~pos.pieces&#40;KNIGHT, PAWN&#41;;
..and all squares that attacked by enemy?
Wasted time?
Am I wrong?

-Tamas
syzygy
Posts: 5563
Joined: Tue Feb 28, 2012 11:56 pm

Re: check evasions

Post by syzygy »

The code you quote removes squares attacked by sliding checkers. If a pawn gives check, there will be no squares to remove. If a knight gives check, there is at most a single square to remove. The work involved to remove that square probably does not outweigh the gain from sometimes one legality check less. But to be sure about this, a test would be needed.

If a sliding piece gives check, there will often be two other squares around the king in the line of attack. So it probably makes a bit more sense for sliding checkers. Still, it is not obviously a win.