backward pawns in Stockfish

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: backward pawns in Stockfish

Post by lech »

[d] 8/8/1p6/pPp5/P1P5/8/8/8 w - -
Are the pawn b6, a4, c4 backward (week) or not ?
Let Stockfish say what prefers. :D
The first patch:

Code: Select all

// Test for backward pawn 
      if (   (passed | isolated | chain) 
          || (ourPawns & attack_span_mask(opposite_color(Us), s)) 
          || &#40;pos.attacks_from<PAWN>&#40;s, Us&#41; & theirPawns&#41;) 
          backward = false; 
      else 
      &#123; 
          b = this_and_neighboring_files_bb&#40;f&#41; & rank_bb&#40;Us == WHITE ? r+1 &#58; r-1&#41;; 

         while (!&#40;b & &#40;ourPawns | theirPawns&#41;)) 
              Us == WHITE ? b <<= 8 &#58; b >>= 8; 

          if &#40;b & file_bb&#40;f&#41; & theirPawns&#41; 
             backward = false; 
         else backward = &#40;b | &#40;Us == WHITE ? b << 8 &#58; b >> 8&#41;) & theirPawns; 
        &#125; 
the second patch:

Code: Select all

// Test for backward pawn 
           if (   &#40;passed | isolated | chain&#41; 
          || &#40;ourPawns & attack_span_mask&#40;opposite_color&#40;Us&#41;, s&#41;) 
          || &#40;pos.attacks_from<PAWN>&#40;s, Us&#41; & theirPawns&#41;) 
          backward = false; 
      else 
      &#123; 
           b = this_and_neighboring_files_bb&#40;f&#41; & rank_bb&#40;Us == WHITE ? r+1 &#58; r-1&#41;; 

          while (!&#40;b & &#40;ourPawns | theirPawns&#41;)) 
              Us == WHITE ? b <<= 8 &#58; b >>= 8; 

          if &#40;b & file_bb&#40;f&#41; & theirPawns&#41; 
            backward = true;
         else backward = &#40;b | &#40;Us == WHITE ? b << 8 &#58; b >> 8&#41;) & theirPawns; 
        &#125; 
The short match (100 games; 1 min/game) won the second patch +39 -32 =29.
Marco was right. :?
It seems that the second patch should be tested against original SF, not the first. :roll:
(I tried it ..... :wink: )
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: backward pawns in Stockfish

Post by bob »

lech wrote:[d] 8/8/1p6/pPp5/P1P5/8/8/8 w - -
Are the pawn b6, a4, c4 backward (week) or not ?
Let Stockfish say what prefers. :D
The first patch:

Code: Select all

// Test for backward pawn 
      if (   &#40;passed | isolated | chain&#41; 
          || &#40;ourPawns & attack_span_mask&#40;opposite_color&#40;Us&#41;, s&#41;) 
          || &#40;pos.attacks_from<PAWN>&#40;s, Us&#41; & theirPawns&#41;) 
          backward = false; 
      else 
      &#123; 
          b = this_and_neighboring_files_bb&#40;f&#41; & rank_bb&#40;Us == WHITE ? r+1 &#58; r-1&#41;; 

         while (!&#40;b & &#40;ourPawns | theirPawns&#41;)) 
              Us == WHITE ? b <<= 8 &#58; b >>= 8; 

          if &#40;b & file_bb&#40;f&#41; & theirPawns&#41; 
             backward = false; 
         else backward = &#40;b | &#40;Us == WHITE ? b << 8 &#58; b >> 8&#41;) & theirPawns; 
        &#125; 
the second patch:

Code: Select all

// Test for backward pawn 
           if (   &#40;passed | isolated | chain&#41; 
          || &#40;ourPawns & attack_span_mask&#40;opposite_color&#40;Us&#41;, s&#41;) 
          || &#40;pos.attacks_from<PAWN>&#40;s, Us&#41; & theirPawns&#41;) 
          backward = false; 
      else 
      &#123; 
           b = this_and_neighboring_files_bb&#40;f&#41; & rank_bb&#40;Us == WHITE ? r+1 &#58; r-1&#41;; 

          while (!&#40;b & &#40;ourPawns | theirPawns&#41;)) 
              Us == WHITE ? b <<= 8 &#58; b >>= 8; 

          if &#40;b & file_bb&#40;f&#41; & theirPawns&#41; 
            backward = true;
         else backward = &#40;b | &#40;Us == WHITE ? b << 8 &#58; b >> 8&#41;) & theirPawns; 
        &#125; 
The short match (100 games; 1 min/game) won the second patch +39 -32 =29.
Marco was right. :?
It seems that the second patch should be tested against original SF, not the first. :roll:
(I tried it ..... :wink: )
The major problem above is the number of games. The error bar will be larger than the difference in ratings, which makes any conclusion nothing more than a guess...

This is the perfect way to take two steps backward for every one step forward...
Justin Sherron
Posts: 29
Joined: Thu Mar 04, 2010 11:35 pm

Re: backward pawns in Stockfish

Post by Justin Sherron »

Hi Marek,

Have you continued to test this second patch? I've played (only) 300 90-second games, but this patch scored an impressive ~55% against my compile of the original code (55, 53.5, and 56% in 3 separate 100 game matches). Much better results than the first patch I tried :wink:
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: backward pawns in Stockfish

Post by lech »

Justin Sherron wrote:Hi Marek,

Have you continued to test this second patch? I've played (only) 300 90-second games, but this patch scored an impressive ~55% against my compile of the original code (55, 53.5, and 56% in 3 separate 100 game matches). Much better results than the first patch I tried :wink:
Justin, I will test the second version but with one modification. I guess :D it can work even better. I found two bugs in SF code. But it is another story. :wink:
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: backward pawns in Stockfish

Post by mcostalba »

lech wrote:I found two bugs in SF code. But it is another story. :wink:
Could you please report them ?

Thanks.
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: backward pawns in Stockfish

Post by lech »

mcostalba wrote:
lech wrote:I found two bugs in SF code. But it is another story. :wink:
Could you please report them ?

Thanks.
Of course, why not ? :lol:

First:

Code: Select all

 evaluate_unstoppable_pawns
if &#40;d < 0 || pathDefended&#41;
            &#123;
                int mtg = RANK_8 - relative_rank&#40;c, s&#41;;
change:

Code: Select all

if &#40;d < 0 || pathDefended&#41;
            &#123;
                int mtg = RANK_8 - relative_rank&#40;c, s&#41; 
		- &#40;relative_rank&#40;c, s&#41; == RANK_2&#41;; // Double pawn push

Next:

Code: Select all

 evaluate_passed_pawns
                   if (   &#40;squares_behind&#40;Us, s&#41; & pos.pieces&#40;ROOK, QUEEN, Them&#41;)
                    && &#40;squares_behind&#40;Us, s&#41; & pos.pieces&#40;ROOK, QUEEN, Them&#41; & pos.attacks_from<QUEEN>&#40;s&#41;))
 
change:

Code: Select all

               if (   &#40;squares_behind&#40;Us, s&#41; & pos.pieces&#40;ROOK, QUEEN, Them&#41;)
                    && &#40;squares_behind&#40;Us, s&#41; & pos.pieces&#40;ROOK, QUEEN, Them&#41; & pos.attacks_from<ROOK>&#40;s&#41;))
 
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: backward pawns in Stockfish

Post by mcostalba »

lech wrote: Of course, why not ? :lol:
The second is more an optimization then a fix, the first one is a real fix although for a very rare case.

Thanks Marek !
Justin Sherron
Posts: 29
Joined: Thu Mar 04, 2010 11:35 pm

Re: backward pawns in Stockfish

Post by Justin Sherron »

Just a quick update - I made it to 500 games (I'll probably quit at that, since I was just doing it out of curiosity). The patch scored 50% and 54% in the 4th and 5th set of 100 games, for a cumulative score of 53.7% after 500 games. Of course, I'm a testing newbie and exceptionally non-talented with computers, which should be taken into consideration when reading my numbers :) . But in any case, I hope it's helpful.
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: backward pawns in Stockfish

Post by lech »

Justin Sherron wrote:Just a quick update - I made it to 500 games (I'll probably quit at that, since I was just doing it out of curiosity). The patch scored 50% and 54% in the 4th and 5th set of 100 games, for a cumulative score of 53.7% after 500 games. Of course, I'm a testing newbie and exceptionally non-talented with computers, which should be taken into consideration when reading my numbers :) . But in any case, I hope it's helpful.
I tested the second patch:

Code: Select all

// Test for backward pawn 
           if (   &#40;passed | isolated | chain&#41; 
          || &#40;ourPawns & attack_span_mask&#40;opposite_color&#40;Us&#41;, s&#41;) 
          || &#40;pos.attacks_from<PAWN>&#40;s, Us&#41; & theirPawns&#41;) 
          backward = false; 
      else 
      &#123; 
           b = this_and_neighboring_files_bb&#40;f&#41; & rank_bb&#40;Us == WHITE ? r+1 &#58; r-1&#41;; 

          while (!&#40;b & &#40;ourPawns | theirPawns&#41;)) 
              Us == WHITE ? b <<= 8 &#58; b >>= 8; 

          if &#40;b & file_bb&#40;f&#41; & theirPawns&#41; 
            backward = true; 
         else backward = &#40;b | &#40;Us == WHITE ? b << 8 &#58; b >> 8&#41;) & theirPawns; 
        &#125; 
with optimization:

Code: Select all

C++
general
debug information format - disabled
optimization
optimization - maximize speed
favor size or speed - favor fast code
code generation
basics runtime checks - default
and command line:

Code: Select all

cutechess-cli.exe -fcp name=sfx cmd=sfx.exe -scp name=sf cmd=sf.exe -both proto=uci option.Threads=2 option.Ponder=false book=book.bin bookdepth=12 option.Hash=64 tc=/0&#58;30+0 -resign 3 700 -wait 1000 -games 100 -repeat
sfx size: 469 504
sf size: 468 992
Now it seems to be ok. :oops:
After 100 games: sfx vs sf: +33 -22 =45 :lol:
I will continue test tomorow. 8-)
A try to improve this patch doesn't work. :cry: