public int EvaluateSlidingPiece(Position position, int color, int pieceType, int materialValue, int mobilityMultiplier, ref Bitboard destinationBitboard) { Bitboard pieces = position.GetPieceBitboard(color, pieceType); int score = 0; while (pieces != 0) { score += materialValue; int square = pieces.BitScanForward(); Bitboards.PopLsb(ref pieces); Bitboard attacks = 0; if (pieceType == Position.ROOK || pieceType == Position.QUEEN) { attacks = Bitboards.GetRookMoveBitboard(square, position.AllPiecesBitboard); } if (pieceType == Position.BISHOP || pieceType == Position.QUEEN) { attacks |= Bitboards.GetBishopMoveBitboard(square, position.AllPiecesBitboard); } attacks &= destinationBitboard; score += Bitboards.CountBits(attacks) * mobilityMultiplier; } return(score); }
public void CalculatesCorrectly() { Bitboard occupancyBitboard = 0x2C479CB67DA469UL; int square = Position.G1; Assert.AreEqual(0x202020DUL, Bitboards.GetRookMoveBitboard(square, occupancyBitboard)); occupancyBitboard = 0xC5C100D915991UL; square = Position.B4; Assert.AreEqual(0x4040B8404000UL, Bitboards.GetRookMoveBitboard(square, occupancyBitboard)); occupancyBitboard = 0; square = Position.E8; Assert.AreEqual(0xF708080808080808UL, Bitboards.GetRookMoveBitboard(square, occupancyBitboard)); }