SebLague / Chess-Challenge

Create your own tiny chess bot!
https://www.youtube.com/watch?v=Ne40a5LkK6A
MIT License
1.78k stars 1.07k forks source link

GetPawnAttacks > Color Issue #401

Open therealsterlingberger opened 11 months ago

therealsterlingberger commented 11 months ago

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!

SebLague commented 11 months ago

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.

therealsterlingberger commented 11 months ago

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!

rowan-mcalpin commented 11 months ago

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