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

backward pawns in Stockfish

Post by lech »

I have a new idea for backwards pawns.
I compiled it with MS Visual C++ 2008 (without optimizations).
Unfortunatelly, I had to stop a test (P IV 3GHz):

Code: Select all

cutechess-cli -fcp name=sfx cmd=sfx.exe proto=uci book=book.bin bookdepth=12 option.Threads=2 option.Hash=64 option.Ponder=false -scp name=sf cmd=sf.exe proto=uci book=book.bin bookdepth=12 option.Threads=2 option.Hash=64 option.Ponder=false -both tc=/1:0 -games 300 -repeat -resign 3 700
The new version seems to be a bit better: sfx vs sf: +38 - 27 =35.
Is there a sense (setting - comp, cute, C++, score) to continue this test.

I tested such a thing.

Code: Select all

// Test for backward pawn
      //
      // If the pawn is passed, isolated, or member of a pawn chain
      // it cannot be backward. If can capture an enemy pawn or if
      // there are friendly pawns behind on neighboring files it cannot
      // be backward either.
      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;
          // We now know that there are no friendly pawns beside or behind this
          // pawn on neighboring files. We now check whether the pawn is
          // backward by looking in the forward direction on the neighboring
          // files, and seeing whether we meet a friendly or an enemy pawn first.
            b = this_and_neighboring_files_bb&#40;f&#41; & rank_bb&#40;Us == WHITE ? r+1 &#58; r-1&#41;;

          // Note that we are sure to find something because pawn is not passed
          // nor isolated, so loop is potentially infinite, but it isn't.
          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 = !&#40;neighboring_files_bb&#40;f&#41; & theirPawns&#41;;
		  // The friendly pawn needs to be at least two ranks closer than the enemy
          // pawn in order to help the potentially backward pawn advance.
          else backward = &#40;b | &#40;Us == WHITE ? b << 8 &#58; b >> 8&#41;) & theirPawns; 
        &#125;
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: backward pawns in Stockfish

Post by mcostalba »

lech wrote: Is there a sense (setting - comp, cute, C++, score) to continue this test.
If I have understood correctly you extend definition of backward pawns also to pawns that have an enemy pawn in front and don't have enemy pawns on neighboring files. Is it correct ?

Could you please post a chess diagram, a position with an example of a backward pawn according to your new definition that is _not_ considered a backward pawn by default SF ?


P.S: I think it is interesting and I would suggest to continue the test, also cutechess command line seems fine.
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: backward pawns in Stockfish

Post by lech »

mcostalba wrote:
lech wrote: Is there a sense (setting - comp, cute, C++, score) to continue this test.
If I have understood correctly you extend definition of backward pawns also to pawns that have an enemy pawn in front and don't have enemy pawns on neighboring files. Is it correct ?

Could you please post a chess diagram, a position with an example of a backward pawn according to your new definition that is _not_ considered a backward pawn by default SF ?


P.S: I think it is interesting and I would suggest to continue the test, also cutechess command line seems fine.
In original SF there is possible a position:
[d] 8/6p1/8/5pPp/8/8/5P1P/8 b - -
After 1…g6 two pawns f2 and h2 become backward (??). My code is a patch (correction) for the SF’s code.
In my opinion, a single opposed enemy pawn can do a pawn backward.
I have some doubts looking trough the result of matches (cutechess-cli). There are too long strings of wins for one side. I think that engines don’t tire and have a healthy psyche.

I think, By the way, it would be good to correct that

Code: Select all

if &#40;isolated&#41;
      &#123;
          value -= IsolatedPawnPenalty&#91;f&#93;;
          if (!&#40;theirPawns & file_bb&#40;f&#41;))
              value -= IsolatedPawnPenalty&#91;f&#93; / 2;
      &#125;
      if &#40;doubled&#41;
          value -= DoubledPawnPenalty&#91;f&#93;;

      if &#40;backward&#41;
      &#123;
          value -= BackwardPawnPenalty&#91;f&#93;;
          if (!&#40;theirPawns & file_bb&#40;f&#41;))
              value -= BackwardPawnPenalty&#91;f&#93; / 2;
by this

Code: Select all

if &#40;isolated&#41;
      &#123;
          value -= IsolatedPawnPenalty&#91;f&#93;;
          if (!opposed&#41;
              value -= IsolatedPawnPenalty&#91;f&#93; / 2;
      &#125;
      if &#40;doubled&#41;
          value -= DoubledPawnPenalty&#91;f&#93;;

      if &#40;backward&#41;
      &#123;
          value -= BackwardPawnPenalty&#91;f&#93;;
          if (!opposed&#41;
              value -= BackwardPawnPenalty&#91;f&#93; / 2;
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: backward pawns in Stockfish

Post by mcostalba »

lech wrote: In original SF there is possible a position:
[d] 8/6p1/8/5pPp/8/8/5P1P/8 b - -
After 1…g6 two pawns f2 and h2 become backward (??). My code is a patch (correction) for the SF’s code.
In my opinion, a single opposed enemy pawn can do a pawn backward.
I have no enough chess knowledge to understand if pawns f2 and h2 are backward (for you they are) or are not, in the latter case your code should be changed in

Code: Select all

  // Test for backward pawn
  //
  backward = false;

  // If the pawn is passed, isolated, or member of a pawn chain
  // it cannot be backward. If can capture an enemy pawn or if
  // there are friendly pawns behind on neighboring files it cannot
  // be backward either.
  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;)
  &#123;
      // We now know that there are no friendly pawns beside or behind this
      // pawn on neighboring files. We now check whether the pawn is
      // backward by looking in the forward direction on the neighboring
      // files, and seeing whether we meet a friendly or an enemy pawn first.
      // We want to look also on our file because, if we are opposed, we
      // want to see if we cannot advance due to the opposed pawn.
      b = this_and_neighboring_files_bb&#40;f&#41; & rank_bb&#40;Us == WHITE ? r+1 &#58; r-1&#41;;

      // Note that we are sure to find something because pawn is not passed
      // nor isolated, so loop is potentially infinite, but it isn't.
      while (!&#40;b & &#40;ourPawns | theirPawns&#41;))
          Us == WHITE ? b <<= 8 &#58; b >>= 8;

      // If pawn advancement is not blocked by an opposing one then this is
      // potentially backward. The last check is to verify friendly pawn is
      // at least two ranks closer than the enemy pawn in order to help
      // the potentially backward pawn advance.
      if &#40;b & file_bb&#40;f&#41; & theirPawns == EmptyBoardBB&#41;
          backward = &#40;b | &#40;Us == WHITE ? b << 8 &#58; b >> 8&#41;) & theirPawns;
  &#125;
lech wrote: I think, By the way, it would be good to correct that

Code: Select all

if &#40;isolated&#41;
      &#123;
          value -= IsolatedPawnPenalty&#91;f&#93;;
          if (!&#40;theirPawns & file_bb&#40;f&#41;))
              value -= IsolatedPawnPenalty&#91;f&#93; / 2;
      &#125;
      if &#40;doubled&#41;
          value -= DoubledPawnPenalty&#91;f&#93;;

      if &#40;backward&#41;
      &#123;
          value -= BackwardPawnPenalty&#91;f&#93;;
          if (!&#40;theirPawns & file_bb&#40;f&#41;))
              value -= BackwardPawnPenalty&#91;f&#93; / 2;
by this

Code: Select all

if &#40;isolated&#41;
      &#123;
          value -= IsolatedPawnPenalty&#91;f&#93;;
          if (!opposed&#41;
              value -= IsolatedPawnPenalty&#91;f&#93; / 2;
      &#125;
      if &#40;doubled&#41;
          value -= DoubledPawnPenalty&#91;f&#93;;

      if &#40;backward&#41;
      &#123;
          value -= BackwardPawnPenalty&#91;f&#93;;
          if (!opposed&#41;
              value -= BackwardPawnPenalty&#91;f&#93; / 2;

Thanks, yes it would be correct :-)
Last edited by mcostalba on Sat Jul 17, 2010 6:09 pm, edited 1 time in total.
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: backward pawns in Stockfish

Post by lech »

mcostalba wrote: If I have understood correctly you extend definition of backward pawns also to pawns that have an enemy pawn in front and don't have enemy pawns on neighboring files. Is it correct ?
If you don't agree with this, it is possible to change the code:

Code: Select all

  Us == WHITE ? b <<= 8 &#58; b >>= 8; 
          if &#40;b & file_bb&#40;f&#41; & theirPawns&#41; 
         backward = false; 
        // The friendly pawn needs to be at least two ranks closer than the   enemy 
          // pawn in order to help the potentially backward pawn advance. 
          else backward = &#40;b | &#40;Us == WHITE ? b << 8 &#58; b >> 8&#41;) & theirPawns; 

After 200 games the result is Sfx vs Sf: +72 -59 =69.
Note that the pawn g6 (after 1...g6) in the mentioned above possition is not backward by the original code.
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: backward pawns in Stockfish

Post by michiguel »

lech wrote:
mcostalba wrote:
lech wrote: Is there a sense (setting - comp, cute, C++, score) to continue this test.
If I have understood correctly you extend definition of backward pawns also to pawns that have an enemy pawn in front and don't have enemy pawns on neighboring files. Is it correct ?

Could you please post a chess diagram, a position with an example of a backward pawn according to your new definition that is _not_ considered a backward pawn by default SF ?


P.S: I think it is interesting and I would suggest to continue the test, also cutechess command line seems fine.
In original SF there is possible a position:
[d] 8/6p1/8/5pPp/8/8/5P1P/8 b - -
After 1…g6 two pawns f2 and h2 become backward (??). My code is a patch (correction) for the SF’s code.
They are not backward pawns.

Miguel
In my opinion, a single opposed enemy pawn can do a pawn backward.
I have some doubts looking trough the result of matches (cutechess-cli). There are too long strings of wins for one side. I think that engines don’t tire and have a healthy psyche.

I think, By the way, it would be good to correct that

Code: Select all

if &#40;isolated&#41;
      &#123;
          value -= IsolatedPawnPenalty&#91;f&#93;;
          if (!&#40;theirPawns & file_bb&#40;f&#41;))
              value -= IsolatedPawnPenalty&#91;f&#93; / 2;
      &#125;
      if &#40;doubled&#41;
          value -= DoubledPawnPenalty&#91;f&#93;;

      if &#40;backward&#41;
      &#123;
          value -= BackwardPawnPenalty&#91;f&#93;;
          if (!&#40;theirPawns & file_bb&#40;f&#41;))
              value -= BackwardPawnPenalty&#91;f&#93; / 2;
by this

Code: Select all

if &#40;isolated&#41;
      &#123;
          value -= IsolatedPawnPenalty&#91;f&#93;;
          if (!opposed&#41;
              value -= IsolatedPawnPenalty&#91;f&#93; / 2;
      &#125;
      if &#40;doubled&#41;
          value -= DoubledPawnPenalty&#91;f&#93;;

      if &#40;backward&#41;
      &#123;
          value -= BackwardPawnPenalty&#91;f&#93;;
          if (!opposed&#41;
              value -= BackwardPawnPenalty&#91;f&#93; / 2;
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: backward pawns in Stockfish

Post by lech »

mcostalba wrote:

Code: Select all

  // Test for backward pawn
  //
  backward = false;

  // If the pawn is passed, isolated, or member of a pawn chain
  // it cannot be backward. If can capture an enemy pawn or if
  // there are friendly pawns behind on neighboring files it cannot
  // be backward either.
  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;)
  &#123;
      // We now know that there are no friendly pawns beside or behind this
      // pawn on neighboring files. We now check whether the pawn is
      // backward by looking in the forward direction on the neighboring
      // files, and seeing whether we meet a friendly or an enemy pawn first.
      // We want to look also on our file because, if we are opposed, we
      // want to see if we cannot advance due to the opposed pawn.
      b = this_and_neighboring_files_bb&#40;f&#41; & rank_bb&#40;Us == WHITE ? r+1 &#58; r-1&#41;;

      // Note that we are sure to find something because pawn is not passed
      // nor isolated, so loop is potentially infinite, but it isn't.
      while (!&#40;b & &#40;ourPawns | theirPawns&#41;))
          Us == WHITE ? b <<= 8 &#58; b >>= 8;

      // If pawn advancement is not blocked by an opposing one then this is
      // potentially backward. The last check is to verify friendly pawn is
      // at least two ranks closer than the enemy pawn in order to help
      // the potentially backward pawn advance.
      if &#40;b & file_bb&#40;f&#41; & theirPawns == EmptyBoardBB&#41;
          backward = &#40;b | &#40;Us == WHITE ? b << 8 &#58; b >> 8&#41;) & theirPawns;
  &#125;
if not "if (b & file_bb(f) & theirPawns == EmptyBoardBB)" backward don't have a value (??) Sorry i see. :oops:
Last edited by lech on Sat Jul 17, 2010 6:14 pm, edited 1 time in total.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: backward pawns in Stockfish

Post by mcostalba »

lech wrote: If you don't agree with this, it is possible to change the code:
Is not that I don't agree. I simply don't know :-)

200 games are not a lot but still now seems promising.
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: backward pawns in Stockfish

Post by lech »

mcostalba wrote:
lech wrote: If you don't agree with this, it is possible to change the code:
Is not that I don't agree. I simply don't know :-)

200 games are not a lot but still now seems promising.
I understand, your version is more secure. My is a speculation. You are right. :D
In both cases SF should play "a bit" better. :wink:
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: backward pawns in Stockfish

Post by lech »

after 300 games sfx vs sf: +113 -86 =101
next session tomorow :)