1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Prefer 0 to EmptyBoardBB

Easier and even faster or at least easier to optimize.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-12-03 11:56:11 +01:00
parent 5c5af4fa65
commit a44c5cf4f7
9 changed files with 41 additions and 43 deletions

View file

@ -151,7 +151,7 @@ namespace {
//
// Case 1: Stalemate
if ( sideToMove == BLACK
&& (bk_attacks() & ~(wk_attacks() | pawn_attacks())) == EmptyBoardBB)
&& !(bk_attacks() & ~(wk_attacks() | pawn_attacks())))
return RESULT_DRAW;
// Case 2: King can capture pawn

View file

@ -166,7 +166,7 @@ void bitboards_init() {
ClearMaskBB[s] = ~SetMaskBB[s];
}
ClearMaskBB[SQ_NONE] = ~EmptyBoardBB;
ClearMaskBB[SQ_NONE] = ~0ULL;
FileBB[FILE_A] = FileABB;
RankBB[RANK_1] = Rank1BB;
@ -231,9 +231,9 @@ void bitboards_init() {
for (Square s = SQ_A1; s <= SQ_H8; s++)
{
BishopPseudoAttacks[s] = bishop_attacks_bb(s, EmptyBoardBB);
RookPseudoAttacks[s] = rook_attacks_bb(s, EmptyBoardBB);
QueenPseudoAttacks[s] = queen_attacks_bb(s, EmptyBoardBB);
BishopPseudoAttacks[s] = bishop_attacks_bb(s, 0);
RookPseudoAttacks[s] = rook_attacks_bb(s, 0);
QueenPseudoAttacks[s] = queen_attacks_bb(s, 0);
}
for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
@ -324,7 +324,7 @@ namespace {
// all the attacks for each possible subset of the mask and so is 2 power
// the number of 1s of the mask. Hence we deduce the size of the shift to
// apply to the 64 or 32 bits word to get the index.
masks[s] = sliding_attacks(pt, s, EmptyBoardBB) & ~edges;
masks[s] = sliding_attacks(pt, s, 0) & ~edges;
shifts[s] = (CpuIs64Bit ? 64 : 32) - count_1s<CNT32_MAX15>(masks[s]);
// Use Carry-Rippler trick to enumerate all subsets of masks[s] and

View file

@ -23,26 +23,6 @@
#include "types.h"
const Bitboard EmptyBoardBB = 0;
const Bitboard FileABB = 0x0101010101010101ULL;
const Bitboard FileBBB = FileABB << 1;
const Bitboard FileCBB = FileABB << 2;
const Bitboard FileDBB = FileABB << 3;
const Bitboard FileEBB = FileABB << 4;
const Bitboard FileFBB = FileABB << 5;
const Bitboard FileGBB = FileABB << 6;
const Bitboard FileHBB = FileABB << 7;
const Bitboard Rank1BB = 0xFF;
const Bitboard Rank2BB = Rank1BB << (8 * 1);
const Bitboard Rank3BB = Rank1BB << (8 * 2);
const Bitboard Rank4BB = Rank1BB << (8 * 3);
const Bitboard Rank5BB = Rank1BB << (8 * 4);
const Bitboard Rank6BB = Rank1BB << (8 * 5);
const Bitboard Rank7BB = Rank1BB << (8 * 6);
const Bitboard Rank8BB = Rank1BB << (8 * 7);
extern Bitboard SquaresByColorBB[2];
extern Bitboard FileBB[8];
extern Bitboard NeighboringFilesBB[8];

View file

@ -376,7 +376,7 @@ Value Endgame<KBBKN>::apply(const Position& pos) const {
assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame);
assert(pos.piece_count(weakerSide, KNIGHT) == 1);
assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
assert(pos.pieces(PAWN) == EmptyBoardBB);
assert(!pos.pieces(PAWN));
Value result = BishopValueEndgame;
Square wksq = pos.king_square(strongerSide);
@ -428,7 +428,7 @@ ScaleFactor Endgame<KBPsK>::apply(const Position& pos) const {
// All pawns are on a single rook file ?
if ( (pawnFile == FILE_A || pawnFile == FILE_H)
&& (pawns & ~file_bb(pawnFile)) == EmptyBoardBB)
&& !(pawns & ~file_bb(pawnFile)))
{
Square bishopSq = pos.piece_list(strongerSide, BISHOP)[0];
Square queeningSq = relative_square(strongerSide, make_square(pawnFile, RANK_8));
@ -443,12 +443,12 @@ ScaleFactor Endgame<KBPsK>::apply(const Position& pos) const {
Rank rank;
if (strongerSide == WHITE)
{
for (rank = RANK_7; (rank_bb(rank) & pawns) == EmptyBoardBB; rank--) {}
for (rank = RANK_7; !(rank_bb(rank) & pawns); rank--) {}
assert(rank >= RANK_2 && rank <= RANK_7);
}
else
{
for (rank = RANK_2; (rank_bb(rank) & pawns) == EmptyBoardBB; rank++) {}
for (rank = RANK_2; !(rank_bb(rank) & pawns); rank++) {}
rank = Rank(rank ^ 7); // HACK to get the relative rank
assert(rank >= RANK_2 && rank <= RANK_7);
}
@ -667,21 +667,21 @@ ScaleFactor Endgame<KPsK>::apply(const Position& pos) const {
Bitboard pawns = pos.pieces(PAWN, strongerSide);
// Are all pawns on the 'a' file?
if ((pawns & ~FileABB) == EmptyBoardBB)
if (!(pawns & ~FileABB))
{
// Does the defending king block the pawns?
if ( square_distance(ksq, relative_square(strongerSide, SQ_A8)) <= 1
|| ( file_of(ksq) == FILE_A
&& (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
&& !in_front_bb(strongerSide, ksq) & pawns))
return SCALE_FACTOR_ZERO;
}
// Are all pawns on the 'h' file?
else if ((pawns & ~FileHBB) == EmptyBoardBB)
else if (!(pawns & ~FileHBB))
{
// Does the defending king block the pawns?
if ( square_distance(ksq, relative_square(strongerSide, SQ_H8)) <= 1
|| ( file_of(ksq) == FILE_H
&& (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
&& !in_front_bb(strongerSide, ksq) & pawns))
return SCALE_FACTOR_ZERO;
}
return SCALE_FACTOR_NONE;

View file

@ -462,8 +462,8 @@ namespace {
// no minor piece which can exchange the outpost piece.
if (bonus && bit_is_set(ei.attackedBy[Us][PAWN], s))
{
if ( pos.pieces(KNIGHT, Them) == EmptyBoardBB
&& (SquaresByColorBB[color_of(s)] & pos.pieces(BISHOP, Them)) == EmptyBoardBB)
if ( !pos.pieces(KNIGHT, Them)
&& !(SquaresByColorBB[color_of(s)] & pos.pieces(BISHOP, Them)))
bonus += bonus + bonus / 2;
else
bonus += bonus / 2;
@ -488,7 +488,7 @@ namespace {
const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square* pl = pos.piece_list(Us, Piece);
ei.attackedBy[Us][Piece] = EmptyBoardBB;
ei.attackedBy[Us][Piece] = 0;
while ((s = *pl++) != SQ_NONE)
{

View file

@ -251,7 +251,7 @@ MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
Color us = pos.side_to_move();
Square ksq = pos.king_square(us);
Bitboard checkers = pos.checkers();
Bitboard sliderAttacks = EmptyBoardBB;
Bitboard sliderAttacks = 0;
assert(pos.piece_on(ksq) == make_piece(us, KING));
assert(checkers);
@ -485,7 +485,7 @@ namespace {
b1 = pawns & pos.attacks_from<PAWN>(pos.ep_square(), Them);
assert(b1 != EmptyBoardBB);
assert(b1);
while (b1)
{

View file

@ -182,7 +182,7 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
// pawn on neighboring files is higher or equal than the number of
// enemy pawns in the forward direction on the neighboring files.
candidate = !(opposed | passed | backward | isolated)
&& (b = attack_span_mask(Them, s + pawn_push(Us)) & ourPawns) != EmptyBoardBB
&& (b = attack_span_mask(Them, s + pawn_push(Us)) & ourPawns) != 0
&& count_1s<Max15>(b) >= count_1s<Max15>(attack_span_mask(Us, s) & theirPawns);
// Passed pawns will be properly scored in evaluation because we need

View file

@ -89,7 +89,7 @@ CheckInfo::CheckInfo(const Position& pos) {
checkSq[BISHOP] = pos.attacks_from<BISHOP>(ksq);
checkSq[ROOK] = pos.attacks_from<ROOK>(ksq);
checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK];
checkSq[KING] = EmptyBoardBB;
checkSq[KING] = 0;
}
@ -931,7 +931,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
st->key = key;
// Update checkers bitboard, piece must be already moved
st->checkersBB = EmptyBoardBB;
st->checkersBB = 0;
if (moveIsCheck)
{
@ -1697,7 +1697,7 @@ bool Position::pos_is_ok(int* failedStep) const {
if (debugBitboards)
{
// The intersection of the white and black pieces must be empty
if ((pieces(WHITE) & pieces(BLACK)) != EmptyBoardBB)
if (!(pieces(WHITE) & pieces(BLACK)))
return false;
// The union of the white and black pieces must be equal to all

View file

@ -158,6 +158,24 @@ typedef uint64_t Bitboard;
const int PLY_MAX = 100;
const int PLY_MAX_PLUS_2 = PLY_MAX + 2;
const Bitboard FileABB = 0x0101010101010101ULL;
const Bitboard FileBBB = FileABB << 1;
const Bitboard FileCBB = FileABB << 2;
const Bitboard FileDBB = FileABB << 3;
const Bitboard FileEBB = FileABB << 4;
const Bitboard FileFBB = FileABB << 5;
const Bitboard FileGBB = FileABB << 6;
const Bitboard FileHBB = FileABB << 7;
const Bitboard Rank1BB = 0xFF;
const Bitboard Rank2BB = Rank1BB << (8 * 1);
const Bitboard Rank3BB = Rank1BB << (8 * 2);
const Bitboard Rank4BB = Rank1BB << (8 * 3);
const Bitboard Rank5BB = Rank1BB << (8 * 4);
const Bitboard Rank6BB = Rank1BB << (8 * 5);
const Bitboard Rank7BB = Rank1BB << (8 * 6);
const Bitboard Rank8BB = Rank1BB << (8 * 7);
enum ValueType {
VALUE_TYPE_NONE = 0,
VALUE_TYPE_UPPER = 1,