Cool Chess Engine Bit Twiddling Trick 0 ▲ Wayne Myers 1 hour ago · Life · hide · 0 comments While having a go at writing my own chess engine I came across a ridiculously beautiful bit twiddling trick… So, I’m on my second weekend of trying to write a chess engine from scratch, having been thoroughly nerd-sniped by Lichess and their generous hosting of the Chess Programming Wiki. I’ve come across the Most Ridiculously Cool bit twiddling trick that I’m fairly sure all the engines use. Certainly the Not Quite A Tutorial As Such But Very Close To It that I am working through has it (see rustic-chess.org - it’s excellent) and I bet they all do. It’s to do with the en passant rule in chess, and how you can quickly calculate the target square for that rule, given either an en passant capture or a pawn move that may allow en passant on the following move. The thing is, in chess engines, most moves involve a start square A and an end square B, so a piece starts on A and ends up at B. In en passant, however, there’s a third square involved - the square behind the pawn that moved two… No comments yet. Log in to reply on the Fediverse. Comments will appear here.