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

.SquareIsAttackedByOpponent() is problematic to use #425

Open TomaszJaworski777 opened 11 months ago

TomaszJaworski777 commented 11 months ago

.SquareIsAttackedByOpponent() generates the mask of attacks everytime you call it, which is slow, which creates a problem. There should be a way to cache an attack mask and use it in the same position for performance.

I would like to have public mathod .GetAttackMask() that basically returns the mask and allows me to call BitboardHelper.SquareIsSet(moveGen.GetOpponentAttackMap(board), square);

This function already exists, but its hidden in APIMoveGen, just make it public.

SebLague commented 11 months ago

The result is cached (the init function is called, which granted it probably shouldn’t be, but it does exit immediately if the initialization step has already been done). I agree it would have been good to expose the underlying bitboard, but as of Aug 1 I’m no longer making changes to the API.