Updating pinned pieces map? When/how?

Discussion of chess software programming and technical issues.

Moderator: Ras

Chessnut1071
Posts: 313
Joined: Tue Aug 03, 2021 2:41 pm
Full name: Bill Beame

Re: Updating pinned pieces map? When/how?

Post by Chessnut1071 »

KhepriChess wrote: Tue Sep 27, 2022 1:41 am I've been messing around with creating an "IsLegal" function to test for move legality before actually making the move. I've gotten it working but I'm trying to speed it up (it's slower method I currently use). I'm having trouble with pinned pieces (again) though.

What I'm getting stuck on is how/when to update the pinned pieces map. For example, take this simple sequence:

[pgn][Variant "From Position"]
[FEN "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1"]

1. e4[/pgn]

After e2e4, I assume that I should no longer consider the black pawn pinned. My current code still considers it pinned after e2e4, so when it tests the legality of f4f3 is says that move is not legal.

I know I could easily call my method that generates the pinned pieces map after every move, but I'm not sure if that's really the correct thing to do. Though I'm not sure how else I'd do it.

My reference for this has been Stockfish. It appears to set the pinned map when the FEN is loaded. But I can't find any other calls to update those maps in the code. Surely somewhere/somehow it does.
This solves check, double check & discovered checks.
64-byte pre-computed table giving the check direction (N,E,S,W & knights] from a given square. XOR with occupancy. With each enemy capture: if the check direction lines up on the enemy king, the piece is pined, otherwise, it's a single check. If the attacked piece is friendly and it lines up on the enemy king it's discovered check. It's super fast with a precomputed check direction table.