IS there a simple way to recognize draw involving a single pawn that is can be captured leaving an insufficient material configuration ?
This is an example from yesterday's tournament :
[pgn]
[Event "Computer chess game"]
[Site "winboard.nl"]
[Date "2017.06.17"]
[Round "?"]
[White "ArasanX"]
[Black "Singularity"]
[Result "1/2-1/2"]
[SetUp "1"]
[FEN "rnbqkbnr/ppp1pppp/8/3p4/2PP4/8/PP2PPPP/RNBQKBNR b KQkq - 0 2"]
[WhiteElo "2061"]
[BlackElo "2000"]
[ECO "E08"]
[Opening "Catalan"]
[Time "22:39:34"]
[Variation "Closed, 7.Qc2 c6 8.Bf4 b6"]
[TimeControl "300+1"]
[Termination "normal"]
[PlyCount "317"]
[Whitetype "program"]
[Blacktype "human"]
[CurrentPosition "8/7K/5k2/5P2/8/4b3/8/8 w - - 101 161"]
2...e6 3.Nf3 Nf6 { D30: Queen's Gambit Declined: 3.Nf3 Nf6 } 4.g3 Bb4+ 5.Bd2 Be7 6.Bg2 O-O 7.O-O Nbd7 8.Qc2 c6 9.Bf4 b6 10.Rd1 Bb7 11.Ne5 Nh5 12.Bd2 Nhf6 13.cxd5 cxd5 14.Nc6 Bxc6 15.Qxc6 a6 16.Rc1 Rc8 17.Qxc8 Qxc8 18.Rxc8 Rxc8 19.Nc3 b5 20.Rc1 Nb6 21.Nd1 Ne4 22.Rxc8+ Nxc8 23.Be1 Ned6 24.e3 Na7 25.b3 Nc6 26.Nb2 a5 27.Bf1 b4 28.h3 g6 29.Na4 h5 30.Nc5 Kg7 31.f4 h4 32.gxh4 Nf5 33.Bf2 Nxh4 34.Bd3 Nf5 35.Kg2 Nd6 36.Kf3 Nb8 37.Ke2 Kf8 38.Be1 Ke8 39.Bc2 Nc6 40.Nd3 Kd8 41.Ne5 Kc7 42.Kf3 Kb6 43.Bd3 Kc7 44.Bd2 Bh4 45.Bc1 Kb6 46.Nd7+ Kc7 47.Nc5 Nf5 48.a3 Be7 49.Bxf5 exf5 50.axb4 Nxb4 51.Na4 Bd6 52.Ba3 Kc6 53.Ke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ke3 Bc1+ 141.Kf3 Bh6 142.Ke4 Bd2 143.Kd5 Be1 144.Kd6 Bf2 145.Kc6 Bg1 146.Kb5 Be3 147.Ka6 Bd4 148.Kb7 Bg1 149.Kc8 Be3 150.Kc7 Bf4+ 151.Kb6 Bd6 152.Kc6 Bh2 153.Kb5 Bg1 154.Kc6 Bf2 155.Kc7 Be3 156.Kd7 Bd4 157.Ke8 Bc3 158.Kf8 Ba1 159.Kg8 Bd4 160.Kh7 Be3 1/2-1/2
[/pgn]
my engines doesn't want to capture the pawn to maintain a 3+ score
how to recognize draws with a pawn ?
Moderator: Ras
-
hgm
- Posts: 28475
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: how to recognize draws with a pawn ?
The problem is the +3 score, which should have been a (close to) 0 score. Making it capture the Pawn would not gain any Elo, as the position is a draw and remains a draw. What could increase Elo is to prevent the engine would convert to KBKP from a won position with score +2 (e.g. KBPPKB) because it thinks it raises its score to +3.
Most engines keep a 'material key' that uniquely identifies what material is on the board, and use it as an index in a material table (exhaustively precalculated or hashed after calculation 'on the fly'). This table can then indicate whether the position needs special evaluation treatment, and if so, what.
Possible special treatments could be:
* Adding a correction to the normal evaluation. (The Bishop-pair bonus could be handled this way.)
* Multiplying the normal evaluation score with a certain factor between 0 and 1 to indicate drawishness.
* Invoke a dedicated evaluation routine instead of the normal one (e.g. for KBPK, to test if it is an edge Pawn and Bishop of the wrong color).
The problem you perceive can be solved by the drawishness factor. End-games get drawish when the side that is ahead has no mating potential; the factor for KBK of course should be 0, as it is an immediate draw, but KBKP and KBKPP would deserve a factor pretty close to 0 as well. (Better not exactly 0, though, because then the side with the Pawn would stop trying.) In particular, end-games where the leading side has no Pawns, or just a single Pawn that is in jeopardy of being sacrificed away, should get the score discounted. Another drawish case, even with many Pawns is unlike Bishops. If the material key considers light and dark Bishops different pieces it can also distinguish those.
End-games like KBPKN are already drawish (but not as drawish as KBK, so they would not need a factor that close to 0, perhaps 0.25), because the single Pawn can be sacrificed away for the Knight, leaving KBK. So in preparing the material table you should award very small factors to end-games without mating potential (which implies no Pawns), and somewhat larger factors to Pawnless material without winning advantage (in general a minor or less ahead, such as KRBKR, KRBKRP, KRBKRPP, ...). But you should also give a significant discount (like 0.25) to combinations where the opponent can reach such a combination by sacrificing his weakest piece for a single Pawn (so KRBPKRN). Without a Pawn you need about twice as big a material advantage to win (KQKR is barely won), so even in that case a factor 0.5 would be deserved.
Most engines keep a 'material key' that uniquely identifies what material is on the board, and use it as an index in a material table (exhaustively precalculated or hashed after calculation 'on the fly'). This table can then indicate whether the position needs special evaluation treatment, and if so, what.
Possible special treatments could be:
* Adding a correction to the normal evaluation. (The Bishop-pair bonus could be handled this way.)
* Multiplying the normal evaluation score with a certain factor between 0 and 1 to indicate drawishness.
* Invoke a dedicated evaluation routine instead of the normal one (e.g. for KBPK, to test if it is an edge Pawn and Bishop of the wrong color).
The problem you perceive can be solved by the drawishness factor. End-games get drawish when the side that is ahead has no mating potential; the factor for KBK of course should be 0, as it is an immediate draw, but KBKP and KBKPP would deserve a factor pretty close to 0 as well. (Better not exactly 0, though, because then the side with the Pawn would stop trying.) In particular, end-games where the leading side has no Pawns, or just a single Pawn that is in jeopardy of being sacrificed away, should get the score discounted. Another drawish case, even with many Pawns is unlike Bishops. If the material key considers light and dark Bishops different pieces it can also distinguish those.
End-games like KBPKN are already drawish (but not as drawish as KBK, so they would not need a factor that close to 0, perhaps 0.25), because the single Pawn can be sacrificed away for the Knight, leaving KBK. So in preparing the material table you should award very small factors to end-games without mating potential (which implies no Pawns), and somewhat larger factors to Pawnless material without winning advantage (in general a minor or less ahead, such as KRBKR, KRBKRP, KRBKRPP, ...). But you should also give a significant discount (like 0.25) to combinations where the opponent can reach such a combination by sacrificing his weakest piece for a single Pawn (so KRBPKRN). Without a Pawn you need about twice as big a material advantage to win (KQKR is barely won), so even in that case a factor 0.5 would be deserved.
-
Joerg Oster
- Posts: 992
- Joined: Fri Mar 10, 2006 4:29 pm
- Location: Germany
- Full name: Jörg Oster
Re: how to recognize draws with a pawn ?
KQKR is almost always a win!
It may be difficult for humans to convert, but not for engines.
Typical exception is where the rook can sacrifice itself leaving the bare king stalemated.
[d]2k5/1r6/2KQ4/8/8/8/8/8 b - - 0 1
It may be difficult for humans to convert, but not for engines.
Typical exception is where the rook can sacrifice itself leaving the bare king stalemated.
[d]2k5/1r6/2KQ4/8/8/8/8/8 b - - 0 1
Jörg Oster
-
hgm
- Posts: 28475
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: how to recognize draws with a pawn ?
Sure. That is what 'barely won' means: won, but very close to not being won. And this for a material advantage > 4. A piece that is just a little bit weaker than a Queen in terms of value would not be able to beat a Rook. Chancellor vs Rook is a fortress draw if the Rook can cut off the opponent King from approaching its own, and Archbishop vs Rook is a general draw. All these pieces are at least 350cP stronger than a Rook, an advantage that would be totally winning in the presence of Pawns (where the draw margin is ~150 cP).
In KQKR there are also some exceptions where you cannot escape checking without getting skewered:
[d]8/2Q5/8/8/8/1K6/r7/1k6 w
In KQKR there are also some exceptions where you cannot escape checking without getting skewered:
[d]8/2Q5/8/8/8/1K6/r7/1k6 w
-
Joerg Oster
- Posts: 992
- Joined: Fri Mar 10, 2006 4:29 pm
- Location: Germany
- Full name: Jörg Oster
Re: how to recognize draws with a pawn ?
Sorry, then this was a misunderstanding from my side.
I thought 'barely' won means almost never won.
I thought 'barely' won means almost never won.
Jörg Oster
-
hgm
- Posts: 28475
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: how to recognize draws with a pawn ?
That would be 'hardly won', I think.
In any case, there is ample reason to divide the normal evaluation score in KQKR by 2, for comparing it to more complex positions with Pawns. Converting KRPPPKR to KQKR is probably not a good idea. Unless you have an EGT for KQKR, of course, but then you would already have a mate score.
In Pair-o-Max, a derivative of Fairy-Max that pays attention to material composition in its eval (awarding pair bonuses, and recognizing drawishness) I had to make an exception for end-games against bare King: when I discounted KRK for having no Pawns, I got some pathological behavior, where it refused to convert to it from more difficultly won positions (like KRPKB). So the idea is that "theoretically won" against a bare King is always "easily won". Pawnless wins can only be difficult if there is defensive material, as you can no longer force your opponent to sacrifice the latter for a Pawn.
The calculated shift is then used in Search() as
The 'mating minor' and 'tough defender' cases do not occur in orthodox Chess, and the "single color-bound piece" is already covered by the "just a minor ahead" rule there. The "deficcient pair" applies to the Knight, however.
In any case, there is ample reason to divide the normal evaluation score in KQKR by 2, for comparing it to more complex positions with Pawns. Converting KRPPPKR to KQKR is probably not a good idea. Unless you have an EGT for KQKR, of course, but then you would already have a mate score.
In Pair-o-Max, a derivative of Fairy-Max that pays attention to material composition in its eval (awarding pair bonuses, and recognizing drawishness) I had to make an exception for end-games against bare King: when I discounted KRK for having no Pawns, I got some pathological behavior, where it refused to convert to it from more difficultly won positions (like KRPKB). So the idea is that "theoretically won" against a bare King is always "easily won". Pawnless wins can only be difficult if there is defensive material, as you can no longer force your opponent to sacrifice the latter for a Pawn.
Code: Select all
int
DiscountShift (int strongSide)
{
int pieceEval, myPieces, hisPieces, defenders, type, h;
int myPawns = pieceCount[strongSide][PAWN];
int weakSide = OPPONENT(strongSide);
int matingMinors = 0;
int discount = 0;
if(myPawns < 2) { // never discount with more than one Pawn
discount = 1 - myPawns; // 1 without Pawns, 0 otherwise
myPieces = pieceCount[strongSide][ALL] - myPawns; // includes King
if(myPieces < 4) { // we have at most two pieces next to King
hisPieces = pieceCount[weakSide][ALL] - pieceCount[weakSide][PAWN]; // includes King
if(hisPieces < 2) discount = 0; // do not discount against bare King
defenders = hisPieces - myPawns; // defenders left after he sacs one for my Pawn
if(defenders < 3 && defenders-- > 0) { // 0 or 1 defenders (now without counting King)
for(type=PAWN+1; pieceCount[weakSide][type] == 0; type++) ; // find piece type of weakest defender
pieceEval = abs(pieceValue[type--])*myPawns; // cost to remove my Pawn
while(hisPieces > 1) hisPieces -= pieceCount[weakSide][++type], // calculate total value of remaining defenders (negated)
pieceEval -= pieceCount[weakSide][type]*pieceValue[type];
if(!hisPieces) pieceEval += 3*pieceValue[type]; // overshoot only possible with two royal defenders; add King values
defenders &= (pairBonus[type] == -1); // this flags a 'tough defender' (like non-royal King)
for(type=PAWN+1,h=myPieces; h>1; h-=pieceCount[strongSide][type++]) // loop over non-Pawns (supposed to be ordered by increasing value)
pieceEval += pieceCount[strongSide][type]*pieceValue[type], // add own piece values to eval
matingMinors |= pieceCount[strongSide][type] & pairBonus[type]; // and detect presence of attackers listed as 'mating minors'
if(!matingMinors && eval < 350 // just a (non-mating) minor ahead (or less)
|| myPieces - 1 & (pairBonus[--type] > 3 | defenders) // or a single piece which is color bound or faces tough defender
|| pieceCount[strongSide][type] == 2 & pairBonus[type] < -1) // or a pair of pieces listed as 'defective pair'
discount = 3 - myPawns;
}
}
}
return discount;
}
Code: Select all
currentEval >>= DiscountShift(currentEval > 0 ? stm : OPPONENT(stm));
-
Evert
- Posts: 2929
- Joined: Sat Jan 22, 2011 12:42 am
- Location: NL
Re: how to recognize draws with a pawn ?
I usually keep track of whether each side has a material combination that would allow it to win. If it doesn't but is nominally ahead in material, the material evaluation is set to 0.
-
hgm
- Posts: 28475
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: how to recognize draws with a pawn ?
Such hard clipping has a disadvantage when the engine plays the side that is nominally behind. E.g. in KBKPP the Pawns can still win, and even if you trust the naive eval enough to have a positive score in all positions where they have a win against optimal defense, you also care how the engine performs against sub-optimal defense. If all KBKPP positions are scored 0, the Pawn side is degraded to a random mover, and will very quickly sacrifice both his Pawns, even against a bungling idiot that would have allowed you to reach a position that is a forced win.
So you would want to have at least some small fraction of the normal evaluation contribute. To prevent this makes the corrected evaluation for the Bishop side ever gets positive, you could add an extra penalty.
But considering that the draw margin is over 100 cP, I really doubt that it will do much harm that the score in KBKP can be, say, +50 cP in favor of the Bishop. The only consequence is that it would be preferred over positions with scores between 0 and +50cP, and all of those would almost certainly be dead draws too.
Also note that the "no winning material" condition is just a part of the picture. In KRNKR the R+N have a lot of potential, but against R they are hardly better off than KNK. It is also quite important to recognize the "last Pawn in jeopardy" cases. Otherwise the engine would happily convert from KNPPKBP to KNPKB, to find itself trapped there because it cannot advance the Pawn without the Bishop sacrificing itself for it.
So you would want to have at least some small fraction of the normal evaluation contribute. To prevent this makes the corrected evaluation for the Bishop side ever gets positive, you could add an extra penalty.
But considering that the draw margin is over 100 cP, I really doubt that it will do much harm that the score in KBKP can be, say, +50 cP in favor of the Bishop. The only consequence is that it would be preferred over positions with scores between 0 and +50cP, and all of those would almost certainly be dead draws too.
Also note that the "no winning material" condition is just a part of the picture. In KRNKR the R+N have a lot of potential, but against R they are hardly better off than KNK. It is also quite important to recognize the "last Pawn in jeopardy" cases. Otherwise the engine would happily convert from KNPPKBP to KNPKB, to find itself trapped there because it cannot advance the Pawn without the Bishop sacrificing itself for it.
-
Evert
- Posts: 2929
- Joined: Sat Jan 22, 2011 12:42 am
- Location: NL
Re: how to recognize draws with a pawn ?
Note that I don't set the evaluation to 0, just the material component.hgm wrote:Such hard clipping has a disadvantage when the engine plays the side that is nominally behind. E.g. in KBKPP the Pawns can still win, and even if you trust the naive eval enough to have a positive score in all positions where they have a win against optimal defense, you also care how the engine performs against sub-optimal defense. If all KBKPP positions are scored 0, the Pawn side is degraded to a random mover, and will very quickly sacrifice both his Pawns, even against a bungling idiot that would have allowed you to reach a position that is a forced win.
So you would want to have at least some small fraction of the normal evaluation contribute. To prevent this makes the corrected evaluation for the Bishop side ever gets positive, you could add an extra penalty.
Yes, I have special-case code for pawnless endings and endings with only a single pawn remaining. I treat those similarly by tweaking the material part of the evaluation.Also note that the "no winning material" condition is just a part of the picture. In KRNKR the R+N have a lot of potential, but against R they are hardly better off than KNK. It is also quite important to recognize the "last Pawn in jeopardy" cases. Otherwise the engine would happily convert from KNPPKBP to KNPKB, to find itself trapped there because it cannot advance the Pawn without the Bishop sacrificing itself for it.
If you use a material table, all of the logic could go in there, of course.
-
hgm
- Posts: 28475
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: how to recognize draws with a pawn ?
Well, giving away Pawns concerns material. How would the Pawn side see that KBK is worse than KBKP is worse than KBKPP if material is set to 0?Evert wrote:Note that I don't set the evaluation to 0, just the material component.