From 2364223f45451a7798baae3ef1c68ee683323db5 Mon Sep 17 00:00:00 2001 From: Coding with Tom <146443103+hcsalmon1@users.noreply.github.com> Date: Tue, 14 Jan 2025 15:00:55 +0000 Subject: [PATCH] Update Algorithm explanation.txt --- Algorithm explanation.txt | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Algorithm explanation.txt b/Algorithm explanation.txt index c63ecfe..5588869 100644 --- a/Algorithm explanation.txt +++ b/Algorithm explanation.txt @@ -513,6 +513,65 @@ To remove the least significant bit we use this method: tempBitboard &= tempBitboard - 1; +Let's say we have the black pawns in the starting position: + + tempBitboard = 65280; + 0 0 0 0 0 0 0 0 + 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + +Inside a loop we get the square and then need to remove that. +We could do this: + + int square = BitscanForward(tempBitboard); + tempBitboard & ~SQUARE_BBS[square]; + +This can be a problem if "square" is not valid though. I do it this way: + + tempBitboard - 1: + 1 1 1 1 1 1 1 1 + 0 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + +When you minus 1 bitboard, it removes the smallest bit and sets all bits below it. +We then just AND this with the bitboard to remove the smallest bit. + + 1 1 1 1 1 1 1 1 + 0 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + & + 1 1 1 1 1 1 1 1 + 0 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + = + 0 0 0 0 0 0 0 0 + 0 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0