Current status is that the move generation for pawns is working.
Then I started with the slider pieces. I read much about it the last days and decided to try my luck with magic bitboards.
I precomputed the arrays for bishops and rooks as described here: http://chessprogramming.wikispaces.com/ ... for+Magics
Then I used a lookup as suggested here: http://chessprogramming.wikispaces.com/ ... ions-Fancy
When I finally got it working, I tested it with this position I set up for the white bishop on D4:
Code: Select all
8 r n b . k . . r
7 . p p p . p p p
6 p q . . . n . .
5 . . . . . . . .
4 . . . B . . . .
3 . . b P p P . .
2 P P P . P . P P
1 R N B Q K . N R
A B C D E F G H
rnb1k2r/1ppp1ppp/pq3n2/8/3B4/2bPpP2/PPP1P1PP/RNBQK1NR w KQkq - 0 1
Code: Select all
printBitboard(bishopAttacks(pos->allPieces(), SQ_D4));
with the result being:
Code: Select all
. . . . . . . .
x . . . . . . .
. x . . . . . .
. . x . x . . .
. . . . . . . .
. . x . x . . .
. x . . . x . .
x . . . . . x .
Code: Select all
x x x . x . . x
. x x x . x x x
x x . . . x . .
. . . . . . . .
. . . x . . . .
. . x x x x . .
x x x . x . x x
x x x x x . x x
Code: Select all
printBitboard(bishopAttacks(pos->allPieces(), SQ_D4) & ~pos->pieces(White));Code: Select all
. . . . . . . .
x . . . . . . .
. x . . . . . .
. . x . x . . .
. . . . . . . .
. . x . x . . .
. . . . . x . .
. . . . . . . .
Now I'm looking for my mistake for quite a while now, but I cannot find it.
Is there a way to test the precomputed magics? I used the function suggested in the cpw to generate them so I assume they are right, but you never know...
For referency (even if taken from the cpw) I paste my relevant code:
Code: Select all
struct SMagic {
U64 mask;
U64 magic;
int shift;
U64* ptr;
};
// these are initialized with the precomputed values
extern SMagic bishopTbl[64];
extern SMagic rookTbl[64];
inline U64 bishopAttacks(U64 occ, Square sq) {
U64* aptr = bishopTbl[sq].ptr;
occ &= bishopTbl[sq].mask;
occ *= bishopTbl[sq].magic;
occ >>= bishopTbl[sq].shift;
return aptr[occ];
}
inline U64 rookAttacks(U64 occ, Square sq) {
U64* aptr = rookTbl[sq].ptr;
occ &= rookTbl[sq].mask;
occ *= rookTbl[sq].magic;
occ >>= rookTbl[sq].shift;
return aptr[occ];
}