Why do some programs evaluate MidGame and EndGame together?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
vittyvirus
Posts: 646
Joined: Wed Jun 18, 2014 2:30 pm
Full name: Fahad Syed

Why do some programs evaluate MidGame and EndGame together?

Post by vittyvirus »

Sorry If this is a silly question. I've rewrote my movegen yet again, and Yaka can finally can generate legal moves (By the way, last 3 digits of pseudo-legal perft 5 are 256).
I looked into Senpai and Glaurung code, and saw that they evaluate eg and mg values, no matter the phase. e.g. In case of passed pawns Senpai does: info.eg += 20; info.mg += 10; No matter what the current phase is. Has this method some advantages I've missed?
Thanks in advance.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Why do some programs evaluate MidGame and EndGame togeth

Post by Ferdy »

vittyvirus wrote:Sorry If this is a silly question. I've rewrote my movegen yet again, and Yaka can finally can generate legal moves (By the way, last 3 digits of pseudo-legal perft 5 are 256).
I looked into Senpai and Glaurung code, and saw that they evaluate eg and mg values, no matter the phase. e.g. In case of passed pawns Senpai does: info.eg += 20; info.mg += 10; No matter what the current phase is. Has this method some advantages I've missed?
Thanks in advance.
There could be some post in here, but here is a sample.
http://talkchess.com/forum/viewtopic.ph ... game+phase
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Why do some programs evaluate MidGame and EndGame togeth

Post by Sven »

vittyvirus wrote:Sorry If this is a silly question. I've rewrote my movegen yet again, and Yaka can finally can generate legal moves (By the way, last 3 digits of pseudo-legal perft 5 are 256).
I looked into Senpai and Glaurung code, and saw that they evaluate eg and mg values, no matter the phase. e.g. In case of passed pawns Senpai does: info.eg += 20; info.mg += 10; No matter what the current phase is. Has this method some advantages I've missed?
Thanks in advance.
Hi Syed,

you can find an explanation of this technique in the CPW under Tapered Eval. The final score will be found by interpolation and depends on the current game phase which is usually calculated from the current material. There are also implementations that store both "mg" and "eg" values in one variable, which is essentially the same as using two variables (or a struct, which is what I prefer personally) but can be written much shorter (like my "struct" solution as well ...).
User avatar
vittyvirus
Posts: 646
Joined: Wed Jun 18, 2014 2:30 pm
Full name: Fahad Syed

Re: Why do some programs evaluate MidGame and EndGame togeth

Post by vittyvirus »

Sven Schüle wrote:
vittyvirus wrote:Sorry If this is a silly question. I've rewrote my movegen yet again, and Yaka can finally can generate legal moves (By the way, last 3 digits of pseudo-legal perft 5 are 256).
I looked into Senpai and Glaurung code, and saw that they evaluate eg and mg values, no matter the phase. e.g. In case of passed pawns Senpai does: info.eg += 20; info.mg += 10; No matter what the current phase is. Has this method some advantages I've missed?
Thanks in advance.
Hi Syed,

you can find an explanation of this technique in the CPW under Tapered Eval. The final score will be found by interpolation and depends on the current game phase which is usually calculated from the current material. There are also implementations that store both "mg" and "eg" values in one variable, which is essentially the same as using two variables (or a struct, which is what I prefer personally) but can be written much shorter (like my "struct" solution as well ...).
Thanks.
What advantages does this give?
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Why do some programs evaluate MidGame and EndGame togeth

Post by Sven »

vittyvirus wrote:
Sven Schüle wrote:
vittyvirus wrote:Sorry If this is a silly question. I've rewrote my movegen yet again, and Yaka can finally can generate legal moves (By the way, last 3 digits of pseudo-legal perft 5 are 256).
I looked into Senpai and Glaurung code, and saw that they evaluate eg and mg values, no matter the phase. e.g. In case of passed pawns Senpai does: info.eg += 20; info.mg += 10; No matter what the current phase is. Has this method some advantages I've missed?
Thanks in advance.
Hi Syed,

you can find an explanation of this technique in the CPW under Tapered Eval. The final score will be found by interpolation and depends on the current game phase which is usually calculated from the current material. There are also implementations that store both "mg" and "eg" values in one variable, which is essentially the same as using two variables (or a struct, which is what I prefer personally) but can be written much shorter (like my "struct" solution as well ...).
Thanks.
What advantages does this give?
As written on the CPW page above: "The idea behind Tapered Eval is to remove evaluation discontinuity."

It has been found that drastical score changes caused by "switching" from middlegame to endgame scoring just by one capture is inferior to smoothly migrating the scoring weights towards "endgame scoring" step by step with each single capture.

You may argue that king safety, for instance, should be handled differently since in practical games there is typically one moment where both kings can stop to hide behind their pawns, e.g. after exchanging queens or one pair of rooks, and start to move towards the center. But testing will most probably confirm that tapered eval is superior even in this case.
User avatar
vittyvirus
Posts: 646
Joined: Wed Jun 18, 2014 2:30 pm
Full name: Fahad Syed

Re: Why do some programs evaluate MidGame and EndGame togeth

Post by vittyvirus »

Sven Schüle wrote:
vittyvirus wrote:
Sven Schüle wrote:
vittyvirus wrote:Sorry If this is a silly question. I've rewrote my movegen yet again, and Yaka can finally can generate legal moves (By the way, last 3 digits of pseudo-legal perft 5 are 256).
I looked into Senpai and Glaurung code, and saw that they evaluate eg and mg values, no matter the phase. e.g. In case of passed pawns Senpai does: info.eg += 20; info.mg += 10; No matter what the current phase is. Has this method some advantages I've missed?
Thanks in advance.
Hi Syed,

you can find an explanation of this technique in the CPW under Tapered Eval. The final score will be found by interpolation and depends on the current game phase which is usually calculated from the current material. There are also implementations that store both "mg" and "eg" values in one variable, which is essentially the same as using two variables (or a struct, which is what I prefer personally) but can be written much shorter (like my "struct" solution as well ...).
Thanks.
What advantages does this give?
As written on the CPW page above: "The idea behind Tapered Eval is to remove evaluation discontinuity."

It has been found that drastical score changes caused by "switching" from middlegame to endgame scoring just by one capture is inferior to smoothly migrating the scoring weights towards "endgame scoring" step by step with each single capture.

You may argue that king safety, for instance, should be handled differently since in practical games there is typically one moment where both kings can stop to hide behind their pawns, e.g. after exchanging queens or one pair of rooks, and start to move towards the center. But testing will most probably confirm that tapered eval is superior even in this case.
Thank you again!
User avatar
hgm
Posts: 27793
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Why do some programs evaluate MidGame and EndGame togeth

Post by hgm »

Sven Schüle wrote:You may argue that king safety, for instance, should be handled differently since in practical games there is typically one moment where both kings can stop to hide behind their pawns, e.g. after exchanging queens or one pair of rooks, and start to move towards the center. But testing will most probably confirm that tapered eval is superior even in this case.
Why would you argue such a thing? Isn't it obvious that moving the King out of its shelter is more dangerous when the opponent has two Rooks plus a Bishop, than when he just has two Rooks? Which makes it again more dangerous than when he has just a Rook and a Bishop?

You either leave the shelter or not. But you have to weigh the urgency/benefits against the danger, and the larger the danger, the more compelling (in terms of impending loss when you don't) the reason has to be for leaving it.

So I think that the explanation of abrupt score jumps is plain nonsense. The abrupt score jump performs worse because it does not reflect reality. Not because score jumps are intrinsically bad when they would reflect reality. Scores always jump abruptly when you lose material. That is why you do QS, to eliminate the associated horizon effect. And not a reason to give all pieces the same value, to get rid of those nasty discontinuitoes...
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Why do some programs evaluate MidGame and EndGame togeth

Post by bob »

hgm wrote:
Sven Schüle wrote:You may argue that king safety, for instance, should be handled differently since in practical games there is typically one moment where both kings can stop to hide behind their pawns, e.g. after exchanging queens or one pair of rooks, and start to move towards the center. But testing will most probably confirm that tapered eval is superior even in this case.
Why would you argue such a thing? Isn't it obvious that moving the King out of its shelter is more dangerous when the opponent has two Rooks plus a Bishop, than when he just has two Rooks? Which makes it again more dangerous than when he has just a Rook and a Bishop?

You either leave the shelter or not. But you have to weigh the urgency/benefits against the danger, and the larger the danger, the more compelling (in terms of impending loss when you don't) the reason has to be for leaving it.

So I think that the explanation of abrupt score jumps is plain nonsense. The abrupt score jump performs worse because it does not reflect reality. Not because score jumps are intrinsically bad when they would reflect reality. Scores always jump abruptly when you lose material. That is why you do QS, to eliminate the associated horizon effect. And not a reason to give all pieces the same value, to get rid of those nasty discontinuitoes...
There is another issue that is related. This revolves around what Berliner first called "evaluation discontinuities". If the evaluation doesn't track smoothly across all positions, but instead takes a sudden big jump or drop with a single position change, then the search can do some pretty creative stuff with that, things that are generally unintended AND undesirable. For example, you might discover that if you bring your king out too quick from a given position, you get into great tactical difficulty. Even though the evaluation jumps positive until the tactical consequences are seen. So push that off to near the horizon where you can still bring the king out, but with much less remaining depth left for the opponent to punish this..

A classic many of us have seen when using the on/off king safety term is that when you are right in the area where it jumps, you might choose to wreck your pawn structure and king safety to win a pawn, because you think you can force a queen exchange which takes you over that "hump" where the king safety suddenly is irrelevant. But once you are wrecked, you might discover that your opponent can give up a little compensation, keep queens around, and you end up in great trouble.

Granted no evaluation is completely continuous since we use integer numbers that represent discrete intervals of (say) 1/100th of a pawn, but it is far better to gradually increase things for the endgame, or reduce them in the middle game (for endgame concepts) and such.
User avatar
hgm
Posts: 27793
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Why do some programs evaluate MidGame and EndGame togeth

Post by hgm »

bob wrote:There is another issue that is related. This revolves around what Berliner first called "evaluation discontinuities". If the evaluation doesn't track smoothly across all positions, but instead takes a sudden big jump or drop with a single position change, then the search can do some pretty creative stuff with that, things that are generally unintended AND undesirable.
Well, that is called horizon effect. You push the point where 'the axe falls' out of view. It would be nice if the axe would announce its presence smoothly in advance, as you approach it.

But real life isn't always nice. If King Safety would really depend only on the presence of an opponent Queen, you can tweak it as much as you want to depend it on presence of Rooks and Bishops, but this is pretty pointless, as the disappearance of those Rooks and Bishops by no means are any indication that the Queen is soon to disappear. You would just be fooling the engine: "Your King is poorly protected, so please quickly trade as many pieces that do not threaten it, just so you can feel better"...
For example, you might discover that if you bring your king out too quick from a given position, you get into great tactical difficulty. Even though the evaluation jumps positive until the tactical consequences are seen. So push that off to near the horizon where you can still bring the king out, but with much less remaining depth left for the opponent to punish this..
This (and the following) sounds more like the well-known defect of minimax that it does not care how it reaches the intended leaf, and puts no penalty at all on it being the only leaf that doesn't mean absolute disaster, compared to having hundreds of options leading to leaves with similar scores. If it can force reaching that leaf, it takes the score of that leaf. And then you search deeper, and the score of that leaf plumets...
A classic many of us have seen when using the on/off king safety term is that when you are right in the area where it jumps, you might choose to wreck your pawn structure and king safety to win a pawn, because you think you can force a queen exchange which takes you over that "hump" where the king safety suddenly is irrelevant. But once you are wrecked, you might discover that your opponent can give up a little compensation, keep queens around, and you end up in great trouble.
You can tell exactly the same story about sacrificing a piece (rather than King safety) to gain a Pawn, because you calculated you would gain the piece back (rather than getting your King safety back through a Queen exchange). It just means your search sucks, that it takes irresponsible risks like that. It would have been more prudent to gain the Pawn without first sacrificing a piece, but minimax scoring does not reflect that.
Granted no evaluation is completely continuous since we use integer numbers that represent discrete intervals of (say) 1/100th of a pawn, but it is far better to gradually increase things for the endgame, or reduce them in the middle game (for endgame concepts) and such.
syzygy
Posts: 5563
Joined: Tue Feb 28, 2012 11:56 pm

Re: Why do some programs evaluate MidGame and EndGame togeth

Post by syzygy »

hgm wrote:It just means your search sucks, that it takes irresponsible risks like that. It would have been more prudent to gain the Pawn without first sacrificing a piece, but minimax scoring does not reflect that.
At least for chess the minimax approach works extremely well. Nothing else that has ever been released comes close. But if one day somebody comes up with something even better, then that would obviously be fantastic.