mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Rename occupied_squares() to pieces()
Also some microoptimizations, were there from ages but hidden: the renaming suddendly made them visible! This is a good example of how better naming lets you write better code. Naming is really a kind of black art! No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
55376219b7
commit
fc3ea7365a
6 changed files with 26 additions and 26 deletions
|
@ -315,7 +315,7 @@ namespace {
|
|||
uint64_t book_key(const Position& pos) {
|
||||
|
||||
uint64_t key = 0;
|
||||
Bitboard b = pos.occupied_squares();
|
||||
Bitboard b = pos.pieces();
|
||||
|
||||
while (b)
|
||||
{
|
||||
|
|
|
@ -547,9 +547,9 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
|||
if (Piece == KNIGHT || Piece == QUEEN)
|
||||
b = pos.attacks_from<Piece>(s);
|
||||
else if (Piece == BISHOP)
|
||||
b = attacks_bb<BISHOP>(s, pos.occupied_squares() & ~pos.pieces(QUEEN, Us));
|
||||
b = attacks_bb<BISHOP>(s, pos.pieces() ^ pos.pieces(QUEEN, Us));
|
||||
else if (Piece == ROOK)
|
||||
b = attacks_bb<ROOK>(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, Us));
|
||||
b = attacks_bb<ROOK>(s, pos.pieces() ^ pos.pieces(ROOK, QUEEN, Us));
|
||||
else
|
||||
assert(false);
|
||||
|
||||
|
@ -573,7 +573,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
|||
if ( (Piece == BISHOP || Piece == ROOK || Piece == QUEEN)
|
||||
&& (PseudoAttacks[Piece][pos.king_square(Them)] & s))
|
||||
{
|
||||
b = BetweenBB[s][pos.king_square(Them)] & pos.occupied_squares();
|
||||
b = BetweenBB[s][pos.king_square(Them)] & pos.pieces();
|
||||
|
||||
assert(b);
|
||||
|
||||
|
@ -977,7 +977,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
|||
// Opponent king cannot block because path is defended and position
|
||||
// is not in check. So only friendly pieces can be blockers.
|
||||
assert(!pos.in_check());
|
||||
assert((queeningPath & pos.occupied_squares()) == (queeningPath & pos.pieces(c)));
|
||||
assert((queeningPath & pos.pieces()) == (queeningPath & pos.pieces(c)));
|
||||
|
||||
// Add moves needed to free the path from friendly pieces and retest condition
|
||||
movesToGo += popcount<Max15>(queeningPath & pos.pieces(c));
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace {
|
|||
// when moving the castling rook we do not discover some hidden checker.
|
||||
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
|
||||
if ( pos.is_chess960()
|
||||
&& (pos.attackers_to(kto, pos.occupied_squares() ^ rfrom) & enemies))
|
||||
&& (pos.attackers_to(kto, pos.pieces() ^ rfrom) & enemies))
|
||||
return mlist;
|
||||
|
||||
(*mlist++).move = make_castle(kfrom, rfrom);
|
||||
|
@ -142,7 +142,7 @@ namespace {
|
|||
// Single and double pawn pushes, no promotions
|
||||
if (Type != MV_CAPTURE)
|
||||
{
|
||||
emptySquares = (Type == MV_QUIET ? target : ~pos.occupied_squares());
|
||||
emptySquares = (Type == MV_QUIET ? target : ~pos.pieces());
|
||||
|
||||
b1 = move_pawns<UP>(pawnsNotOn7) & emptySquares;
|
||||
b2 = move_pawns<UP>(b1 & TRank3BB) & emptySquares;
|
||||
|
@ -180,7 +180,7 @@ namespace {
|
|||
if (pawnsOn7 && (Type != MV_EVASION || (target & TRank8BB)))
|
||||
{
|
||||
if (Type == MV_CAPTURE)
|
||||
emptySquares = ~pos.occupied_squares();
|
||||
emptySquares = ~pos.pieces();
|
||||
|
||||
if (Type == MV_EVASION)
|
||||
emptySquares &= target;
|
||||
|
@ -233,7 +233,7 @@ namespace {
|
|||
|
||||
if (*pl != SQ_NONE)
|
||||
{
|
||||
target = ci.checkSq[Pt] & ~pos.occupied_squares(); // Non capture checks only
|
||||
target = ci.checkSq[Pt] & ~pos.pieces(); // Non capture checks only
|
||||
|
||||
do {
|
||||
from = *pl;
|
||||
|
@ -308,10 +308,10 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) {
|
|||
target = pos.pieces(~us);
|
||||
|
||||
else if (Type == MV_QUIET)
|
||||
target = ~pos.occupied_squares();
|
||||
target = ~pos.pieces();
|
||||
|
||||
else if (Type == MV_NON_EVASION)
|
||||
target = pos.pieces(~us) | ~pos.occupied_squares();
|
||||
target = ~pos.pieces(us);
|
||||
|
||||
mlist = (us == WHITE ? generate_pawn_moves<WHITE, Type>(pos, mlist, target)
|
||||
: generate_pawn_moves<BLACK, Type>(pos, mlist, target));
|
||||
|
@ -356,7 +356,7 @@ MoveStack* generate<MV_QUIET_CHECK>(const Position& pos, MoveStack* mlist) {
|
|||
if (pt == PAWN)
|
||||
continue; // Will be generated togheter with direct checks
|
||||
|
||||
Bitboard b = pos.attacks_from(Piece(pt), from) & ~pos.occupied_squares();
|
||||
Bitboard b = pos.attacks_from(Piece(pt), from) & ~pos.pieces();
|
||||
|
||||
if (pt == KING)
|
||||
b &= ~PseudoAttacks[QUEEN][ci.ksq];
|
||||
|
|
|
@ -377,7 +377,7 @@ Bitboard Position::hidden_checkers() const {
|
|||
|
||||
while (pinners)
|
||||
{
|
||||
b = squares_between(ksq, pop_1st_bit(&pinners)) & occupied_squares();
|
||||
b = squares_between(ksq, pop_1st_bit(&pinners)) & pieces();
|
||||
|
||||
if (b && single_bit(b) && (b & pieces(sideToMove)))
|
||||
result |= b;
|
||||
|
@ -437,7 +437,7 @@ bool Position::move_attacks_square(Move m, Square s) const {
|
|||
assert(!square_is_empty(from));
|
||||
|
||||
// Update occupancy as if the piece is moving
|
||||
occ = occupied_squares() ^ from ^ to;
|
||||
occ = pieces() ^ from ^ to;
|
||||
|
||||
// The piece moved in 'to' attacks the square 's' ?
|
||||
if (attacks_from(piece, to, occ) & s)
|
||||
|
@ -474,7 +474,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
|||
Square to = to_sq(m);
|
||||
Square capsq = to + pawn_push(them);
|
||||
Square ksq = king_square(us);
|
||||
Bitboard b = (occupied_squares() ^ from ^ capsq) | to;
|
||||
Bitboard b = (pieces() ^ from ^ capsq) | to;
|
||||
|
||||
assert(to == ep_square());
|
||||
assert(piece_moved(m) == make_piece(us, PAWN));
|
||||
|
@ -626,7 +626,7 @@ bool Position::is_pseudo_legal(const Move m) const {
|
|||
}
|
||||
// In case of king moves under check we have to remove king so to catch
|
||||
// as invalid moves like b1a1 when opposite queen is on c1.
|
||||
else if (attackers_to(to, occupied_squares() ^ from) & pieces(~us))
|
||||
else if (attackers_to(to, pieces() ^ from) & pieces(~us))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -668,7 +668,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
|
|||
|
||||
// Promotion with check ?
|
||||
if (is_promotion(m))
|
||||
return attacks_from(Piece(promotion_type(m)), to, occupied_squares() ^ from) & ksq;
|
||||
return attacks_from(Piece(promotion_type(m)), to, pieces() ^ from) & ksq;
|
||||
|
||||
// En passant capture with check ? We have already handled the case
|
||||
// of direct checks and ordinary discovered check, the only case we
|
||||
|
@ -677,7 +677,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
|
|||
if (is_enpassant(m))
|
||||
{
|
||||
Square capsq = make_square(file_of(to), rank_of(from));
|
||||
Bitboard b = (occupied_squares() ^ from ^ capsq) | to;
|
||||
Bitboard b = (pieces() ^ from ^ capsq) | to;
|
||||
|
||||
return (attacks_bb< ROOK>(ksq, b) & pieces( ROOK, QUEEN, us))
|
||||
| (attacks_bb<BISHOP>(ksq, b) & pieces(BISHOP, QUEEN, us));
|
||||
|
@ -690,7 +690,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
|
|||
Square rfrom = to; // 'King captures the rook' notation
|
||||
Square kto = relative_square(us, rfrom > kfrom ? SQ_G1 : SQ_C1);
|
||||
Square rto = relative_square(us, rfrom > kfrom ? SQ_F1 : SQ_D1);
|
||||
Bitboard b = (occupied_squares() ^ kfrom ^ rfrom) | rto | kto;
|
||||
Bitboard b = (pieces() ^ kfrom ^ rfrom) | rto | kto;
|
||||
|
||||
return attacks_bb<ROOK>(rto, b) & ksq;
|
||||
}
|
||||
|
@ -1235,7 +1235,7 @@ int Position::see(Move m) const {
|
|||
from = from_sq(m);
|
||||
to = to_sq(m);
|
||||
capturedType = type_of(piece_on(to));
|
||||
occ = occupied_squares();
|
||||
occ = pieces();
|
||||
|
||||
// Handle en passant moves
|
||||
if (is_enpassant(m))
|
||||
|
@ -1667,7 +1667,7 @@ bool Position::pos_is_ok(int* failedStep) const {
|
|||
|
||||
// The union of the white and black pieces must be equal to all
|
||||
// occupied squares
|
||||
if ((pieces(WHITE) | pieces(BLACK)) != occupied_squares())
|
||||
if ((pieces(WHITE) | pieces(BLACK)) != pieces())
|
||||
return false;
|
||||
|
||||
// Separate piece type bitboards must have empty intersections
|
||||
|
|
|
@ -108,7 +108,7 @@ public:
|
|||
Color side_to_move() const;
|
||||
|
||||
// Bitboard representation of the position
|
||||
Bitboard occupied_squares() const;
|
||||
Bitboard pieces() const;
|
||||
Bitboard pieces(Color c) const;
|
||||
Bitboard pieces(PieceType pt) const;
|
||||
Bitboard pieces(PieceType pt, Color c) const;
|
||||
|
@ -285,7 +285,7 @@ inline Color Position::side_to_move() const {
|
|||
return sideToMove;
|
||||
}
|
||||
|
||||
inline Bitboard Position::occupied_squares() const {
|
||||
inline Bitboard Position::pieces() const {
|
||||
return occupied;
|
||||
}
|
||||
|
||||
|
@ -343,7 +343,7 @@ inline Square Position::castle_rook_square(CastleRight f) const {
|
|||
|
||||
template<PieceType Pt>
|
||||
inline Bitboard Position::attacks_from(Square s) const {
|
||||
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, occupied_squares())
|
||||
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, pieces())
|
||||
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
||||
: StepAttacksBB[Pt][s];
|
||||
}
|
||||
|
|
|
@ -1335,7 +1335,7 @@ split_point_start: // At split points actual search starts from here
|
|||
kingAtt = pos.attacks_from<KING>(ksq);
|
||||
pc = pos.piece_moved(move);
|
||||
|
||||
occ = pos.occupied_squares() & ~(1ULL << from) & ~(1ULL << ksq);
|
||||
occ = pos.pieces() ^ from ^ ksq;
|
||||
oldAtt = pos.attacks_from(pc, from, occ);
|
||||
newAtt = pos.attacks_from(pc, to, occ);
|
||||
|
||||
|
@ -1403,7 +1403,7 @@ split_point_start: // At split points actual search starts from here
|
|||
ksq = pos.king_square(pos.side_to_move());
|
||||
if ( piece_is_slider(p1)
|
||||
&& (squares_between(t1, ksq) & f2)
|
||||
&& (pos.attacks_from(p1, t1, pos.occupied_squares() ^ f2) & ksq))
|
||||
&& (pos.attacks_from(p1, t1, pos.pieces() ^ f2) & ksq))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
Loading…
Add table
Reference in a new issue