Pseudo legal check evasion bug

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Pseudo legal check evasion bug

Post by Henk »

I just had a bug where a pinned piece gave check. But opponent did not capture the king for it was doing check evasion.

Just overlooked that you should not do check evasion when you can capture opponents king.

That's disappointing for an extra check if king can be captured is not for free.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Pseudo legal check evasion bug

Post by Sven »

Henk wrote:I just had a bug where a pinned piece gave check. But opponent did not capture the king for it was doing check evasion.

Just overlooked that you should not do check evasion when you can capture opponents king.

That's disappointing for an extra check if king can be captured is not for free.
I would not call that an "extra check", it is part of the design of a "king-capture engine" that legality testing is done by checking whether one of the generated moves captures the king. So if you have three types of search with a corresponding move generator for each one:
- normal,
- evasion,
- qsearch,
then you always need to include generation of captures, maybe with the optimization that moves capturing the enemy king are generated first.
mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Pseudo legal check evasion bug

Post by mar »

Henk wrote:I just had a bug where a pinned piece gave check. But opponent did not capture the king for it was doing check evasion.

Just overlooked that you should not do check evasion when you can capture opponents king.

That's disappointing for an extra check if king can be captured is not for free.
You don't have to check for that, depends on how/when do you legality checking.

I do legality check before considering a move. Also my material value for king is 0 (unless I do SEE).

If you can capture opponent king then the position is illegal, so the one who moves pinned piece to give check should be forfeited by playing illegal move.

Therefore I restrict pinned pieces to move in king->piece diagonal mask.
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: Pseudo legal check evasion bug

Post by Henk »

Sven Schüle wrote:
Henk wrote:I just had a bug where a pinned piece gave check. But opponent did not capture the king for it was doing check evasion.

Just overlooked that you should not do check evasion when you can capture opponents king.

That's disappointing for an extra check if king can be captured is not for free.
I would not call that an "extra check", it is part of the design of a "king-capture engine" that legality testing is done by checking whether one of the generated moves captures the king. So if you have three types of search with a corresponding move generator for each one:
- normal,
- evasion,
- qsearch,
then you always need to include generation of captures, maybe with the optimization that moves capturing the enemy king are generated first.
O wait I should check if opponent king can be captured when computing capture moves in check evasion.
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: Pseudo legal check evasion bug

Post by Henk »

Actually it was funny for after pinned piece gives check both players only considered check evasion moves for now they were both in check.
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Pseudo legal check evasion bug

Post by hgm »

Yes, and if you do check extension, then boom... stack overflow.
mar wrote:I do legality check before considering a move. Also my material value for king is 0 (unless I do SEE).

If you can capture opponent king then the position is illegal, so the one who moves pinned piece to give check should be forfeited by playing illegal move.

Therefore I restrict pinned pieces to move in king->piece diagonal mask.
In CrazyWa I split legality checking in two. Early in MakeMove (after decoding the from- and to-square from the move representation), when in check, I test if the move could possibly solve the existing check. I.e. whether it moves the King, or if not in double check captures the checker, or if not in contact check lands on the same ray closer to King than the checker. If so, MakeMove() aborts, returning a value that will cause the move to be scored as -INF without search.

Moves that are made, if not King moves, are first tested for having been pinned, by testing the from-square for alignment with King, and a clear path. If they expose the King, Search() immediately returns with a +INF score.

In case of a King move I just run the move generator earlier than usual, to see if a a King capture is generated. If there is, Search() also immediately returns +INF.