1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Add a see() function that take only destination square

In this case firstlocates the least valuable attacker, if any,
then proceed as usual.

This will be used by next patch.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2008-12-09 11:20:47 +01:00
parent 235df6a887
commit aaad48464b
4 changed files with 52 additions and 20 deletions

View file

@ -250,8 +250,8 @@ Bitboard BMask[64];
int BAttackIndex[64]; int BAttackIndex[64];
Bitboard BAttacks[0x1480]; Bitboard BAttacks[0x1480];
Bitboard SetMaskBB[64]; Bitboard SetMaskBB[65];
Bitboard ClearMaskBB[64]; Bitboard ClearMaskBB[65];
Bitboard StepAttackBB[16][64]; Bitboard StepAttackBB[16][64];
Bitboard RayBB[64][8]; Bitboard RayBB[64][8];
@ -433,6 +433,8 @@ namespace {
// be necessary to touch any of them. // be necessary to touch any of them.
void init_masks() { void init_masks() {
SetMaskBB[SQ_NONE] = 0ULL;
ClearMaskBB[SQ_NONE] = ~SetMaskBB[SQ_NONE];
for(Square s = SQ_A1; s <= SQ_H8; s++) { for(Square s = SQ_A1; s <= SQ_H8; s++) {
SetMaskBB[s] = (1ULL << s); SetMaskBB[s] = (1ULL << s);
ClearMaskBB[s] = ~SetMaskBB[s]; ClearMaskBB[s] = ~SetMaskBB[s];

View file

@ -113,8 +113,8 @@ extern const Bitboard RankBB[8];
extern const Bitboard RelativeRankBB[2][8]; extern const Bitboard RelativeRankBB[2][8];
extern const Bitboard InFrontBB[2][8]; extern const Bitboard InFrontBB[2][8];
extern Bitboard SetMaskBB[64]; extern Bitboard SetMaskBB[65];
extern Bitboard ClearMaskBB[64]; extern Bitboard ClearMaskBB[65];
extern Bitboard StepAttackBB[16][64]; extern Bitboard StepAttackBB[16][64];
extern Bitboard RayBB[64][8]; extern Bitboard RayBB[64][8];

View file

@ -1582,10 +1582,16 @@ void Position::undo_null_move(const UndoInfo &u) {
/// Position::see() is a static exchange evaluator: It tries to estimate the /// Position::see() is a static exchange evaluator: It tries to estimate the
/// material gain or loss resulting from a move. There are two versions of /// material gain or loss resulting from a move. There are three versions of
/// this function: One which takes a move as input, and one which takes a /// this function: One which takes a destination square as input, one takes a
/// 'from' and a 'to' square. The function does not yet understand promotions /// move, and one which takes a 'from' and a 'to' square. The function does
/// or en passant captures. /// not yet understand promotions or en passant captures.
int Position::see(Square to) const {
assert(square_is_ok(to));
return see(SQ_NONE, to);
}
int Position::see(Move m) const { int Position::see(Move m) const {
@ -1595,18 +1601,22 @@ int Position::see(Move m) const {
int Position::see(Square from, Square to) const { int Position::see(Square from, Square to) const {
// Approximate material values, with pawn = 1 // Material values
static const int seeValues[18] = { static const int seeValues[18] = {
0, 1, 3, 3, 5, 10, 100, 0, 0, 1, 3, 3, 5, 10, 100, 0, 0, 0 0, PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
RookValueMidgame, QueenValueMidgame, QueenValueMidgame*10, 0,
0, PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
RookValueMidgame, QueenValueMidgame, QueenValueMidgame*10, 0,
0, 0
}; };
Bitboard attackers, occ, b; Bitboard attackers, occ, b;
assert(square_is_ok(from)); assert(square_is_ok(from) || from == SQ_NONE);
assert(square_is_ok(to)); assert(square_is_ok(to));
// Initialize colors // Initialize colors
Color us = color_of_piece_on(from); Color us = (from != SQ_NONE ? color_of_piece_on(from) : opposite_color(color_of_piece_on(to)));
Color them = opposite_color(us); Color them = opposite_color(us);
// Initialize pieces // Initialize pieces
@ -1616,6 +1626,8 @@ int Position::see(Square from, Square to) const {
// Find all attackers to the destination square, with the moving piece // Find all attackers to the destination square, with the moving piece
// removed, but possibly an X-ray attacker added behind it. // removed, but possibly an X-ray attacker added behind it.
occ = occupied_squares(); occ = occupied_squares();
while (true)
{
clear_bit(&occ, from); clear_bit(&occ, from);
attackers = (rook_attacks_bb(to, occ) & rooks_and_queens()) attackers = (rook_attacks_bb(to, occ) & rooks_and_queens())
| (bishop_attacks_bb(to, occ) & bishops_and_queens()) | (bishop_attacks_bb(to, occ) & bishops_and_queens())
@ -1624,7 +1636,24 @@ int Position::see(Square from, Square to) const {
| (pawn_attacks(WHITE, to) & pawns(BLACK)) | (pawn_attacks(WHITE, to) & pawns(BLACK))
| (pawn_attacks(BLACK, to) & pawns(WHITE)); | (pawn_attacks(BLACK, to) & pawns(WHITE));
// If the opponent has no attackers, we are finished if (from != SQ_NONE)
break;
// If we don't have any attacker we are finished
if ((attackers & pieces_of_color(us)) == EmptyBoardBB)
return 0;
// Locate the least valuable attacker to the destination square
// and use it to initialize from square.
PieceType pt;
for (pt = PAWN; !(attackers & pieces_of_color_and_type(us, pt)); pt++)
assert(pt < KING);
from = first_1(attackers & pieces_of_color_and_type(us, pt));
piece = piece_on(from);
}
// If the opponent has no attackers we are finished
if ((attackers & pieces_of_color(them)) == EmptyBoardBB) if ((attackers & pieces_of_color(them)) == EmptyBoardBB)
return seeValues[capture]; return seeValues[capture];

View file

@ -253,6 +253,7 @@ public:
// Static exchange evaluation // Static exchange evaluation
int see(Square from, Square to) const; int see(Square from, Square to) const;
int see(Move m) const; int see(Move m) const;
int see(Square to) const;
// Accessing hash keys // Accessing hash keys
Key get_key() const; Key get_key() const;