Pradu wrote:Dann Corbit wrote:Precompute and store in a table of bitmaps.
For any slider at position p on a board, there are at most 127 possible states on any of his rays. You can simply index the 7 bit number to find out the attacks, pins, etc.
That's true but that's computing each pinned piece separately instead of computing them all in parallel.
You precompute the answers and store them. There is no computation at runtime. You can do the simple way and just store the table of precomputed bitmaps, or you can go past that and encode all of the actions for the bitmaps in separate functions.
In addition, the maximum of 2 direct attacks/defends for opponentcolor/mycolor have only a few states as well.
Half-pins are also useful for battery calculation. You can use quarter pins if you want to get esoteric.
I don't quite understand this can you elaborate on what you mean by a "direct attack/defend for opponentcolor/mycolor". I probably should by now but embarresingly, I do not know the concept of half-pins and quarter-pins. Can you elaborate on this as well?
[diag]
1k1n3q/1n4b1/1R6/1Q6/1R6/2P5/1n6/K7 w - -
[/diag]
Some of the terms I don't really know too well, so I just make up my own.
In the above diagram, white's rook on B6 directly attacks the knight, and has a full pin on the same knight. In a similar manner, the rook on B6 also directly defends the queen. One piece removed, the rook has a shadow attack on the king and a shadow defend on the other white rook.
The white rook on B4 directly attack the black knight on B2 and direcrtly defends the white queen on B5. The white rook on B4 has a shadow defend of the white rook on B6 and a half shadow on the black knight on B7 and a quarter shadow on the black king on b8.
I calculate it like this:
All non sliders have only direct attacks (pawn, King, knight).
All other pieces attack directly the empty squares between themselves and any first piece standing on one of their rays.
So the direct attack bitmap for the rook on B4 is the squares B1, B2, B5.
The shadow attack bitmap for the rook on B4 is the squares B1 and B6.
The half-shadow attack bitmap for the rook on B4 is the square B7.
The quarter-shadow attack bitmap for the rook on B4 is B8.
For the whole board, you can mark each square as safe for a given piece type, depending on what attacks it, and if lowest attackers are equal, by the MVV/LVA against it (which can be fully precomputed and incrementally updated as each piece moves).
The bitmaps calculated do not even have to be stored. You can instead use the bits to create board increment functions that increment the attackers for the squares by piece type.
I am sure that there are many other approaches that are as good or better than this one, but it seems obvious and intuitive for me.