Old testposition I posted revisited...

Discussion of anything and everything relating to chess playing software and machines.

Moderator: Ras

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

Re: Old testposition I posted revisited...

Post by mcostalba »

mcostalba wrote:
Eelco de Groot wrote:
Complete evaluate.cpp did not fit so just the passed pawns routine 8-)
Hi Eelco,

thanks a lot !

In the mean time I have written something myself that I am testing now, it is along your ideas but code is a bit different. If tests are good I will post the code.
Test seems positive, although still running, anyhow this is the patch to apply in case you are interested. More or less it follows your ideas, only implementation is slightly different.

Code: Select all

diff --git a/src/evaluate.cpp b/src/evaluate.cpp
index 9fd4040..c5f5835 100644
--- a/src/evaluate.cpp
+++ b/src/evaluate.cpp
@@ -933,28 +933,31 @@ namespace {
                         && (squares_behind(us, s) & pos.rooks_and_queens(them)))
                         b3 = b2;
 
-                    if ((b2 & pos.pieces_of_color(them)) == EmptyBoardBB)
+                    // Squares attacked or occupied by enemy pieces
+                    b3 |= (b2 & pos.pieces_of_color(them));
+
+                    if ((b2 & pos.pieces_of_color_and_type(them, PAWN)) == EmptyBoardBB)
                     {
-                        // There are no enemy pieces in the pawn's path! Are any of the
-                        // squares in the pawn's path attacked by the enemy?
+                        // There are no enemy pawns in the pawn's path! Are any of the
+                        // squares in the pawn's path attacked or occupied by the enemy?
                         if (b3 == EmptyBoardBB)
-                            // No enemy attacks, huge bonus!
+                            // No enemy attacks or pieces, huge bonus!
                             ebonus += Value(tr * (b2 == b4 ? 17 : 15));
                         else
-                            // OK, there are enemy attacks. Are those squares which are
-                            // attacked by the enemy also attacked by us?  If yes, big bonus
-                            // (but smaller than when there are no enemy attacks), if no,
-                            // somewhat smaller bonus.
+                            // OK, there are enemy attacks or pieces (but not pawns). Are those
+                            // squares which are attacked by the enemy also attacked by us?
+                            // If yes, big bonus (but smaller than when there are no enemy attacks),
+                            // if no, somewhat smaller bonus.
                             ebonus += Value(tr * ((b3 & b4) == b3 ? 13 : 8));
                     }
                     else
                     {
-                        // There are some enemy pieces in the pawn's path. While this is
+                        // There are some enemy pawns in the pawn's path. While this is
                         // sad, we still assign a moderate bonus if all squares in the path
                         // which are either occupied by or attacked by enemy pieces are
                         // also attacked by us.
-                        if (((b3 | (b2 & pos.pieces_of_color(them))) & ~b4) == EmptyBoardBB)
-                            ebonus += Value(tr * 6);
+                        if ((b3 & b4) == b3)
+                            ebonus += Value(tr * 5);
                     }
                     // At last, add a small bonus when there are no *friendly* pieces
                     // in the pawn's path.
User avatar
Eelco de Groot
Posts: 4669
Joined: Sun Mar 12, 2006 2:40 am
Full name:   Eelco de Groot

Re: Old testposition I posted revisited...

Post by Eelco de Groot »

mcostalba wrote:
Test seems positive, although still running, anyhow this is the patch to apply in case you are interested. More or less it follows your ideas, only implementation is slightly different.

Code: Select all

diff --git a/src/evaluate.cpp b/src/evaluate.cpp
index 9fd4040..c5f5835 100644
--- a/src/evaluate.cpp
+++ b/src/evaluate.cpp
@@ -933,28 +933,31 @@ namespace {
                         && (squares_behind(us, s) & pos.rooks_and_queens(them)))
                         b3 = b2;
 
-                    if ((b2 & pos.pieces_of_color(them)) == EmptyBoardBB)
+                    // Squares attacked or occupied by enemy pieces
+                    b3 |= (b2 & pos.pieces_of_color(them));
+
+                    if ((b2 & pos.pieces_of_color_and_type(them, PAWN)) == EmptyBoardBB)
                     {
-                        // There are no enemy pieces in the pawn's path! Are any of the
-                        // squares in the pawn's path attacked by the enemy?
+                        // There are no enemy pawns in the pawn's path! Are any of the
+                        // squares in the pawn's path attacked or occupied by the enemy?
                         if (b3 == EmptyBoardBB)
-                            // No enemy attacks, huge bonus!
+                            // No enemy attacks or pieces, huge bonus!
                             ebonus += Value(tr * (b2 == b4 ? 17 : 15));
                         else
-                            // OK, there are enemy attacks. Are those squares which are
-                            // attacked by the enemy also attacked by us?  If yes, big bonus
-                            // (but smaller than when there are no enemy attacks), if no,
-                            // somewhat smaller bonus.
+                            // OK, there are enemy attacks or pieces (but not pawns). Are those
+                            // squares which are attacked by the enemy also attacked by us?
+                            // If yes, big bonus (but smaller than when there are no enemy attacks),
+                            // if no, somewhat smaller bonus.
                             ebonus += Value(tr * ((b3 & b4) == b3 ? 13 : 8));
                     }
                     else
                     {
-                        // There are some enemy pieces in the pawn's path. While this is
+                        // There are some enemy pawns in the pawn's path. While this is
                         // sad, we still assign a moderate bonus if all squares in the path
                         // which are either occupied by or attacked by enemy pieces are
                         // also attacked by us.
-                        if (((b3 | (b2 & pos.pieces_of_color(them))) & ~b4) == EmptyBoardBB)
-                            ebonus += Value(tr * 6);
+                        if ((b3 & b4) == b3)
+                            ebonus += Value(tr * 5);
                     }
                     // At last, add a small bonus when there are no *friendly* pieces
                     // in the pawn's path.
Hi Marco,

Thanks for your example! Another interesting variation on the code. I was a bit afraid that this kind of change would be hard to test, to measure an elo-change because it only would affect games with passed pawns. But probably that is still a very large portion and all the passed pawns have to be evaluated in the whole search-tree, where the enemy will usually try to avoid your pawns becoming passed, so that fraction is probably a larger part of searchtree than just the actual gamefragments with passed pawns are of the games. So it is a very important part of eval.

I hope I follow the description of your code now in the git patch, Marco, I think that your code would have to work but, possibly, you could have made it a bit more compact while it would, as far as I can see, do the same? If i'm correct when the routine for passed pawns start you ask at the beginning

Code: Select all

        Bitboard b = ei.pi->passed_pawns() & pos.pawns(us), b2, b3, b4;

        while (b)
        {
Because bitboard b only contains our passed pawns, by definition there can be no enemy pawns on bitboard b2!

So in your code

Code: Select all

+                    if ((b2 & pos.pieces_of_color_and_type(them, PAWN)) == EmptyBoardBB) 
                     { 
is always true! If you leave out this test and run a few testpositions you should get exactly the same output in eval and nodenumbers. But it would save a test and be a bit more compact. If you don't get the same output I am wrong or there is a bug, it is possible but it would be a really bad bug :) Affecting all passed pawn code, if it would exist.

Regards, Eelco

P.S. I tried about a dozen variations on root-search again, my favourite part of search but I think they are all worse :oops: I don't understand how Vas can do so much work there and still continue to get elo out of it. I think it has to do with black box magic and the philosopher's stone! In other words I have no clue :)

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
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Old testposition I posted revisited...

Post by mcostalba »

Eelco de Groot wrote:

Code: Select all

        Bitboard b = ei.pi->passed_pawns() & pos.pawns(us), b2, b3, b4;

        while (b)
        {
Because bitboard b only contains our passed pawns, by definition there can be no enemy pawns on bitboard b2!
Actually it is b that is assigned not b2..b4. Probably I could rewrite in a better way but the above code corresponds to:

Code: Select all

        Bitboard b2, b3, b4;
        Bitboard b = ei.pi->passed_pawns() & pos.pawns(us);

        while (b)
        {
Actually if you see few lines below b2 is assigned as

Code: Select all

        b2 = squares_in_front_of(us, s);
Eelco de Groot wrote: P.S. I tried about a dozen variations on root-search again, my favourite part of search but I think they are all worse :oops: I don't understand how Vas can do so much work there and still continue to get elo out of it. I think it has to do with black box magic and the philosopher's stone! In other words I have no clue :)

Eelco
I also don't have clue :-) but I think devil is in the details. I have seen that the improvments we got from orginal Glaurung code base were nothing earth shattering, just many small, even very small little tweaks that at the end make a difference.

P.S: The fact that the changes are small it does not mean they are easy to find. Actually they are very difficult to spot, at least for me.
User avatar
Eelco de Groot
Posts: 4669
Joined: Sun Mar 12, 2006 2:40 am
Full name:   Eelco de Groot

Re: Old testposition I posted revisited...

Post by Eelco de Groot »

mcostalba wrote:
Eelco de Groot wrote:

Code: Select all

        Bitboard b = ei.pi->passed_pawns() & pos.pawns(us), b2, b3, b4;

        while (b)
        {
Because bitboard b only contains our passed pawns, by definition there can be no enemy pawns on bitboard b2!
Actually it is b that is assigned not b2..b4. Probably I could rewrite in a better way but the above code corresponds to:

Code: Select all

        Bitboard b2, b3, b4;
        Bitboard b = ei.pi->passed_pawns() & pos.pawns(us);

        while (b)
        {
Hello Marco,

I thought I understood that, the two ways are equivalent, they should do exactly the same thing?
Actually if you see few lines below b2 is assigned as

Code: Select all

        b2 = squares_in_front_of(us, s);
Maybe it is just that I don't understand some basic C, but what I meant was that we are looking at passed pawns (in Bitboard b) and by definition (the definition of a passed pawn) passed pawns can't have enemy pawns in front of them!
Eelco de Groot wrote: P.S. I tried about a dozen variations on root-search again, my favourite part of search but I think they are all worse :oops: I don't understand how Vas can do so much work there and still continue to get elo out of it. I think it has to do with black box magic and the philosopher's stone! In other words I have no clue :)

Eelco
I also don't have clue :-) but I think devil is in the details. I have seen that the improvments we got from orginal Glaurung code base were nothing earth shattering, just many small, even very small little tweaks that at the end make a difference.

P.S: The fact that the changes are small it does not mean they are easy to find. Actually they are very difficult to spot, at least for me.
It could be that, just small things adding up. But I still think we are missing a key part of the puzzle here! And I don't think it is in the old Strelka code if there were clues in Rybka 1.0 Beta already, or maybe it is, and nobody found it :shock:

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
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Old testposition I posted revisited...

Post by mcostalba »

Yes Eelco,

you are right ! Sorry I have misunderstood. This is the modified and equivalent patch:

Code: Select all

diff --git a/src/evaluate.cpp b/src/evaluate.cpp
index 9fd4040..372313b 100644
--- a/src/evaluate.cpp
+++ b/src/evaluate.cpp
@@ -933,29 +933,23 @@ namespace {
                         && (squares_behind(us, s) & pos.rooks_and_queens(them)))
                         b3 = b2;
 
-                    if ((b2 & pos.pieces_of_color(them)) == EmptyBoardBB)
-                    {
-                        // There are no enemy pieces in the pawn's path! Are any of the
-                        // squares in the pawn's path attacked by the enemy?
-                        if (b3 == EmptyBoardBB)
-                            // No enemy attacks, huge bonus!
-                            ebonus += Value(tr * (b2 == b4 ? 17 : 15));
-                        else
-                            // OK, there are enemy attacks. Are those squares which are
-                            // attacked by the enemy also attacked by us?  If yes, big bonus
-                            // (but smaller than when there are no enemy attacks), if no,
-                            // somewhat smaller bonus.
-                            ebonus += Value(tr * ((b3 & b4) == b3 ? 13 : 8));
-                    }
+                    // Squares attacked or occupied by enemy pieces
+                    b3 |= (b2 & pos.pieces_of_color(them));
+
+                    // There are no enemy pawns in the pawn's path
+                    assert((b2 & pos.pieces_of_color_and_type(them, PAWN)) == EmptyBoardBB);
+
+                    // Are any of the squares in the pawn's path attacked or occupied by the enemy?
+                    if (b3 == EmptyBoardBB)
+                        // No enemy attacks or pieces, huge bonus!
+                        ebonus += Value(tr * (b2 == b4 ? 17 : 15));
                     else
-                    {
-                        // There are some enemy pieces in the pawn's path. While this is
-                        // sad, we still assign a moderate bonus if all squares in the path
-                        // which are either occupied by or attacked by enemy pieces are
-                        // also attacked by us.
-                        if (((b3 | (b2 & pos.pieces_of_color(them))) & ~b4) == EmptyBoardBB)
-                            ebonus += Value(tr * 6);
-                    }
+                        // OK, there are enemy attacks or pieces (but not pawns). Are those
+                        // squares which are attacked by the enemy also attacked by us?
+                        // If yes, big bonus (but smaller than when there are no enemy attacks),
+                        // if no, somewhat smaller bonus.
+                        ebonus += Value(tr * ((b3 & b4) == b3 ? 13 : 8));
+
                     // At last, add a small bonus when there are no *friendly* pieces
                     // in the pawn's path.
                     if ((b2 & pos.pieces_of_color(us)) == EmptyBoardBB)

Thanks again for pointing out this.
Marco