Exchange

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Exchange

Post by xr_a_y »

In Weini I used to add a term in order to
- when ahead exchange pieces
- when below exchange pawns

In Minic, I try to reproduce that using this kind of stuff

Code: Select all

    score.scoresEG[EvalScore::sc_Exchange] -= ScoreType(EvalConfig::tradeDownPiece * (matScoreW - matScoreB)/100.f * std::min(matPieceScoreW,matPieceScoreB)/100.f);
    score.scoresEG[EvalScore::sc_Exchange] += ScoreType(EvalConfig::tradeDownPawn  * (matScoreW - matScoreB)/100.f * std::min(matPawnScoreW ,matPawnScoreB )/100.f);
matScoreW - matScoreB being the whole material (including pawns) balance, so more or less who is behind, then scaled in more or less pawn value.
matPieceScore being material score from piece only
matPawnScore being material score from pawn only

Do you agree with this ?

The idea is, the more material difference there is (matScoreW - matScoreB), the more player want to exchange.

Maybe I shall add a margin like if (abs(matScoreW - matScoreB) > margin )?
User avatar
hgm
Posts: 27789
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Exchange

Post by hgm »

This tendency to trade when ahead would come automatically if the end-game piece values were larger than the opening values. Then advancing the game phase would increase the value of a given material advantage.

Like you already hint at, this trade-encouragement backfires if the advantage is not yet decisive; it would just hasten the draw without exploring the possibilities to build out the advantage to get a win. But this could be included separately, through applying a multiplier to the score which decreases towards 0 with advancing game phase whenever the end-game advantage is below a threshold. This can be adapted for use with contempt by having it act on the projected end-game advantage, which would add a contempt-dependent amount to the current end-game advantage, also decreasing with game phase.
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Exchange

Post by xr_a_y »

hgm wrote: Mon Jul 01, 2019 7:28 am This tendency to trade when ahead would come automatically if the end-game piece values were larger than the opening values. Then advancing the game phase would increase the value of a given material advantage.
Endgame piece value are smaller in Minic (except pawn value)

Code: Select all

ScoreType   Values[13]        = { -8000, -1103, -538, -393, -359, -85, 0, 85, 359, 393, 538, 1103, 8000 };
ScoreType   ValuesEG[13]      = { -8000, -1076, -518, -301, -290, -93, 0, 93, 290, 301, 518, 1076, 8000 };
but I don't understand how this should trigger exchange anyway? can you say a little more on the subject please ?
jdart
Posts: 4366
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Exchange

Post by jdart »

Generally speaking, when ahead, you want to exchange pieces but not pawns. Especially, you don't want to exchange away your last pawn, because quite a few material configurations with no pawns but more pieces are draws or drawish, notably Rook + minor vs. Rook.

You also though need to tune any such eval term. I actually used to have a trade-down bonus but it is gone now because tuning set the value to zero. I think if you have enough special-case endgame knowledge this term may be unneeded.

--Jon
User avatar
hgm
Posts: 27789
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Exchange

Post by hgm »

Well, if being a Knight ahead is +300 in opening score, and +400 in endgame score, and the game phase is defined as minors+3*Rooks+6*Queens (running from 0=Pawn ending to 32=opening), if you were a Knight ahead with all other material on the board you would have +300*31/32+400*1/32 = +303. By trading Queens this would go up to +300*19/32+400*13/32 = +341.

As to Jon's remark: as Pawns do not weigh in to the game phase, trading those would not be encouraged. Presumably there will be specific end-game code strongly discounting the score when the number of Pawns for the leading side gets really low (like 0 or 1). But it could be advantageous to already apply a modest reduction for piece advantages that in themselves are not winning when the number of Pawns decreases but still is >=2. That would encourage the losing side to try to get to the pawnless situation.

[note I added some text to my previous posting]
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Exchange

Post by xr_a_y »

hgm wrote: Mon Jul 01, 2019 7:51 am Well, if being a Knight ahead is +300 in opening score, and +400 in endgame score, and the game phase is defined as minors+3*Rooks+6*Queens (running from 0=Pawn ending to 32=opening), if you were a Knight ahead with all other material on the board you would have +300*31/32+400*1/32 = +303. By trading Queens this would go up to +300*19/32+400*13/32 = +341.

[note I added some text to my previous posting]
Ok I get it now. Thanks.

But as I don't have EG value bigger than MG ones, I cannot rely on that. I introduced some margin to the formula, and launch a test. I'll see the result tonight.
User avatar
hgm
Posts: 27789
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Exchange

Post by hgm »

But this suggests the values are wrong, and that by adding this extra term you correct that. The min(matA, matB) in your term is effectively the game phase, as when matA and matB are not approximately equal the game is decided anyway, and extra eval terms, good or bad, would have no effect on that. So you could as well have used (matA+matB)/2, which is a game-phase measure.
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Exchange

Post by xr_a_y »

hgm wrote: Mon Jul 01, 2019 8:05 am But this suggests the values are wrong, and that by adding this extra term you correct that.
This is scary. Does others engines exhibit such lower EG values ?
User avatar
hgm
Posts: 27789
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Exchange

Post by hgm »

Lower end-game piece values make little sense to me. Intuitively I would highly prefer a position with B+N vs B and several (equal) Pawns over one where there were in addition a Queen, a Rook and another Knight on each side.

One could argue that being a Knight ahead early should enable you to gain more material before you reach the B+N vs B stage, but in a position that should already be a certain win such extra material contributes nothing. With Queens and Rooks there will be a non-zero chance for a mating attack that would make you lose despite your extra Knight. When the opponent only has a single Bishop, there is no such possibility. And with B+N vs B it will probably be trivial to gobble up all remaining Pawns of the weak side without any compensation.

But no matter what the corect piece values are, one thing is clear: an extra term const * materialDifference * gamePhase is redundant, and just a needlessly complex way to alter the opening piece values (if gamePhase = totalMaterial).
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Exchange

Post by xr_a_y »

I agree with your analysis but :

1°) my recent optimization (texel tuning on quiet.edp) tries (even starting from higher EG values) disagree and converge to lower EG values (without the additional term of course), and I don't get why yet.

2°) the added term won't affect opening because the scaling factor depends on material imbalance that is small in the opening (I guess above 1 pawn we are in the crazy part of opening theory).

I must precise that PST used (from rofchade1) are almost centered so I think they are not influencing too much those EG values.