Monster move: 1...Nc3+!!

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

Moderator: Ras

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

Re: Monster move: 1...Nc3+!!

Post by Eelco de Groot »

Maybe some people would like to have a more concrete example of what codechanges I made, to achieve some better "understanding" of Albert's testposition by the program. The code is not tuned anyway, but can give an idea and is not at all complicated to make as I reused coded from other places in Stockfish and some that was in Rainbow Serpent. There already was code for passed pawns attacking the king, but only if there was a Rook or queen behind the pawn. Because the position seems to show that the rook may often need to be on an open file, I decided to change that.

There was this in the passed pawn eval already:

Code: Select all

// If the pawn is free to advance, increase bonus
if (pos.is_empty(blockSq))
{
    squaresToQueen = forward_bb(Us, s);
    defendedSquares = squaresToQueen & ei.attackedBy[Us][0];
    Value bonuspoints;
				
    // Passed pawn supported by our Rooks or Queen?								
				
    if (   (forward_bb(Them, s) & pos.pieces(Us, ROOK, QUEEN))
      && (forward_bb(Them, s) & pos.pieces(Us, ROOK, QUEEN) & pos.attacks_from<ROOK>(s)))
    {
        rookqueenSupport = true;
        if (ei.mi->game_phase() > PHASE_ENDGAME && (squaresToQueen & ei.kingRing[Them]))
            mbonus += Value(rr * (10 - indirectBlock * 4 - passed_pawnAttacked * 2 + passed_pawnDefended * 2));
        assert(passed_pawnDefended); //[always true here because of rook or queen behind] 
    }
In Stockfish the corresponding bit of code is line 896-900 in evaluate.cpp:

Code: Select all

// If the pawn is free to advance, increase bonus
if (pos.is_empty(blockSq))
{
    squaresToQueen = forward_bb(Us, s);
    defendedSquares = squaresToQueen & ei.attackedBy[Us][0];
I move the middlegame bonus for a passed pawn on its way to the king to later in the block when we have a more complete endgame bonus, and I increased the value I think, but not with much detail in the calculation, and the increase may be a bit much... It is probably less accurate this way because I take not just a (endgame passed pawn) value adjusted for the game phase (it is an mbonus) but then also multiplicate it roughly with the number of Bishops on our side (or the equivalent in heavy pieces). We do not have accurate King attack information here and those King safety values can grow exponentionally, so I hope the accuracy here is not a big issue, it is not integrated further into the King safety calculation so it does not "grow" anymore.

Code: Select all

// In the middle game, add bonuspoints if our passed pawn approaches the opponent king
if (ei.mi->game_phase() > PHASE_ENDGAME && (squaresToQueen & ei.kingRing[Them]))
    mbonus += (ebonus/8) * int(pos.non_pawn_material(Us)/BishopValueMidgame); //[was: Value(rr * (10 - indirectBlock * 4 - passed_pawnAttacked * 2 + passed_pawnDefended * 2));]

// 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,
This is just before the codeblock where the endgame bonus changes again but only if there is hardly any material left. The new calculation will also give a bonus if there is no Rook or Queen behind the passed pawn.

I don't think this first change is very important but having an extra bonus for Rooks on open files in the presence of passed pawns will help a bit more I think. I borrowed some code originally from Gary (Gary Linscott on Github) for this, from Stockfish Pawn shelter code:

Code: Select all

// Special extra evaluation for rooks
if (Piece == ROOK)
{
    // Open and half-open files
    f = file_of(s);
    if (ei.pi->file_is_half_open(Us, f))
    {
        if (ei.pi->file_is_half_open(Them, f))
        {
            score += RookOpenFileBonus;
            if (kingAttackCount > 0)
                score += RookOpenKingfileBonus;
            if (b = ei.pi->passed_pawns(Us) & (FileBB[f + 1] | FileBB[f - 1]))
            {
                Rank r = rank_of(Us == WHITE ? first_1(b) : ~last_1(b));
                score += make_score((2 + 3 * kingAttackCount) * int(r) * int(r), 4 * int(r) * int(r));
            }
        }
        else
            score += RookHalfOpenFileBonus;
    }
    else if (!blockingOurPawn && ei.pi->file_is_half_open(Them, f))
        score += RookAndPotentialCandidateBonus;
This new bonus for 'rook on open file next to passer' is both for middle game and endgame, but twice as large in the endgame unless the rook also happens to attack the king position, then the bonus is 8:4 for middlegame compared to the endgame if our rook attacks two kingarea squares, on average. The int kingAttackCount is just for the single piece (rook) we are now looking at but in case of an open file I think it will usually be larger than one. Sorry if this is all a bit too technical, but if the reader happens to be familiar with the Stockfish code I think it is easily recognizable what the code does. Hopefully not too many new bugs :)

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
gladius
Posts: 568
Joined: Tue Dec 12, 2006 10:10 am
Full name: Gary Linscott

Re: Monster move: 1...Nc3+!!

Post by gladius »

Eelco de Groot wrote: I don't think this first change is very important but having an extra bonus for Rooks on open files in the presence of passed pawns will help a bit more I think.
This sounds like a very interesting idea. I gave it a shot with a really basic implementation, and it didn't quite pan out (about -5 elo over 20k superfast games). I'm trying a small refinement now, hopefully will do a little better.

Did you get a chance to test your changes?
User avatar
Eelco de Groot
Posts: 4705
Joined: Sun Mar 12, 2006 2:40 am
Full name:   Eelco de Groot

Re: Monster move: 1...Nc3+!!

Post by Eelco de Groot »

gladius wrote:
Eelco de Groot wrote: I don't think this first change is very important but having an extra bonus for Rooks on open files in the presence of passed pawns will help a bit more I think.
This sounds like a very interesting idea. I gave it a shot with a really basic implementation, and it didn't quite pan out (about -5 elo over 20k superfast games). I'm trying a small refinement now, hopefully will do a little better.

Did you get a chance to test your changes?
Hi Gary, interesting that you wanted to test it! To be honest I have no real data about Rainbow Serpent's playing strength whatsoever... I just does not feel like it is ready for that, and I'm not really that methodical either. If it does not feel ready I see not much point in testing it numerically. I do try to get a feel of course, but that starts just with letting it run for a pretty long time on one position, in this case it was this position from Albert, so that is all the data I can give you now... 5 elo less does sound reasonably encouraging though. For one it is a King Safety change and that should be sensitive to the time control. But it is not really just a middle game issue, because I feel it is about the transition from King attack to something else if there is no mate, especially here in this feature that combines both passed pawn and KS. You can exchange the pressure here on the king castle with for instance an endgame with still a passed pawn, or the opponent has to give/exchange material to stop both the attack and the passed pawn, and this pressure may lead to a conversion of one advantage to another. It will probably also have to do with playing style, because of this link between King Safety and passed pawns, if you change the weights for both a bit, already you have a different playing style. But that does not mean we should be satisfied with losing 5 elo in very fast games, just that I think there is not enough data in that yet. I would not really feel the need for a simple as possible implementation, even though that may work best with the set of eval features you have.

Maybe it would be better to just start with checking if you can give Stockfish something like my version of RookOpenKingfileBonus, I think these things should go first, and a version of rookqueenSupport; because for one thing, both of these are simpler than the 'rook on open file next to passer' bonus. (And they should be related to it.) I am afraid I have no hard data on those two yet either, if they don't work I think they will disappear eventually, if they are really wrong it will eventually become obvious enough, but I like to know why they don't work not just the impact on elo. I know this is all a bit unorthodox thinking not to say lunacy, to think that Rainbow Serpent will ever work as intended this way, but speaking of the moon, to this day some people refuse to believe we ever were capable of moonlandings too... :)

Thanks for the interest Gary!
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
User avatar
Eelco de Groot
Posts: 4705
Joined: Sun Mar 12, 2006 2:40 am
Full name:   Eelco de Groot

Re: Monster move: 1...Nc3+!!

Post by Eelco de Groot »


922 - if (adjacent_files_bb(file_of(s)) & pos.pieces(Us, ROOK, QUEEN))
922 + if (this_and_adjacent_files_bb(file_of(s)) & in_front_bb(Them, s) & pos.pieces(Us, ROOK, QUEEN))
923 923 ebonus += Value(rr * 3);
924 924 }
925 925 } // rr != 0
This change may not work so well because if your pawn is on the 7th rank, the rook has to be pushed to the eighth rank, so in front of the pawn, for instance to give check or attack a piece that is defending back rank against the promotion. The rook may fall then, so any benefit may lie beyond the horizon. If that accurately explains the -9 elo then there must be something positive too, with a better formulation?

I will probably make an update of the public sources of "Ferrifish" soon because especially the King Safety in there is no longer in use and of course it does not have these latest changes in the passed pawn code. The present version of Rainbow Serpent is not completely up to date with the SF master because I have to add all those changes by hand! There is probably a faster way, or more than one, Marco referred to a GnuWin32 patch once but I could not get that to work. That is okay, I want to check the lines a bit and then you can better do the changes by hand if there is time. Rainbow Serpent is reasonably up to date, most of the code until the june 02 update of Stockfish Master is in it.

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
gladius
Posts: 568
Joined: Tue Dec 12, 2006 10:10 am
Full name: Gary Linscott

Re: Monster move: 1...Nc3+!!

Post by gladius »

Eelco de Groot wrote:This change may not work so well because if your pawn is on the 7th rank, the rook has to be pushed to the eighth rank, so in front of the pawn, for instance to give check or attack a piece that is defending back rank against the promotion. The rook may fall then, so any benefit may lie beyond the horizon. If that accurately explains the -9 elo then there must be something positive too, with a better formulation?
That is a good point. I'm now running a test with https://github.com/glinscott/Stockfish/ ... 39d4a212f7. It is well with error margins currently after 1200 games, sitting at 211 - 190 - 809 [+6].

The RookOpenKingFileBonus looks interesting as well, thanks. I will try that out as well after this.