
Problem with bitboard knight attack generator
Moderator: Ras
-
- Posts: 153
- Joined: Fri Sep 30, 2011 7:48 am
Re: Problem with bitboard knight attack generator
ok, I have been counting moves, thanks 

-
- Posts: 153
- Joined: Fri Sep 30, 2011 7:48 am
Re: Problem with bitboard knight attack generator
I think the default move number can be approximated from the material score, or simply set to 1. Perhaps this should be an option.
-
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: Problem with bitboard knight attack generator
If I were in you I'd try to disjoint parsing by validation. In the first step I parse the fen string taking caring only of not crashing, in the second step I'd validate the resulting position.....just my 5 cents.Dave_N wrote: There is nothing pretty about my code however ... it works. The amount of rigorous checking needed isn't what I have in mind for internal board setting functions and so it is abstracted.
-
- Posts: 153
- Joined: Fri Sep 30, 2011 7:48 am
Re: Problem with bitboard knight attack generator
Well at the moment I am doing the parse stage twice on the case of user input. The first parse is to detect bad chars and count material and '/' characters, then to validate the rest of the substrings. This is useful because then I can give more information about what exactly has gone wrong. The second parse is done by the board object and reports "internal fen error" if there is a problem.
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Problem with bitboard knight attack generator
There is still a bug in that code which was partially also my own proposal, sorry for that. It does not work for black pawn attacks from a2 due to the negative shift by (i - 9) which has an undefined (and usually wrong) result.ZirconiumX wrote:I admit defeat...
Lucas was right.
Code: Select all
//... void InitPawnAttacks() { static Bitboard const a[8] = { 0x4ULL, 0x5ULL, 0x5ULL, 0x5ULL, 0x5ULL, 0x5ULL, 0x5ULL, 0x1ULL }; for (int i = a2; i <= h7; i++) { PawnAttacks[0][i] = a[File(i)] << (i + 7); PawnAttacks[1][i] = a[File(i)] << (i - 9); } }
By applying the necessary correction, like in:
Code: Select all
for (int i = a2; i <= h7; i++) {
PawnAttacks[0][i] = a[File(i)] << (i + 7);
PawnAttacks[1][i] = (i >= 9) ?
(a[File(i)] << (i - 9)) :
(a[File(i)] >> (9 - i));
}
Sven