Skip to content

Commit

Permalink
First try
Browse files Browse the repository at this point in the history
Bench 3110425
  • Loading branch information
MJZ1977 committed May 13, 2019
1 parent 7f1fd7c commit 02092ac
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/pawns.cpp
Expand Up @@ -69,7 +69,7 @@ namespace {

Bitboard b, neighbours, stoppers, doubled, support, phalanx;
Bitboard lever, leverPush;
Square s;
Square s, opposedPawn;
bool opposed, backward;
Score score = SCORE_ZERO;
const Square* pl = pos.squares<PAWN>(Us);
Expand All @@ -89,11 +89,6 @@ namespace {
File f = file_of(s);
Rank r = relative_rank(Us, s);

if (theirPawns & (s+Up))
e->pawnAttacksSpan[Us] |= PawnAttacks[Us][s];
else
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);

// Flag the pawn
opposed = theirPawns & forward_file_bb(Us, s);
stoppers = theirPawns & passed_pawn_span(Us, s);
Expand All @@ -104,6 +99,16 @@ namespace {
phalanx = neighbours & rank_bb(s);
support = neighbours & rank_bb(s - Up);

if (Us == WHITE)
opposedPawn = lsb(theirPawns & forward_file_bb(Us, s));
else
opposedPawn = msb(theirPawns & forward_file_bb(Us, s));

if (opposed)
e->pawnAttacksSpan[Us] |= (pawn_attack_span(Us, s) & ~pawn_attack_span(Us, opposedPawn));
else
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);

// A pawn is backward when it is behind all pawns of the same color
// on the adjacent files and cannot be safely advanced.
backward = !(ourPawns & pawn_attack_span(Them, s + Up))
Expand Down

2 comments on commit 02092ac

@locutus2
Copy link

Choose a reason for hiding this comment

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

@MJZ1977
This patch have the problem that the lsb and msb functions are not well defined if the argument is zero (which is the case if the pawn unopposed).

Also its better to use the function backmost_sq instead of lsb and msb. This is more readable and hides the use of lsb and msb.

So following code would be correct and more readable:
if (opposed) e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s) & ~pawn_attack_span(Us, backmost_sq(Us, theirPawns & forward_file_bb(Us, s))); else e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);

@MJZ1977
Copy link
Owner Author

Choose a reason for hiding this comment

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

Thank you for advice !

Please sign in to comment.