Stockfish - material balance/imbalance evaluation

Discussion of chess software programming and technical issues.

Moderator: Ras

Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: Stockfish - material balance/imbalance evaluation

Post by Ralph Stoesser »

mcostalba wrote:
So we need to retune all !

Thanks, yes, this is a case where we will need to use autmatic tuning ;-)
Before you start your major retuning session, maybe you want to consider to include also pawn attacks to the thread table.

With pawn attacks included SF seems to play slightly better at lightning fast 1 sec games on my test machine (core duo notebook). But more testing is needed. Also it could be a coincidence because of the false auto-tuned paramters. ;)

Btw: After applying the fix I have seen SF consider the main ruy lopez
1.e4 e5 2.Nf3 Nc6 3.Bb5 a6 4.Ba4(!!) :D
first time ever.
User avatar
Eelco de Groot
Posts: 4655
Joined: Sun Mar 12, 2006 2:40 am
Full name:   Eelco de Groot

Re: Stockfish - material balance/imbalance evaluation

Post by Eelco de Groot »

mcostalba wrote:
Ralph Stoesser wrote: @Marco, at least your hidden automatic tuning machine cannot fix bugs, but we humans can. ;)
evaluate.cpp, line 145
Wow ! This is a bug, but to properly fix we need to retune all !

If we rewrite the labes as should be:

Code: Select all

  const Score ThreatBonus[8][8] = {
      { Z, Z, Z, Z, Z, Z, Z, Z },
      { Z, S(18,37),       Z, S(37,47), S(55,97), S(55,97), Z, Z }, // not used
      { Z, S(18,37), S(37,47),       Z, S(55,97), S(55,97), Z, Z }, // KNIGHT attacks
      { Z, S( 9,27), S(27,47), S(27,47),       Z, S(37,47), Z, Z }, // BISHOP attacks
      { Z, S(27,37), S(27,37), S(27,37), S(27,37),       Z, Z, Z }, // ROOK attacks
      { Z, Z, Z, Z, Z, Z, Z, Z }, // QUEEN attacks
      { Z, Z, Z, Z, Z, Z, Z, Z }, // not used
      { Z, Z, Z, Z, Z, Z, Z, Z }  // not used
  };
we see that evaluation for the queen is completely missing ! and that also evaluation for a KNIGHT attacking a BISHOP, for a BISHOP attacking a ROOK and a ROOK attacking a QUEEN are all missing.

So we need to retune all !

Thanks, yes, this is a case where we will need to use autmatic tuning ;-)
Is this labeling correct?

Code: Select all

  const Score ThreatBonus[8][8] = {
      { Z, Z, Z, Z, Z, Z, Z, Z }, // BISHOP PAIR attacks
      { Z, S(18,37),       Z, S(37,47), S(55,97), S(55,97), Z, Z }, // PAWN
attacks
      { Z, S(18,37), S(37,47),       Z, S(55,97), S(55,97), Z, Z }, // KNIGHT attacks
      { Z, S( 9,27), S(27,47), S(27,47),       Z, S(37,47), Z, Z }, // BISHOP attacks
      { Z, S(27,37), S(27,37), S(27,37), S(27,37),       Z, Z, Z }, // ROOK attacks
      { Z, Z, Z, Z, Z, Z, Z, Z }, // QUEEN attacks
      { Z, Z, Z, Z, Z, Z, Z, Z }, // KING attacks
      { Z, Z, Z, Z, Z, Z, Z, Z }  // not used
  };
I find it still very strange that the table still works with Knight-Knight attacks, Bishop-Bishop coefficients that are not zero and others that should be zero. I have not tried the new version yet. The coefficients are small but still strange that it could be tuned at all... I had been looking at those Z,Z,Z tables but assumed somehow that the Bishop pair was not included in the table :oops: Rainbow Serpent by the way has KING attacks but if this interpretation is correct it was actually QUEEN attacks :oops: :oops: ? If so I can say that QUEEN attacks should work :) Don't know about King attacks now... If this only explains why Tord Marco And Joona coud not find more elos in the table, that is not so surprising anymore then :idea: Thanks to Ralph! One more bug find like this and Stockfish can overtake Rybka 4 when she comes out :D

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: Stockfish - material balance/imbalance evaluation

Post by Ralph Stoesser »

Eelco de Groot wrote:One more bug find like this and Stockfish can overtake Rybka 4 when she comes out :D

Eelco
Yeah, but let's wait until their parameter tuning regarding this bug has finished first ... (joke ;))

BTW, "BISHOP PAIR attacks" would be not the right labeling because ei.attackedBy[color][0] contains all squares attacked by color, regardless of piece type. Therefor ThreatBonus[0] would refer to attacks from all pieces. Better to leave it by "not used".
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: Stockfish - material balance/imbalance evaluation

Post by Ralph Stoesser »

Ralph Stoesser wrote: Before you start your major retuning session, maybe you want to consider to include also pawn attacks to the thread table.
I just have discovered that this is already computed in evaluate_pieces() as a penalty per piece instead of a bonus. My fault, sorry.
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: Stockfish - material balance/imbalance evaluation

Post by Ralph Stoesser »

I'm in bug hunting mood now, so I have a question.

Below we find the calculation of the attacked squares per piece. According to the comment we also find x-ray attacks for bishops and rooks. But the queen attacks is calculated the same way as the attacks for knights. Why?

evaluate.cpp, line 547

Code: Select all


        // Find attacked squares, including x-ray attacks for bishops and rooks
        if (Piece == KNIGHT || Piece == QUEEN)
            b = pos.attacks_from<Piece>(s);
        else if (Piece == BISHOP)
            b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(QUEEN, Us));
        else if (Piece == ROOK)
            b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, Us));
        else
            assert(false);
I would expect something like this instead. The queen is also able to x-ray attack, and there is also a blocking condition for the queen.

Code: Select all

         // Find attacked squares, including x-ray attacks for queens, bishops and rooks
        if (Piece == KNIGHT)
            b = pos.attacks_from<KNIGHT>(s);
        else if (Piece == QUEEN)
        	b = queen_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, BISHOP, Us));
        else if (Piece == BISHOP)
            b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(QUEEN, Us));
        else if (Piece == ROOK)
            b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, Us));
        else
            assert(false);
What I'm missing here?
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Stockfish - material balance/imbalance evaluation

Post by mcostalba »

Ralph Stoesser wrote: What I'm missing here?
Nothing in particular ;-)

It is not neccesarly a bug, it was always like that down to Glaurung times....anyhow I second that could be an interesting tweak to try.

Do you want to try it yourself ? Or do you prefer I put this in my test queue ?

Thanks anyhow for reporting.
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: Stockfish - material balance/imbalance evaluation

Post by Ralph Stoesser »

mcostalba wrote:
Ralph Stoesser wrote: What I'm missing here?
Nothing in particular ;-)

It is not neccesarly a bug, it was always like that down to Glaurung times....anyhow I second that could be an interesting tweak to try.

Do you want to try it yourself ? Or do you prefer I put this in my test queue ?

Thanks anyhow for reporting.
It's currently difficult to test. SF 1.7.1 does not evaluate queen threats because of the TheatBonus table error. On the other hand if I apply the TheatBonus patch, SF seems to play slightly weaker because of the erroneous tuned eval parameters.

When do you plan to re-tune the eval paramters? How long will it take?
Maybe it's a good idea to wait a bit.

In another thread Sven suggested a tweak regarding the passed pawn evaluation. From a first look at the problem I would say he could be right. http://talkchess.com/forum/viewtopic.ph ... 399#347399 But I think this issue would be rather independent from automatic eval tuning.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Stockfish - material balance/imbalance evaluation

Post by mcostalba »

Ralph Stoesser wrote: It's currently difficult to test. SF 1.7.1 does not evaluate queen threats because of the TheatBonus table error. On the other hand if I apply the TheatBonus patch, SF seems to play slightly weaker because of the erroneous tuned eval parameters.
:?: :?:

I fail to see a link between testing this tweak and the bug in TheatBonus table. Anyhow, don't worry, I'll do it. :-)

Ralph Stoesser wrote: When do you plan to re-tune the eval paramters? How long will it take?
Maybe it's a good idea to wait a bit.


You will have to wait many months because will be published in the next release...and again, I fail to see how a bug can halt all the test process ongoing on SF. This bug is many months old, it was introduced even before 1.6 was released and neverthless we have now 1.7.1 so I really don't get your point here.
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: Stockfish - material balance/imbalance evaluation

Post by Ralph Stoesser »

This patch would add x-ray attacks to the queen attacks.
But since evaluate_threats() does not evaluate queen threats, because of the bug,
it would not make any difference whether I include x-ray attacks for queens or not, evaluate_threats() still would not "see" it. That's what I meant.

Besides evaluate_threats(), queen attacks are especially important in king safety eval.
I would first double check whether it would hurt in king safety to have included x-ray attacks for the queen attacks. Especially the "safe queen contact checks" part seems to be very critical. I will take a look at it tomorrow evening.

It's bed time now. Thanks for anwering. Good night. ;)
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Stockfish - material balance/imbalance evaluation

Post by mcostalba »

Ralph Stoesser wrote: it would not make any difference whether I include x-ray attacks for queens or not, evaluate_threats() still would not "see" it. That's what I meant.
No, x-ray attacks for queens are used to evaluate mobility not threats.
Ralph Stoesser wrote: Besides evaluate_threats(), queen attacks are especially important in king safety eval.
I would first double check whether it would hurt in king safety to have included x-ray attacks for the queen attacks. Especially the "safe queen contact checks" part seems to be very critical. I will take a look at it tomorrow evening.

It's bed time now. Thanks for anwering. Good night. ;)
I am curious how you "double check" without testing the tweak and verify with real games if it hurts ot not :?:

....anyhow good night.