I hope you feel better soon.
Using a union is ok. But be careful with different compilers and CPUs.
The byte order or inner struct/union alignment may vary. Though
normally with 64 bit and 8 bytes everything should be working as expected.
Do 64-bit compilers and C/C++ have 64-bit bitfields? Would that be ok also?
You need not answer this. It is not important now.
I just wondered if you planned to use my shifting 6-bit style for the bishops.
Rooks do need all 8 rows and 8 files. And may be your byte access is faster
than shifting.
Am I right that the required bit number per square for rooks looks like this?
- Code: Select all
12 11 11 11 11 11 11 12 4 x 12 bit = 4 x 4096 entries = 16384
11 10 10 10 10 10 10 11 24 x 11 bit = 24 x 2048 entries = 49152
11 10 10 10 10 10 10 11 36 x 10 bit = 36 x 1024 entries = 36864
11 10 10 10 10 10 10 11 total = 102400
11 10 10 10 10 10 10 11
11 10 10 10 10 10 10 11
11 10 10 10 10 10 10 11
12 11 11 11 11 11 11 12
The + and | question: Ok, it is possible to use |. I just made a table
for the bishops. But you can not use all sequences for the subtables.
You have to plan the order carefully. That takes away one possibility
of choice and freedom and complicates the initialisation of the table.
Proof: The number of entries in the table is 5248 which is 1010010000000 in binary.
You can not use the 9-bit central bishop index subtable at the end of the table,
because that would require the bits xxxx000000000 to xxxx111111111.
That is a contradiction to the last possible index which is 1010001111111. qed.
However a possible sequence for the | idea is:
- Code: Select all
0000999999999 4 times 9 bit
0001999999999
0010999999999
0011999999999
0100007777777 12 times 7 bit
01....7777777
0110117777777
0111000666666 4 times 6 bit
0111001666666
0111010666666
0111011666666
0111100055555 44 times 5 bit
01111...55555
0111111155555
1000000055555
100.....55555
1001111155555
1010000055555
101000..55555
1010001155555
Now apply the 64 squares to this sequence.
That's why I like to use + with the offset-idea in mind and any sequence is ok.
Another news is that I played with bit shifting and chasing the bits
around the board by multiplying them with magic numbers. And doing this
I found the method that Gerd Isenberg uses more or less independently
from his postings. That is, I knew there was this method but I did not
look too close and I did no reverse engineering. But at least I understand
it now. Well, most of it.
Tester needed! Volunteers step forward! Do this test:
For each of the methods
- rotated bitboards from Bob,
- magic bitboards from Gerd,
- exploding bitboards from Harald,
- hashed bitboards from Mike
implement it and measure the time for
- full attack bitboard generating,
- 8 direction attacks,
- mobility function,
- do and undo all moves
of the rooks and bishops
in all positions of a test set with openings, middle game and endgame,
and show us the results.
Harald