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.
Pseudo legal check evasion bug
Moderators: hgm, Rebel, chrisw
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Pseudo legal check evasion bug
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: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.
- 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.
-
- Posts: 2559
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: Pseudo legal check evasion bug
You don't have to check for that, depends on how/when do you legality checking.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 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.
-
- Posts: 7220
- Joined: Mon May 27, 2013 10:31 am
Re: Pseudo legal check evasion bug
O wait I should check if opponent king can be captured when computing capture moves in check evasion.Sven Schüle wrote: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: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.
- 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.
-
- Posts: 7220
- Joined: Mon May 27, 2013 10:31 am
Re: Pseudo legal check evasion bug
Actually it was funny for after pinned piece gives check both players only considered check evasion moves for now they were both in check.
-
- Posts: 27811
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Pseudo legal check evasion bug
Yes, and if you do check extension, then boom... stack overflow.
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.
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.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.
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.