Rule of Square test position

Discussion of chess software programming and technical issues.

Moderator: Ras

CRoberson
Posts: 2091
Joined: Mon Mar 13, 2006 2:31 am
Location: North Carolina, USA

Rule of Square test position

Post by CRoberson »

Well, I wrote rule of square code (unstoppable passer) for NoonianChess
10 years ago and rewrote it completely for Telepath 3 years ago. Today,
I found a position that fits the logic perfectly and shows how wrong it
is.

[d] 8/8/6p1/1P5p/5k2/K1P5/P7/8 b - - 0 50

The logic was:

Code: Select all

       find the  passers for each side
       toss out any passers the oppsing kings can catch
       of remaining passers, take the leading one and give big bonus to
         the side with it as long as it is ahead of the opposing best one.
  
Seemed like fairly simple sound logic.
But the position clearly shows it is lacking

Thought some of you might find the position useful.

Time for me to rethink and rewrite some old code.
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Rule of Square test position

Post by michiguel »

CRoberson wrote:Well, I wrote rule of square code (unstoppable passer) for NoonianChess
10 years ago and rewrote it completely for Telepath 3 years ago. Today,
I found a position that fits the logic perfectly and shows how wrong it
is.

[d] 8/8/6p1/1P5p/5k2/K1P5/P7/8 b - - 0 50

The logic was:

Code: Select all

       find the  passers for each side
       toss out any passers the oppsing kings can catch
       of remaining passers, take the leading one and give big bonus to
         the side with it as long as it is ahead of the opposing best one.
  
Seemed like fairly simple sound logic.
But the position clearly shows it is lacking

Thought some of you might find the position useful.

Time for me to rethink and rewrite some old code.
This is very complex. In fact, this seems to be a draw with the help of the white king. Gaviota thinks black is winning and later changes its mind. So, it will happily (and wrongly) simplifies the position thinking is winning.
This reminds me of the famous Reti composition (see below)

Gaviota's analysis.

Code: Select all

        10   1:      0.0    +3.41  Kf4-e5   
        34   2:      0.0    +3.06  Kf4-e5   c3-c4    
       197   3:      0.0    +3.39  Kf4-e5   Ka3-b4   Ke5-d5   
       625   4       0.0      :-(  
      1134   4:      0.0    +2.97  Kf4-e5   Ka3-b4   Ke5-d5   a2-a4    
      1683   5       0.0      :-)  Kf4-e5   
      2818   5:      0.0    +3.36  Kf4-e5   Ka3-b4   Ke5-d6   Kb4-c4   
                                   h5-h4    
      5830   6       0.0      :-(  
      9289   6:      0.0    +2.91  Kf4-e5   Ka3-b4   Ke5-d6   Kb4-c4   
                                   h5-h4    a2-a4    
     21340   7:      0.1    +3.00  Kf4-e5   Ka3-b4   Ke5-d6   a2-a4    
                                   Kd6-c7   a4-a5    Kc7-b8   
     37514   8       0.2    +3.09  Kf4-e5   Ka3-b4   Ke5-d6   Kb4-c4   
                                   h5-h4    Kc4-d4   h4-h3    a2-a4    
     53355   8:      0.2    +3.09  Kf4-e5   Ka3-b4   Ke5-d6   Kb4-c4   
                                   h5-h4    Kc4-d4   h4-h3    a2-a4    
     91328   9       0.4    +3.12  Kf4-e5   Ka3-b4   Ke5-d6   c3-c4    
                                   Kd6-c7   c4-c5    g6-g5    a2-a4    
                                   Kc7-b8   <-transp 
    162694   9:      0.6    +3.12  Kf4-e5   Ka3-b4   Ke5-d6   c3-c4    
                                   Kd6-c7   c4-c5    g6-g5    a2-a4    
                                   Kc7-b8   <-transp 
    310924  10       1.1    +2.89  Kf4-e5   Ka3-b4   Ke5-d6   Kb4-a5   
                                   Kd6-c7   Ka5-a6   Kc7-b8   a2-a4    
                                   g6-g5    a4-a5    
    433233  10:      1.3    +2.89  Kf4-e5   Ka3-b4   Ke5-d6   Kb4-a5   
                                   Kd6-c7   Ka5-a6   Kc7-b8   a2-a4    
                                   g6-g5    a4-a5    
    637547  11       1.6    +2.94  Kf4-e5   Ka3-b4   Ke5-d6   Kb4-a5   
                                   Kd6-c7   Ka5-a6   Kc7-b8   a2-a4    
                                   g6-g5    a4-a5    Kb8-c7   
    921917  11:      2.0    +2.94  Kf4-e5   Ka3-b4   Ke5-d6   Kb4-a5   
                                   Kd6-c7   Ka5-a6   Kc7-b8   a2-a4    
                                   g6-g5    a4-a5    Kb8-c7   
   1596155  12       3.1    +2.71  Kf4-e5   Ka3-b4   Ke5-d6   Kb4-a5   
                                   Kd6-c7   Ka5-a6   Kc7-b8   a2-a4    
                                   g6-g5    c3-c4    g5-g4    c4-c5    
   2507947  12:      4.4    +2.71  Kf4-e5   Ka3-b4   Ke5-d6   Kb4-a5   
                                   Kd6-c7   Ka5-a6   Kc7-b8   a2-a4    
                                   g6-g5    c3-c4    g5-g4    c4-c5    
   3168629  13       5.5      :-)  Kf4-e5   
  11548303  13      17.4    +3.19  Kf4-e5   b5-b6    Ke5-d6   Ka3-b4   
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    g6-g5    c5-c6    
                                   Kb7-c8   c6-c7    Kc8-b7   a2-a4    
  18201326  13:     26.4    +3.19  Kf4-e5   b5-b6    Ke5-d6   Ka3-b4   
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    g6-g5    c5-c6    
                                   Kb7-c8   c6-c7    Kc8-b7   a2-a4    
  19449364  14      28.3      :-)  Kf4-e5   
  21365024  14      31.2    +3.48  Kf4-e5   Ka3-b4   Ke5-d6   b5-b6    
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    h4-h3    Ka5-b5   
                                   h3-h2    c5-c6    Kb7-c8   b6-b7    
                                   Kc8-c7   
  28316310  14:     41.4    +3.48  Kf4-e5   Ka3-b4   Ke5-d6   b5-b6    
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    h4-h3    Ka5-b5   
                                   h3-h2    c5-c6    Kb7-c8   b6-b7    
                                   Kc8-c7   
  66011136  15      98.4      :-(  Kf4-e5   
  91655555  15     136.1      :-(  
 122619849  15     184.2      :-(  Kf4-e5   
 149264138  15     224.4      :-(  
 175809874  15     266.7    +0.44  Kf4-e5   b5-b6    Ke5-d6   Ka3-b4   
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    h4-h3    c5-c6    
                                   Kb7xc6   Ka5-a6   h3-h2    b6-b7    
                                   h2-h1=Q  b7-b8=Q  Qh1-f3   
 207047011  15:    318.9    +0.44  Kf4-e5   b5-b6    Ke5-d6   Ka3-b4   
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    h4-h3    c5-c6    
                                   Kb7xc6   Ka5-a6   h3-h2    b6-b7    
                                   h2-h1=Q  b7-b8=Q  Qh1-f3   
 263713838  16     408.1    +0.43  Kf4-e5   b5-b6    Ke5-d6   Ka3-b4   
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    h4-h3    c5-c6    
                                   Kb7xc6   Ka5-a6   h3-h2    b6-b7    
                                   h2-h1=Q  b7-b8=Q  Qh1-f1   Ka6-a5   
                                   Qf1-f3   
 340473076  16:    534.3    +0.43  Kf4-e5   b5-b6    Ke5-d6   Ka3-b4   
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    h4-h3    c5-c6    
                                   Kb7xc6   Ka5-a6   h3-h2    b6-b7    
                                   h2-h1=Q  b7-b8=Q  Qh1-f1   Ka6-a5   
                                   Qf1-f3   
 541661279  17     852.1    +0.12  Kf4-e5   b5-b6    Ke5-d6   Ka3-b4   
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    h4-h3    c5-c6    
                                   Kb7xc6   Ka5-a6   h3-h2    b6-b7    
                                   h2-h1=Q  b7-b8=Q  Qh1-f1   Ka6-a5   
                                   Qf1-f5   Ka5-a4   Qf5-f2   
 983635444  17:   1640.3    +0.12  Kf4-e5   b5-b6    Ke5-d6   Ka3-b4   
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    h4-h3    c5-c6    
                                   Kb7xc6   Ka5-a6   h3-h2    b6-b7    
                                   h2-h1=Q  b7-b8=Q  Qh1-f1   Ka6-a5   
                                   Qf1-f5   Ka5-a4   Qf5-f2   
1699938309  18    2744.2    +0.13  Kf4-e5   b5-b6    Ke5-d6   Ka3-b4   
                                   Kd6-c6   Kb4-a5   Kc6-b7   c3-c4    
                                   h5-h4    c4-c5    h4-h3    c5-c6    
                                   Kb7xc6   Ka5-a6   h3-h2    b6-b7    
                                   h2-h1=Q  b7-b8=Q  Qh1-f1   Ka6-a5   
                                   Qf1-f5   Ka5-a4   Qf5-c2   Ka4-a3   
                                   Qc2-f2   
This position may break your code too (as well as all or many of the engines).
Reti, white draws.

[d]7K/8/k1P5/7p/8/8/8/8 w - -

Regards,
Miguel
CRoberson
Posts: 2091
Joined: Mon Mar 13, 2006 2:31 am
Location: North Carolina, USA

Re: Rule of Square test position

Post by CRoberson »

Good point on Reti's study. Saw that position in 1988 and forgot about
it. Knew the solution as soon as I saw your post. Thanks, that made me change
direction on how to approach the problem.

Also, you may enjoy the following position that occured later
in the game. At first glance, it looks like a black win but it is a draw.
Play it through via tablebases and the solution is quite neat. How the
white king swings around to catch the "uncatchable" pawn.

[d] 8/K7/6p1/P1k5/8/8/8/8 b - - 0 65
rjgibert
Posts: 317
Joined: Mon Jun 26, 2006 9:44 am

Re: Rule of Square test position

Post by rjgibert »

CRoberson wrote:Good point on Reti's study. Saw that position in 1988 and forgot about
it. Knew the solution as soon as I saw your post. Thanks, that made me change
direction on how to approach the problem.

Also, you may enjoy the following position that occured later
in the game. At first glance, it looks like a black win but it is a draw.
Play it through via tablebases and the solution is quite neat. How the
white king swings around to catch the "uncatchable" pawn.

[d] 8/K7/6p1/P1k5/8/8/8/8 b - - 0 65
You must mean 1...Kc6 2. Kb8 Kb5 3. Kb7 Kxa5 4. Kc6..., etc. However, no "swinging" is required. White has the simpler, quicker draw by 1...Kc6 2. a6 Kc7 3. Ka8 g5 4. a7 g4 stalemate.
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Rule of Square test position

Post by michiguel »

rjgibert wrote:
CRoberson wrote:Good point on Reti's study. Saw that position in 1988 and forgot about
it. Knew the solution as soon as I saw your post. Thanks, that made me change
direction on how to approach the problem.

Also, you may enjoy the following position that occured later
in the game. At first glance, it looks like a black win but it is a draw.
Play it through via tablebases and the solution is quite neat. How the
white king swings around to catch the "uncatchable" pawn.

[d] 8/K7/6p1/P1k5/8/8/8/8 b - - 0 65
You must mean 1...Kc6 2. Kb8 Kb5 3. Kb7 Kxa5 4. Kc6..., etc. However, no "swinging" is required. White has the simpler, quicker draw by 1...Kc6 2. a6 Kc7 3. Ka8 g5 4. a7 g4 stalemate.
I just found this one:
http://www.queensac.com/chessblog/games/reti4.htm

Miguel
pijl

Re: Rule of Square test position

Post by pijl »

CRoberson wrote:Well, I wrote rule of square code (unstoppable passer) for NoonianChess
10 years ago and rewrote it completely for Telepath 3 years ago. Today,
I found a position that fits the logic perfectly and shows how wrong it
is.

[d] 8/8/6p1/1P5p/5k2/K1P5/P7/8 b - - 0 50

The logic was:

Code: Select all

       find the  passers for each side
       toss out any passers the oppsing kings can catch
       of remaining passers, take the leading one and give big bonus to
         the side with it as long as it is ahead of the opposing best one.
  
Seemed like fairly simple sound logic.
But the position clearly shows it is lacking

Thought some of you might find the position useful.

Time for me to rethink and rewrite some old code.
I've encountered quite a few of these positions, and decided at some point that I would not give the unstoppable passer bonus when the opponent had a passer that was more advanced than the unstoppable one, and counted on search to find out whether the passer was really unstoppable or not. Downside of course is that the bonus is not given in many cases where it should.
Initially I implemented in this way in Crashtest dummy as well. So CTD021 will give excellent results when feeding it the positions in this thread, even without search.
Later I found that the downside of handling the potential unstoppables in this way was bigger than the advantage of not trading down a won game to this type of draws or losses, so I removed it again in the later CTD versions. As expected it has problems with this position now too (although it correctly reports a drawish score in a matter of seconds).
Richard.
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: Rule of Square test position

Post by Michael Sherwin »

CRoberson wrote:Well, I wrote rule of square code (unstoppable passer) for NoonianChess
10 years ago and rewrote it completely for Telepath 3 years ago. Today,
I found a position that fits the logic perfectly and shows how wrong it
is.

[d] 8/8/6p1/1P5p/5k2/K1P5/P7/8 b - - 0 50

The logic was:

Code: Select all

       find the  passers for each side
       toss out any passers the oppsing kings can catch
       of remaining passers, take the leading one and give big bonus to
         the side with it as long as it is ahead of the opposing best one.
  
Seemed like fairly simple sound logic.
But the position clearly shows it is lacking

Thought some of you might find the position useful.

Time for me to rethink and rewrite some old code.
Back when computers were much slower this kind of eval code was very usefull and made a big positive difference. Now, not so much so, as the search can find what the code is designed to indicate.

Now, the code should be written in such a way as to indicate that by counter threats there is the possibility for the 'uncatchable passed pawn' to be caught. But, that may also be covered in the search by extentions.
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
pijl

Re: Rule of Square test position

Post by pijl »

Michael Sherwin wrote: Back when computers were much slower this kind of eval code was very usefull and made a big positive difference. Now, not so much so, as the search can find what the code is designed to indicate.

Now, the code should be written in such a way as to indicate that by counter threats there is the possibility for the 'uncatchable passed pawn' to be caught. But, that may also be covered in the search by extentions.
It is still quite important.
As you know, search in pawn endings goes into double digits within a second and reaches major depths quickly. So when searching in pawn endings it is of a lesser importance.
But the challenge is to trade down to winning pawn endings. Imagine you have a position with a few pieces (including queen) where the search manages to examine a pawn ending with only a few plies left. You really want to know whether the passer you have has a fair chance of being unstoppable. You might even need to sac a pawn (or more) for it to reach that ending. Knowledge that tells you that you have a winning ending without the 10 plies of search that you would need to find that out could be a crucial addition to your program.
Richard.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Rule of Square test position

Post by bob »

Michael Sherwin wrote:
CRoberson wrote:Well, I wrote rule of square code (unstoppable passer) for NoonianChess
10 years ago and rewrote it completely for Telepath 3 years ago. Today,
I found a position that fits the logic perfectly and shows how wrong it
is.

[d] 8/8/6p1/1P5p/5k2/K1P5/P7/8 b - - 0 50

The logic was:

Code: Select all

       find the  passers for each side
       toss out any passers the oppsing kings can catch
       of remaining passers, take the leading one and give big bonus to
         the side with it as long as it is ahead of the opposing best one.
  
Seemed like fairly simple sound logic.
But the position clearly shows it is lacking

Thought some of you might find the position useful.

Time for me to rethink and rewrite some old code.
Back when computers were much slower this kind of eval code was very usefull and made a big positive difference. Now, not so much so, as the search can find what the code is designed to indicate.

Now, the code should be written in such a way as to indicate that by counter threats there is the possibility for the 'uncatchable passed pawn' to be caught. But, that may also be covered in the search by extentions.
You are overlooking the main problem. It is not whether or not the search can resolve this position, which it clearly can. It is whether the search can resolve the position 20 plies earlier to determine whether to try to reach this position or not, and the answer there is clearly no.

You have to evaluate these positions or you are going to lose lots of endings. If you can't get it perfect, you have to make it as correct as possible so that you don't make losing mistakes thinking you are winning.
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: Rule of Square test position

Post by Michael Sherwin »

In reply to Bob and Richard,

I said, 'not so much so'. I did not say, 'not at all'. :P

It clearly does not pay the dividends that it used to when much slower hardware was used.

RomiChess rarely looses pure pawn race conditions and frequently wins positions pawns down due to pawn races. RomiChess has no pawn race code.

You might be amazed if you were to see the endleaf eval in RomiChess.

Code: Select all

s32 Eval()
{
  s32 score;
  s32 bonus;
  s32 sq;
  u64 pawns;

  score = PawnLook();
  if(score == NOHASH)
  {
    score = 0;
    pawns = wPawns;
    bonus = (computer == WHITE) ? 4 : 0;
    while(pawns)
    {
      sq = FirstBit(pawns);
      pawns &= clrBit[sq];
      if(openFile[Col(sq)] & (wPawns & clrBit[sq]))
        score -= (DOUBLED + bonus);
      if(!(wPassed[sq] & bPawns)) score += (PASSED - bonus);
      if(!(wIsolated[sq] & wPawns)) 
      {
        score -= (ISOLATED + bonus);
        if(!(wFrontal[sq] & bPawns)) score -= (FRONTAL + bonus);
      } 
    } 

    pawns = bPawns;
    bonus = (computer == BLACK) ? 4 : 0;
    while(pawns)
    {
      sq = LastBit(pawns);
      pawns &= clrBit[sq];
      if(openFile[Col(sq)] & (bPawns & clrBit[sq]))
        score += (DOUBLED + bonus);
      if(!(bPassed[sq] & wPawns)) score -= (PASSED - bonus);
      if(!(bIsolated[sq] & bPawns))
      { 
        score += (ISOLATED + bonus);
        if(!(bFrontal[sq] & wPawns)) score += (FRONTAL + bonus);
      } 
    }
    PawnStore(score);
  }
  score += (wEvalBonus - bEvalBonus);
  if(wBishopNum > 1) score += 32;
  if(bBishopNum > 1) score -= 32;
  score = score + wMat - bMat + wPos - bPos;
  return wtm ?  score : -score;
}
That's it. That is the whole RomiChess eval function!

wMat & bMat are computed on the fly in MakeMove().

wPos & bPos are also done on the fly in MakeMove() and come from the piece square tables that are set up at the beginning of every search.

:?:
Now a question if you will. How much elo can be added to RomiChess, just by rewritting the eval?

THANKS!
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through