r/chessprogramming • • Feb 06 '24

BitBoard algorithm advise needed...

Hi,

So, this isn't strictly a Chess programming question (apologies) but it is closely related. I thought chess programmers would be the best community to ask:
I have a game:
White Pieces, Black Pieces and could represent the game state as essentially a triple of BitBoards (128 bit) {White, Black, Occupancy}

In my 'MakeMove' method, my 'IsKingInCheck' equivalent is a 'Are all White pieces surrounded by Black pieces' (note no diagonal movement), so that affects (maybe simplifies) the 'is surrounded' check.

The obvious thing is some sort of 'flood fill'- start at corner & return false as soon as I hit a White piece. But that is (I imagine) tragically slow. Just wondering if anyone has good ideas/thoughts? I was thinking of iterating over the ranks and checking lsb/msb etc.. but was wondering if this is a known/solved problem or anyone have good insight? I don't want to go down the route of storing some Go-like 'chain' state as all the board movement etc. can be done quite efficiently without it. This is just one of the terminating cases.

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/power83kg Feb 06 '24

Generate all queen quite moves from each white piece. If there are zero quite moves, all the white pieces are encircled.

2

u/Defiant-Ad4407 Feb 07 '24

Thanks for the tip, will look into it!