Joost Buijs wrote:
Rein Halbersma wrote:
Why do you need the edge_squares masking? If you have the "ghost" squares at each edge, then the opposite_pieces & (empty_squares << current_direction) would be the cheapest way to isolate all opposite pieces with an empty piece behind them.
To be honest, I never looked at it in very great detail, I use ghost squares at 10,21,32, and 43 and I assumed that when there sits an enemy piece on the edge this test can fail that's why I mask out the edge-squares.
The funny thing is that the test fails indeed when I remove that mask and I still believe it is needed, but I will take another look at it.
My empty-square mask is the inverse of the occupied square-mask and it is possible that I should mark the ghost bits as being not empty, that will take time as well.
It is not so important anyway, with or without that edge-mask there won't be much difference in speed.
I suspect that your empty_squares contains bits on the ghost squares. What I have are two masks called "squares" and "ghosts". They satisfy the following
bitcount(squares) == 50
bitcount(ghosts) == 14
squares ^ ghosts == ~(0ULL) (all 64 bits set to 1)
squares == ~ghosts
If you have your board class with bitboards for black, white and kings, then occupied == black ^ white. However, if you now define empty_squares == ~occupied, you have introduced 14 bits on the ghosts squares for empty_squares. This means that in patterns as opponent_pieces & (empty_squares << dir) you can also find that jumps over pieces located on the board edge are possible. Hence, you need edge mask detection. Is this what is the case in your code?
To avoid this, the only time that I have an explicit use of the ghosts squares is when I compute empty_squares
empty_squares = squares ^ occupied (equivalent to ~ghosts ^ occupied)
I think that if you compute your empty_squares in the above way, then you don't need any edge_mask when computing move or jump patterns.
Yes, this is indeed what is happening. This morning I already figured it out.
It is very easy to change in my code, but I expect that it doesn't have much influence on the performance (if any).
This evening I will modify it and let you know the results.