Please don't blame me for the algorithm, I am not its author, I have only referred to it.hgm wrote:But this is awful for left shifts. The natural carry propagation would do all that shifting and ORing in a single instruction (O-2R).
It might even be competitive to keep two copies of the board similar to rotated bitboard, but one rotated 180 degrees, so that you can do the O-2R trick in both directions. Especially if you do not store a whole board per memory cell, but just a ray. Even in 32-bit words you could store two copies of a ray of 15 squares, so it would work upto 15x15 boards. The board would be divided over many memory cells, but each move would only touch the 4 rays through the from- and the 8 rays through the to-square, so it isn't really important how many words the entire board takes.
If you want to propose an improved version of it then go ahead.
I hope you are aware of the purpose of the eastAttacksFrom() and similar functions; otherwise see below (where "X" is just a marker for visualization, not part of the bitboards; also note: LSB = A1 = lower left corner, MSB = H8 = upper right corner):
Code: Select all
bbRook:
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . 1 . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
bbEmpty:
1 1 1 1 . 1 1 .
1 1 . 1 1 1 . 1
1 1 1 1 1 1 1 1
1 1 1 X 1 1 . 1
1 1 1 . 1 1 1 1
1 1 1 1 1 1 1 1
1 1 . 1 1 1 1 1
. 1 1 1 1 1 1 1
northAttacks:
. . . 1 . . . .
. . . 1 . . . .
. . . 1 . . . .
. . . X . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
eastAttacks:
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . X 1 1 1 .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
southAttacks:
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . X . . . .
. . . 1 . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
westAttacks:
. . . . . . . .
. . . . . . . .
. . . . . . . .
1 1 1 X . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .