Passed Pawns (endgame)

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Passed Pawns (endgame)

Post by mcostalba »

Ralph Stoesser wrote: You seem to be somehow pissed from the other thread.
I have abolutely no intention to harm you.
Come back to earth please...
Ralph,

you don't harm me and I am already on earth.

I fail to understand why you took my comments so badly. This is not the first time. I never intended to piss off anything. Probably you are the kind of guy who wants to have always the last word and who hates to be commented.

In this case I won't comment anymore on your post. If instead, you are willing to accept constructive criticism and promise to try to control yourself and calm down avoiding annoying personal attacks then I think we can have interesting discussions (I mean interesting also for the other forum's readers).

Your choice.

Best
Marco
User avatar
Eelco de Groot
Posts: 4567
Joined: Sun Mar 12, 2006 2:40 am
Full name:   

Re: Passed Pawns (endgame)

Post by Eelco de Groot »

Ralph Stoesser wrote:@Sven
I think your approach to remove this line

Code: Select all

ebonus += Value(square_distance(theirKingSq, blockSq) * 6 * tr);
will not work in general. It would work for the special cases though. I have played 5000 very fast self play games and the default version was *far* ahead.

After many fruitless tries in that direction (I tried to replace the constant 6 with 5 or 4 and other minor tweaks), right now I try something completely other

replace this ugly special case

Code: Select all

        // Rook pawns are a special case: They are sometimes worse, and
        // sometimes better than other passed pawns. It is difficult to find
        // good rules for determining whether they are good or bad. For now,
        // we try the following: Increase the value for rook pawns if the
        // other side has no pieces apart from a knight, and decrease the
        // value if the other side has a rook or queen.
        if (square_file(s) == FILE_A || square_file(s) == FILE_H)
        {
            if (   pos.non_pawn_material&#40;Them&#41; <= KnightValueMidgame
                && pos.piece_count&#40;Them, KNIGHT&#41; <= 1&#41;
                ebonus += ebonus / 4;
            else if &#40;pos.pieces&#40;ROOK, QUEEN, Them&#41;)
                ebonus -= ebonus / 4;
        &#125;
with a new one at the same place in the code

Code: Select all

if &#40;pos.pieces&#40;ROOK, QUEEN, Them&#41; && !pos.pieces&#40;ROOK, QUEEN, Us&#41;)
     ebonus /= 4;
That somehow seems to work better in general and it's also ok for the special cases, but not yet enough test games at reasonable time control.

I just wanted to tell you. Maybe you somehow can be successfull with your approach though.

That would be very nice, because what I test right now looks *very* ugly. :lol:
The first code fragment (Case 1) is about passed pawns on the Rook file, or edge files, the second code suggestion (Case 2) seems to be just about Rook and Queen support but Ralph is not very clear about this. They are certainly both related I think, but need not be excluding each other. Especially the H-file/A-file code is very rudimentary and probably could/should be made more complex. It is just the testing that would be the major hurdle, as always.

Case 2: more rules about Queen and Rook support are in Rainbow Serpent, what Ralph seems to propose is okay. (Interpreting this as just for A- and H-pawns, then it becomes the suggestion No. 1 below.) Interpreting it as a general rule, there is already code for enemy Rook or Queen behind our passed pawn but why not add a condition that there is a bonus with own Rook and Queen support behind the passed pawn. Also because the opposite case for enemy Rook/Queen behind the pawn is already in place.

Case 1: Rainbow Serpent has very messy code for Rook-file pawns, it can give wrong answers when for instance own King support or King oppostion to enemy passed pawn is not needed, because the passed pawn is already controlled by your Queen, or by your Bishop for instance. It is just a stopgap measure to direct the King toward the edge files, from both sides, which was not in Tord's rule. I don't think this is good enough to test fully, maybe it is even wrong, maybe there are other ways of coding something like this.

Rainbow Serpent code:

Code: Select all


		if &#40;true&#41;
		&#123;
			// Rook pawns are a special case&#58; They are sometimes worse, and
			// sometimes better than other passed pawns. It is difficult to find
			// good rules for determining whether they are good or bad. For now,
			// we try the following&#58; Increase the value for rook pawns if the
			// other side has no pieces apart from a knight, and decrease the
			// value if the other side has a rook or queen.
			if &#40;square_file&#40;s&#41; == FILE_A || square_file&#40;s&#41; == FILE_H&#41;
			&#123;
				if (   pos.non_pawn_material&#40;Them&#41; <= KnightValueMidgame
                    && pos.piece_count&#40;Them, KNIGHT&#41; <= 1&#41;
					ebonus += ebonus / 4;
				else if &#40;pos.pieces&#40;ROOK, QUEEN, Them&#41;)
					ebonus -= ebonus / 4;
				if &#40;r >= 2&#41;
				&#123;
					int kingDistancebonus = tr + (&#40;pos.non_pawn_material&#40;Them&#41; <= BishopValueMidgame&#41; && !pos.opposite_colored_bishops&#40;)) * tr;
					ebonus -= Value&#40;(&#40;4 - square_distance&#40;theirKingSq, qsq&#41;) + &#40;4 - theirKingDistance&#41;)* kingDistancebonus&#41;;
				&#125;
			&#125;
		&#125;

Reading Ralph's post again, I think it is a little unclear which part of the code Ralph wants to replace, are you suggesting something like:

Code: Select all

        // Rook pawns are a special case&#58; They are sometimes worse, and
        // sometimes better than other passed pawns. It is difficult to find
        // good rules for determining whether they are good or bad. For now,
        // we try the following&#58; Increase the value for rook pawns if the
        // other side has no pieces apart from a knight, and decrease the
        // value if the other side has a rook or queen.
        if &#40;square_file&#40;s&#41; == FILE_A || square_file&#40;s&#41; == FILE_H&#41;
        &#123;
            if &#40;pos.pieces&#40;ROOK, QUEEN, Them&#41; && !pos.pieces&#40;ROOK, QUEEN, Us&#41;)
                 ebonus /= 4;
        &#125;
Or replacing just this single line

Code: Select all


				else if &#40;pos.pieces&#40;ROOK, QUEEN, Them&#41;)
					ebonus -= ebonus / 4;
So it becomes something like

Code: Select all

        // Rook pawns are a special case&#58; They are sometimes worse, and
        // sometimes better than other passed pawns. It is difficult to find
        // good rules for determining whether they are good or bad. For now,
        // we try the following&#58; Increase the value for rook pawns if the
        // other side has no pieces apart from a knight, and decrease the
        // value if the other side has a rook or queen.
        if &#40;square_file&#40;s&#41; == FILE_A || square_file&#40;s&#41; == FILE_H&#41;
        &#123;
            if (   pos.non_pawn_material&#40;Them&#41; <= KnightValueMidgame
                && pos.piece_count&#40;Them, KNIGHT&#41; <= 1&#41;
                ebonus += ebonus / 4;
            if &#40;pos.pieces&#40;ROOK, QUEEN, Them&#41; && !pos.pieces&#40;ROOK, QUEEN, Us&#41;)
                 ebonus /= 4;
        &#125;
Regards, Eelco
Debugging is twice as hard as writing the code in the first
place. Therefore, if you write the code as cleverly as possible, you
are, by definition, not smart enough to debug it.
-- Brian W. Kernighan
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: Passed Pawns (endgame)

Post by Ralph Stoesser »

Hi Eelco,

I meant the complete replacement with Tord's rook pawns special case. A patch which reduces the lines of code and add knowledge or Elo or both at the same time is always very much preferable. As a professionell software developer I often have to understand and clean-up code from other people. So I know what I'm talking about. Especially amateur programmers often tend to make their code too complex, because they think the more cases my program can handle the smarter it is. This is a fallacy. Complex code becomes very fast very difficult to manage, and whenever you are able to you should prevent it. Clean and simple is always best. This is why Sven's first approach was to simply remove a line of code.

There are several possibilities for a patch that would most likely play equal strong compared to default SF and additionally can handle those special positions. The challange is to find the most elegant and universal patch. Also it would be desirable that such a patched version would play slightly stronger Elo wise, because at least we can additionally play a seldom category of endgames better. But to approve this we probably would need some hundred thousend test games.

My condition about the heavy pieces imbalance is not that bad, but I believe it is not comprehensive enough, because the same possibly could happen with a bishop which is able to control the square in front of the passed pawn in the long term. Therefor it would be more general to solve this issue via (long term) square control considerations only. But this is a challange to get right.

Btw: My allegedly completely wrong replace patch attempt scored exactly equal with default SF after 1000 games at 1 min per game. It scored slightly weaker on a 5000 games test at 1 sec per game though. I try now to reinclude Tord's rook pawns special code and play again 1000 games @1min.
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: Passed Pawns (endgame)

Post by lech »

I found the next position which SF 171 (default options +zugzwang detection) can’t win (probably all other engines too :cry: ).
It took me a little time because I had wanted to find an extreme simple and obvious example.

[d] 8/6kP/1p6/p7/Pr6/K2B4/8/8 b - - 0 1

1...Rh4 2.Kb3 Kf6 3.Kc3 Ke5 (the rest is very easy) 4.Bg6 Kd5 5.Bf5 [5.Kd3 Rh3+ 6.Ke2 Kc4 7.Bf5 Rh6 8.Kf3 Kb3 9.Kg4 Kxa4 10.Kg5 Rxh7 -+] 5...Kc5 6.Bg6 Rh3+ 7.Bd3 Kd5 8.Kc2 Kd4 9.Bf5 Rh2+ 10.Kb3 Rh4 11.Bg6 Rh3+ 12.Kb2 Kc4 13.Bf5 Rh2+ 14.Ka3 Rh1 15.Be4 Rh3+ 16.Ka2 Kb4 17.Bc2 Rh1 18.Kb2 Rh2 19.Kb1 Ka3 20.Kc1 Ka2 21.Kd1 Kb2 22.Be4 Kb3 23.Bc2+ Kb4 24.Kc1 Kc3 25.Be4 Kb3 -+ :lol:
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: Passed Pawns (endgame)

Post by lech »

lech wrote:I found the next position which SF 171 (default options +zugzwang detection) can’t win (probably all other engines too :cry: ).
It took me a little time because I had wanted to find an extreme simple and obvious example.

[d] 8/6kP/1p6/p7/Pr6/K2B4/8/8 b - - 0 1

1...Rh4 2.Kb3 Kf6 3.Kc3 Ke5 (the rest is very easy) 4.Bg6 Kd5 5.Bf5 [5.Kd3 Rh3+ 6.Ke2 Kc4 7.Bf5 Rh6 8.Kf3 Kb3 9.Kg4 Kxa4 10.Kg5 Rxh7 -+] 5...Kc5 6.Bg6 Rh3+ 7.Bd3 Kd5 8.Kc2 Kd4 9.Bf5 Rh2+ 10.Kb3 Rh4 11.Bg6 Rh3+ 12.Kb2 Kc4 13.Bf5 Rh2+ 14.Ka3 Rh1 15.Be4 Rh3+ 16.Ka2 Kb4 17.Bc2 Rh1 18.Kb2 Rh2 19.Kb1 Ka3 20.Kc1 Ka2 21.Kd1 Kb2 22.Be4 Kb3 23.Bc2+ Kb4 24.Kc1 Kc3 25.Be4 Kb3 -+ :lol:
All mentioned above patches don’t work with my new position. Only change of value “Passed Pawns (endgame)” gives result. In my opinion, a pawn on 7(2) line is no longer the same pawn. :wink:
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: Passed Pawns (endgame)

Post by Ralph Stoesser »

lech wrote: All mentioned above patches don’t work with my new position. Only change of value “Passed Pawns (endgame)” gives result. In my opinion, a pawn on 7(2) line is no longer the same pawn. :wink:
Nothing special compared to the other examples.
Why shouldn't it work?
lech
Posts: 1136
Joined: Sun Feb 14, 2010 10:02 pm

Re: Passed Pawns (endgame)

Post by lech »

Ralph Stoesser wrote:
lech wrote: All mentioned above patches don’t work with my new position. Only change of value “Passed Pawns (endgame)” gives result. In my opinion, a pawn on 7(2) line is no longer the same pawn. :wink:
Nothing special compared to the other examples.
Why shouldn't it work?
don't work = to play moves like Kg7->h8
I think that it is a logic bug and the SF's team can do a better patch. :D
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: Passed Pawns (endgame)

Post by Ralph Stoesser »

lech wrote:
Ralph Stoesser wrote:
lech wrote: All mentioned above patches don’t work with my new position. Only change of value “Passed Pawns (endgame)” gives result. In my opinion, a pawn on 7(2) line is no longer the same pawn. :wink:
Nothing special compared to the other examples.
Why shouldn't it work?
don't work = to play moves like Kg7->h8
I think that it is a logic bug and the SF's team can do a better patch. :D
All the proposed patch attempts do work well with this position. Except the patches from SF team, because, so far, they haven't shown any. 8-)

Black king's path to e5 is easily found within a few seconds.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Passed Pawns (endgame)

Post by mcostalba »

Ralph Stoesser wrote:
All the proposed patch attempts do work well with this position. Except the patches from SF team, because, so far, they haven't shown any. 8-)
I don't have any patch to show, sorry. Actually I am not very interested in tweaking for a given position. I consider good a patch that proves to increase strength in a real games test session: I don't care how it behaves in specific positions. 8-)
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: Passed Pawns (endgame)

Post by Ralph Stoesser »

mcostalba wrote:
Ralph Stoesser wrote:
All the proposed patch attempts do work well with this position. Except the patches from SF team, because, so far, they haven't shown any. 8-)
I don't have any patch to show, sorry. Actually I am not very interested in tweaking for a given position. I consider good a patch that proves to increase strength in a real games test session: I don't care how it behaves in specific positions. 8-)
You don't have to. Only $ELO makes the world go round...
Nevertheless, from a chess player's point of view this is a very stupid behauviour from SF and possibly many other engines.