mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33: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:
parent
235df6a887
commit
aaad48464b
4 changed files with 52 additions and 20 deletions
|
@ -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];
|
||||||
|
|
|
@ -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];
|
||||||
|
|
|
@ -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,15 +1626,34 @@ 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();
|
||||||
clear_bit(&occ, from);
|
while (true)
|
||||||
attackers = (rook_attacks_bb(to, occ) & rooks_and_queens())
|
{
|
||||||
| (bishop_attacks_bb(to, occ) & bishops_and_queens())
|
clear_bit(&occ, from);
|
||||||
| (piece_attacks<KNIGHT>(to) & knights())
|
attackers = (rook_attacks_bb(to, occ) & rooks_and_queens())
|
||||||
| (piece_attacks<KING>(to) & kings())
|
| (bishop_attacks_bb(to, occ) & bishops_and_queens())
|
||||||
| (pawn_attacks(WHITE, to) & pawns(BLACK))
|
| (piece_attacks<KNIGHT>(to) & knights())
|
||||||
| (pawn_attacks(BLACK, to) & pawns(WHITE));
|
| (piece_attacks<KING>(to) & kings())
|
||||||
|
| (pawn_attacks(WHITE, to) & pawns(BLACK))
|
||||||
|
| (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];
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue