Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backward simplication #614

Closed
wants to merge 7 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions src/pawns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ namespace {
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);

Bitboard b, neighbours, doubled, supported, phalanx;
Bitboard b, neighbours, stoppers, doubled, supported, phalanx;
Square s;
bool passed, isolated, opposed, backward, lever, connected;
bool isolated, opposed, lever, connected, backward;
Score score = SCORE_ZERO;
const Square* pl = pos.squares<PAWN>(Us);
const Bitboard* pawnAttacksBB = StepAttacksBB[make_piece(Us, PAWN)];
Expand Down Expand Up @@ -131,41 +131,33 @@ namespace {
neighbours = ourPawns & adjacent_files_bb(f);
doubled = ourPawns & forward_bb(Us, s);
opposed = theirPawns & forward_bb(Us, s);
passed = !(theirPawns & passed_pawn_mask(Us, s));
stoppers = theirPawns & passed_pawn_mask(Us, s);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be nitpicking, but while there could you pelase reindent all?

        // Flag the pawn
        neighbours = ourPawns   & adjacent_files_bb(f);
        doubled    = ourPawns   & forward_bb(Us, s);
        opposed    = heirPawns  & forward_bb(Us, s);
        stoppers   = theirPawns & passed_pawn_mask(Us, s);
        lever      = theirPawns & pawnAttacksBB[s];
        phalanx    = neighbours & rank_bb(s);
        supported  = neighbours & rank_bb(s - Up);
        connected  = supported | phalanx;
        isolated   = !neighbours;

lever = theirPawns & pawnAttacksBB[s];
phalanx = neighbours & rank_bb(s);
supported = neighbours & rank_bb(s - Up);
connected = supported | phalanx;
isolated = !neighbours;

// Test for backward pawn.
// If the pawn is passed, isolated, lever or connected it cannot be
// backward. If there are friendly pawns behind on adjacent files
// or if it is sufficiently advanced, it cannot be backward either.
if ( (passed | isolated | lever | connected)
|| (ourPawns & pawn_attack_span(Them, s))
|| (relative_rank(Us, s) >= RANK_5))
if ( (isolated | lever | connected) || (relative_rank(Us, s) >= RANK_5))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the same indentation as in the original code ?

backward = false;
else
{
// We now know there are no friendly pawns beside or behind this
// pawn on adjacent files. We now check whether the pawn is
// backward by looking in the forward direction on the adjacent
// files, and picking the closest pawn there.
b = pawn_attack_span(Us, s) & (ourPawns | theirPawns);
b = pawn_attack_span(Us, s) & rank_bb(backmost_sq(Us, b));

// If we have an enemy pawn in the same or next rank, the pawn is
// backward because it cannot advance without being captured.
backward = (b | shift_bb<Up>(b)) & theirPawns;
// Find the backmost rank with neighbours or stoppers
b = rank_bb(backmost_sq(Us, neighbours | stoppers));

// The pawn is backward when it cannot safely progress to that rank:
// either there is a stopper in the way on this rank,
// or there is a stopper on adjacent file which control the way to that rank
backward = (b | shift_bb<Up>(b & adjacent_files_bb(f))) & stoppers;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this 'b & adjacent_files_bb' needs some comment...

}

assert(opposed | passed | (pawn_attack_span(Us, s) & theirPawns));
assert(opposed | !stoppers | (pawn_attack_span(Us, s) & theirPawns));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assert is wrong because !stoppers is a bool and is bitwised 'or' with bitboards.


// Passed pawns will be properly scored in evaluation because we need
// full attack info to evaluate them. Only the frontmost passed
// pawn on each file is considered a true passed pawn.
if (passed && !doubled)
if (!(stoppers | doubled))
e->passedPawns[Us] |= s;

// Score this pawn
Expand Down