Problem with bitboard knight attack generator

Discussion of chess software programming and technical issues.

Moderator: Ras

Dave_N
Posts: 153
Joined: Fri Sep 30, 2011 7:48 am

Re: Problem with bitboard knight attack generator

Post by Dave_N »

ok, I have been counting moves, thanks :)
Dave_N
Posts: 153
Joined: Fri Sep 30, 2011 7:48 am

Re: Problem with bitboard knight attack generator

Post by Dave_N »

I think the default move number can be approximated from the material score, or simply set to 1. Perhaps this should be an option.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Problem with bitboard knight attack generator

Post by mcostalba »

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.
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
Posts: 153
Joined: Fri Sep 30, 2011 7:48 am

Re: Problem with bitboard knight attack generator

Post by Dave_N »

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.
Sven
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

Post by Sven »

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);
	}
}
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.

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));
}
the code loses a tiny bit of its former elegance. But anyway, it is initialization code, and the first rule to follow is correctness.

Sven