backward pawns in Stockfish

Discussion of chess software programming and technical issues.

Moderator: Ras

lech
Posts: 1169
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)) 
          || (pos.attacks_from<PAWN>(s, Us) & theirPawns)) 
          backward = false; 
      else 
      { 
          b = this_and_neighboring_files_bb(f) & rank_bb(Us == WHITE ? r+1 : r-1); 

         while (!(b & (ourPawns | theirPawns))) 
              Us == WHITE ? b <<= 8 : b >>= 8; 

          if (b & file_bb(f) & theirPawns) 
             backward = false; 
         else backward = (b | (Us == WHITE ? b << 8 : b >> 8)) & theirPawns; 
        } 
the second patch:

Code: Select all

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

          while (!(b & (ourPawns | theirPawns))) 
              Us == WHITE ? b <<= 8 : b >>= 8; 

          if (b & file_bb(f) & theirPawns) 
            backward = true;
         else backward = (b | (Us == WHITE ? b << 8 : b >> 8)) & theirPawns; 
        } 
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 (   (passed | isolated | chain) 
          || (ourPawns & attack_span_mask(opposite_color(Us), s)) 
          || (pos.attacks_from<PAWN>(s, Us) & theirPawns)) 
          backward = false; 
      else 
      { 
          b = this_and_neighboring_files_bb(f) & rank_bb(Us == WHITE ? r+1 : r-1); 

         while (!(b & (ourPawns | theirPawns))) 
              Us == WHITE ? b <<= 8 : b >>= 8; 

          if (b & file_bb(f) & theirPawns) 
             backward = false; 
         else backward = (b | (Us == WHITE ? b << 8 : b >> 8)) & theirPawns; 
        } 
the second patch:

Code: Select all

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

          while (!(b & (ourPawns | theirPawns))) 
              Us == WHITE ? b <<= 8 : b >>= 8; 

          if (b & file_bb(f) & theirPawns) 
            backward = true;
         else backward = (b | (Us == WHITE ? b << 8 : b >> 8)) & theirPawns; 
        } 
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: 1169
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: 1169
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 (d < 0 || pathDefended)
            {
                int mtg = RANK_8 - relative_rank(c, s);
change:

Code: Select all

if (d < 0 || pathDefended)
            {
                int mtg = RANK_8 - relative_rank(c, s) 
		- (relative_rank(c, s) == RANK_2); // Double pawn push

Next:

Code: Select all

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

Code: Select all

               if (   (squares_behind(Us, s) & pos.pieces(ROOK, QUEEN, Them))
                    && (squares_behind(Us, s) & pos.pieces(ROOK, QUEEN, Them) & pos.attacks_from<ROOK>(s)))
 
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: 1169
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 (   (passed | isolated | chain) 
          || (ourPawns & attack_span_mask(opposite_color(Us), s)) 
          || (pos.attacks_from<PAWN>(s, Us) & theirPawns)) 
          backward = false; 
      else 
      { 
           b = this_and_neighboring_files_bb(f) & rank_bb(Us == WHITE ? r+1 : r-1); 

          while (!(b & (ourPawns | theirPawns))) 
              Us == WHITE ? b <<= 8 : b >>= 8; 

          if (b & file_bb(f) & theirPawns) 
            backward = true; 
         else backward = (b | (Us == WHITE ? b << 8 : b >> 8)) & theirPawns; 
        } 
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: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: