Then you're back to square one (or, a1
Mailbox move gives check routine
Moderator: Ras
-
Ras
- Posts: 2703
- Joined: Tue Aug 30, 2016 8:19 pm
- Full name: Rasmus Althoff
Re: Mailbox move gives check routine
Rasmus Althoff
https://www.ct800.net
https://www.ct800.net
-
hgm
- Posts: 28396
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Mailbox move gives check routine
No again. You only have to do it for the from- and to-square. Other pieces cannot be checking, because they would then already have been checking before the move. And then you would never have tried this move, but captured the king for a beta cutoff. So you test the to-square for alignment of the mover, and the from-square for alignment of a queen.
Point is that 90% of the tests will turn out negative, and no, then you don't have to worry about blocked sliders, because there is nothing to block. Of the other 10% part will be leapers or contact alignment by sliders; no blocking possible there either. So the code to test for blocking is executed so rarely that it doesn't significantly contribute to the execution time.
And when you do have a distant slider alignment, and do the ray scan starting at the king, you would bump into the pawn shield on the very first square, in a typical midle-game position. So the ray scan will be fast as well, in the rare case that it has to be done.
Point is that 90% of the tests will turn out negative, and no, then you don't have to worry about blocked sliders, because there is nothing to block. Of the other 10% part will be leapers or contact alignment by sliders; no blocking possible there either. So the code to test for blocking is executed so rarely that it doesn't significantly contribute to the execution time.
And when you do have a distant slider alignment, and do the ray scan starting at the king, you would bump into the pawn shield on the very first square, in a typical midle-game position. So the ray scan will be fast as well, in the rare case that it has to be done.
-
Sven
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Mailbox move gives check routine
[d]8/4b3/8/3k4/2p5/4Pp2/1K1P1P2/R7 b - - 0 1
So you think of temporarily "patching" the board to analyze whether the ep capture delivers a discovered check, like in the example above (Bf6+ d4 cxd3+)? I can only imagine that you want to do that patch by removing the Pc4 and putting it to d4 so that d4-d3 would be a discovered check ... But that would restrict application of this code to giving diagonal or horizontal check while it would actually hurt when testing for a vertical discovered check.
If you really think that this patching simplifies the code (which I doubt since ep capture is a very rare case and doing straightforward things should be simple enough to address it correctly) then you could always use const_cast<> in C++, e.g.:
Code: Select all
bool Board::ep_capture_gives_discovered_check(Move const & m) const
{
#ifdef _DEBUG
Board boardCopy = *this;
#endif
const_cast<Board *>(this)->patch_forward_to_check_ep_capture(m);
bool result = ...;
const_cast<Board +>(this)->patch_backward_to_check_ep_capture(m);
#ifdef _DEBUG
ASSERT(*this == boardCopy);
#endif
return result;
}
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
-
dangi12012
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Mailbox move gives check routine
Now i am really confused SVEN?
Code: Select all
const_cast<Board +>(this)Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
R. Tomasi
- Posts: 307
- Joined: Wed Sep 01, 2021 4:08 pm
- Location: Germany
- Full name: Roland Tomasi
Re: Mailbox move gives check routine
Well, actually there are quite some situations where you would need to cast a this-pointer (think about CRTP or Barton-Nackman). In the code snippet here, it seems to be totally off, I agree. From the looks of it I would guess that the "patch_..." methods maybe aren't const such that the compiler would complain. The cast would fix the compiler-error, but may be quite dangerous, because the problem the compiler was complaining about hasn't gone away. The compiler was just told to shut up about it...
-
R. Tomasi
- Posts: 307
- Joined: Wed Sep 01, 2021 4:08 pm
- Location: Germany
- Full name: Roland Tomasi
Re: Mailbox move gives check routine
Don't use const_cast for that kind of scenario. If from the outside perspective the instance remains constant, then you should investigate using mutable members instead.
-
Ras
- Posts: 2703
- Joined: Tue Aug 30, 2016 8:19 pm
- Full name: Rasmus Althoff
Re: Mailbox move gives check routine
What about discovered checks by pieces unrelated to the move?
At that point, we are back to square one anyway, and have a lot of complicated code for corner cases like discovered check through en passant where the discovering piece is not even the moving piece, but the captured pawn.And when you do have a distant slider alignment, and do the ray scan starting at the king
However, I have another idea for a pretty simple speed-up of discovering checks in mailbox. In the middlegame, the kings are usually on the 1st resp. 8th rank so that there cannot be checks from behind. Arranging the check verification so that the "from behind" checks come last allows an early return in that case.
Rasmus Althoff
https://www.ct800.net
https://www.ct800.net
-
dangi12012
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Mailbox move gives check routine
I want to say that with bitboards you get a lot of this stuff for free (Literally a single and instruction). Including resolving all PINS. That is totally impossible with mailslots....Ras wrote: ↑Wed Nov 24, 2021 12:21 pmWhat about discovered checks by pieces unrelated to the move?
At that point, we are back to square one anyway, and have a lot of complicated code for corner cases like discovered check through en passant where the discovering piece is not even the moving piece, but the captured pawn.And when you do have a distant slider alignment, and do the ray scan starting at the king
However, I have another idea for a pretty simple speed-up of discovering checks in mailbox. In the middlegame, the kings are usually on the 1st resp. 8th rank so that there cannot be checks from behind. Arranging the check verification so that the "from behind" checks come last allows an early return in that case.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
hgm
- Posts: 28396
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Mailbox move gives check routine
This must move over the from-square, and can thus only check when the from-square has queen-alignment with the king. This is why you have to test to-square and from-square. In the presence of hoppers (e.g. Xiangqi Cannon) you also have to test the to-square for hopper-alignment (in addition to alignment of the piece that would land there), as the moved piece could have activated the hopper.
Sure, but the point is that you almost never reach that point.At that point, we are back to square one anyway, ...
Well, this cannot be helped. E.p. capture is an intrinsically more complex move, as it modifies 3 squares instead of 2. Each modified square could in principle cause a check. Evacuated squares can cause discovered checks, occupied squares can either have the occupant check directly or activate a hopper. And squares that change occupant can have an effect, such as a Cannon that gets captured in Janggi, the capturer now acting as mount for another cannon (as Cannons are not allowed to jump over each other there)...., and have a lot of complicated code for corner cases like discovered check through en passant where the discovering piece is not even the moving piece, but the captured pawn.
Remember that the requested task was to determine whether a move delivers check before that move is made. So however you are going to do that, you would always have to supply code that can handle the case where both evacuated squares are still in the check path.
It still seems you imagine a method of check verification where you scan away from the king in all possible directions. For delivering checks, or testing whether you expose your own king when not in check, this is not very competitive. There are at least 3 directions, and usually 5 or 8. (And then I even ignore knight checks!) So it is better to just test the few directions that lead to modified squares. Only when you start from a position where you already are in check you should account for the possibility that the pieces that were checking are still checking, when testing for legality. (And of course when the moving piece is a king, all these short-cuts are from the table.)However, I have another idea for a pretty simple speed-up of discovering checks in mailbox. In the middlegame, the kings are usually on the 1st resp. 8th rank so that there cannot be checks from behind. Arranging the check verification so that the "from behind" checks come last allows an early return in that case.
-
hgm
- Posts: 28396
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Mailbox move gives check routine
That does sound a bit optimistic. What would you want to AND to determine wheter a move given as (fromSqr, toSqr) delivers a check?dangi12012 wrote: ↑Wed Nov 24, 2021 1:04 pmI want to say that with bitboards you get a lot of this stuff for free (Literally a single and instruction). Including resolving all PINS. That is totally impossible with mailslots....