Check move validity for a pinned pieces

Discussion of chess software programming and technical issues.

Moderator: Ras

mathmoi
Posts: 290
Joined: Mon Mar 13, 2006 5:23 pm
Location: Québec
Full name: Mathieu Pagé

Check move validity for a pinned pieces

Post by mathmoi »

Hi,

I'm working on my PGN parser again. To disambiguate SAN moves, I work with a Bitboard board representation.

Using XRayRookAttacks(...) and xRayBishopAttacks(...) I can identify if a piece is partially pinned. However, I'm not sure how I can generate a bitboard of the squares the partially pinned piece can move to (The squares between it's own king and the attacking piece (inlcuding it).

I would need such a bitboard to verify if the piece can move to the to square I extracted from the SAN move.

Can this be done?

Thanks
Ron Murawski
Posts: 397
Joined: Sun Oct 29, 2006 4:38 am
Location: Schenectady, NY

Re: Check move validity for a pinned pieces

Post by Ron Murawski »

mathmoi wrote:Hi,

I'm working on my PGN parser again. To disambiguate SAN moves, I work with a Bitboard board representation.

Using XRayRookAttacks(...) and xRayBishopAttacks(...) I can identify if a piece is partially pinned. However, I'm not sure how I can generate a bitboard of the squares the partially pinned piece can move to (The squares between it's own king and the attacking piece (inlcuding it).

I would need such a bitboard to verify if the piece can move to the to square I extracted from the SAN move.

Can this be done?

Thanks
Hi Mathieu,

Here's one way to handle it.

First, create a global array of bitboards
uint64 XRayMask[64][64];
initialize this array by looping through, using both of your functions XRayRookAttacks(...) and xRayBishopAttacks(...) The bitboards should not include the 'from' square, but they should include all squares in between plus the 'to' square.

let's assume you have a bitboard of all semi-legal 'to' squares for the pinned piece, called 'bb'

now do:

Code: Select all

if ( piece_is_pinned )
    bb &= XRayMask[king_sq][enemy_attacking_piece];
this will limit possible destination squares to the pin ray

Ron
User avatar
hgm
Posts: 28419
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Check move validity for a pinned pieces

Post by hgm »

If you want to limit the table size, you could also use a table based on the square difference. Like Ray[from_sqr + (from_sqr&0x70) - Ox88_king_sqr].
(Where adding the from_sqr&0x70 is needed to convert straight numbering to 0x88 square numbering.
Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Check move validity for a pinned pieces

Post by Gerd Isenberg »

CPW Square attacked by covers Legality Test.
mathmoi
Posts: 290
Joined: Mon Mar 13, 2006 5:23 pm
Location: Québec
Full name: Mathieu Pagé

Re: Check move validity for a pinned pieces

Post by mathmoi »

Thanks to both of you and to Gerd.

I though of using a in_between[64][64] array, but I hoped that I could avoid it because of it's size (32k), but the 0x88 idea will make it much smaller.

Thanks.
jdart
Posts: 4413
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Check move validity for a pinned pieces

Post by jdart »

I am lazy and in parsing PGN I just make the move and see if the king is then attacked, although I also have a function isPinned, that does what you want.

See Notation::value and Board::isPinned (https://github.com/jdart1/arasan-chess?source=cc).

--Jon
User avatar
hgm
Posts: 28419
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Check move validity for a pinned pieces

Post by hgm »

The fastest way to parse SAN is not worry about legality at all in the first attempt, and only when this leads to an ambiguity, try to figure out which one of the possible moves is legal. This is what I do in WinBoard's position search. The assumption is that the input PGN consists of legal moves. Testing the legality is pretty much a waste of time, because what can you do when the input PGN does contain an illegal move? You might skip the rest of the game, so the sought position is not matched against any positions after the illegal move. But is that really what the user would want? As it is the game would appear in the list of games that contain the sought position, and only when he tries to load it, he would run into the illegal-move complaint. This seems a better solution.

Only doing the legality test in case of ambiguous move caused an enormous speedup of the reading of big PGN files.