Chess-Challenge icon indicating copy to clipboard operation
Chess-Challenge copied to clipboard

GetPawnAttacks > Color Issue

Open therealsterlingberger opened this issue 2 years ago • 3 comments

Hi,

I ran into an issue using BitboardHelper.GetPawnAttacks(Square square, bool IsWhite).

Shortform: The result of BitboardHelper.GetPawnAttacks(new Square("b4"), false) == 21474836480 == c5 & a5 which is wrong for a black pawn on b4 (parameter false). The result of BitboardHelper.GetPawnAttacks(new Square("b4"), true) == 327680== c3 & a3 which would be correct for a black pawn on b4 but uses the wrong parameter.

Is there something wrong with the function or do I get it wrong?

According to documentation: GetPawnAttacks(Square square, bool isWhite) > Gets a bitboard of squares that a pawn (of the given colour [in my case black]) can attack from the given square.

Thanks, hadn't had this much fun coding in quite a long time!

therealsterlingberger avatar Jul 30 '23 18:07 therealsterlingberger

Hi @therealsterlingberger, I'm happy you're enjoying the challenge! That's a bit mysterious, I tried writing the same code:

ulong blackPawnAttacks = BitboardHelper.GetPawnAttacks(new Square("b4"), false);
BitboardHelper.VisualizeBitboard(blackPawnAttacks);
Console.WriteLine(blackPawnAttacks); // 327680

and am getting the correct values. Is there any chance you've just mixed up which value you're printing out? If not, please post your full code here and let me know what version of the project you're using.

SebLague avatar Jul 30 '23 20:07 SebLague

Hey there, thanks for the quick response,

it seems the issue has resolved itself by me not being braindead for coding the entire day, seems to work fine now. I will do some more debugging and try different positions and will close the issue after that if nothing new comes up.

Sorry for the inconvenience!

therealsterlingberger avatar Jul 31 '23 09:07 therealsterlingberger

My best guess @therealsterlingberger is that you were mixing up true and false for "isWhite".

rowan-mcalpin avatar Aug 06 '23 16:08 rowan-mcalpin