Is correct this reasoning?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Luis Babboni
Posts: 464
Joined: Sat Feb 28, 2015 4:37 pm
Location: Argentina

Is correct this reasoning?

Post by Luis Babboni »

I hope my poor english and my poor programming skills will be not enough to scare away from this question all people here! :oops:

Soberango had a problem about wich I asking here before: if sees mate in 4 before see mate in 2, cause alpha beta, choice move for mate in 4 because the result is the same.
It was suggested that it must evaluate better mate in 2 than in 4 to solve it.
OK, I did it for 0.06.0 version I´m working in, was very easy to implement and works fine.

The point is that actually I think I wrongly thought this problem was of the same kind that this:
Sometimes being able to capture a piece right now, postponed it for following moves not seeing, cause "horizon effect", that opponent will could save this piece if it was not captured right now.
But actually I could not easy see how to do it using some similar way I used to the case of mate said upon. The problem is that in mate cases, there are no further moves after that so evaluation is made at the moment of the mate. But here, there exists moves beyond the possible capture and then when the evaluation is made, is the same for actual position when was the piece captured.

Well, first I thought in adding some pararell kind of score that track when pieces was captured.... but being the objetive of 0.07.0 version the adding of iterative deepening, actually I think this (iterative deepening) will solve this problem, so I do not need to add any "pararel" evaluation or anything as messy!

Then my question is first if I understand correctly what iterative deepening is and second if it is correct my reasoning about that this solve my previous problem.

1st: what is called "iterative deepening" is to not just to search first to ply 1, later play 2 and so on but at the same time choice for the following search the previous best move as the first now to cut better the tree for this next ply, I´m right? (Actually Soberango start search at ply 1, then if have time ply 2 and so on but do not choice the best previous move as the first of next ply search).

2nd: starting the next ply search by the best move, Soberango will do not postponed the capture of a piece anymore cause the "horizon effect" of previous depth was shorter and the possibilitie of capture that piece later did not exists and the alpha beta now will do not replace the option of early capture by a later capture cause will have the same value and the early capture option was choiced before. i´m right?

Thanks for your time if somone reach this point of my question and the same if not anyway! :wink:
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: Is correct this reasoning?

Post by brtzsnr »

1. You can read more on iterative deepening on wikipedia https://en.wikipedia.org/wiki/Iterative ... rst_search

Basically, you increment the maximum depth you are going to search until you run out of time. Hash-table and principal-variation table will take care of using the best moves from the previous iteration. If your engine doesn't have a hash table, add one; it will improve move ordering quiet a lot (>90% time only one move will be searched).


2. The deeper you go the smaller horizon effect. Normally quiescence search takes care of horizon effect caused by captures. King safety is another thing that causes horizon effects, but that's for stronger engines (>2000 Elo).
User avatar
hgm
Posts: 27810
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Is correct this reasoning?

Post by hgm »

Luis Babboni wrote:But actually I could not easy see how to do it using some similar way I used to the case of mate said upon. The problem is that in mate cases, there are no further moves after that so evaluation is made at the moment of the mate. But here, there exists moves beyond the possible capture and then when the evaluation is made, is the same for actual position when was the piece captured.
To solve this problem, the 'delayed-loss bonus' was invented:

When the best move in a position has a score below the static evaluation, you add a bonus to that score. This means that from all lines of play that gain a certain piece, the one that actually captures it closest to the root will have the highest score, because the bonus will be awarded the smaller number of times to the player that will be losing the material.

There is one snag: in combination with alpha-beta pruning, you will have to precompensate the window limits for the addition of the bonus. Otherwise a search that just failed low, returning alpha and thus representing an upper bound, could become > alpha by adding the bonus, and thus be mistaken for an exact score.

In micro-Max/Fairy-Max the delayed-loss bonus is always 1 centi-Pawn, so window limits below the static eval have to be pre-compensated by 1 point:

Code: Select all

Search(alpha, beta)
{
  curEval = Evaluate();
  if&#40;alpha < curEval&#41; alpha--;
  if&#40;beta <= curEval&#41; beta--;

  ... // usual negamax code

  if&#40;bestScore < curEval&#41; bestScore++;
  return bestScore;
&#125;
This also takes care of the mating distance, as in the face of a mate the score of the side to be mated will always be below the static evaluation. So the 'mated' score will be softened by one point for ever move between the root and the actual capture of the Kings, making the mating engine wanting to do it in as few moves as possible.
User avatar
Luis Babboni
Posts: 464
Joined: Sat Feb 28, 2015 4:37 pm
Location: Argentina

Re: Is correct this reasoning?

Post by Luis Babboni »

Thanks people!

But I´m afraid I´ll need a more detailed explanation.

Alexandru:
For the moment Soberango not have hash tables neither quiescense search.
You think I must have that before try to solve my actual problem?

HGM:
Im afraid the "as myself" way to developement my engine (starting for not just my poor english but too to not known to programing in C++ so the most of the code I saw has not meaning for me and then I just tried to understand the idea behind it and developement my own way to do it) making it harder for me to understand things that are very obvious for others.
So my first question trying to understand your explanation is may be very stupid :oops: :
"...When the best move in a position has a score below the static evaluation..."
I just have one score that I calculate seeing the postition in the board when the depth I trying to reach is reached.
I compared the differents scores obteined that way and choice the best one (in fact for example I think my "alpha beta" is not really an alpha beta way to do it no matter its obteins the same result).
So my first noob question is:
What is exactly the score of the best move?
What is exactly the static evaluation?"
My guesses after a little googling makes me think (but far to be sure) is that best move score is my actual score calculated analyzing the position at the end of the tree and static evaluation is the score I do not calculate because is the score after did the quiescence search that Soberango do not do for the moment.

Plus that, I´m as "daring" as to ask if is possible that the usual better way to solve my problem is that "delayed loss bonus" but the iterative deepening (at least as I understand it) could solve it too?

Thanks again for your time!! :D
User avatar
hgm
Posts: 27810
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Is correct this reasoning?

Post by hgm »

The 'static evaluation' is the score you calculate for the current positions, without searching any moves. This is how you get scores in the leaves of your tree. I am sure you must do something like that too, even if you don't have quiescence search.

The score of a move is the score obtained by 'searching' this move, i.e. actually making it, and then doing some other calculation on the position after it. (Which could be an immediate static evaluation, but could also involve more search.)

The score of a position is the score of the best move in that position.

I don't think iterative deepening is a relyable way to solve the problem. Often it helps, but often it does not. E.g. it is very usual that when you finally gain something (capture a piece, or promote a Pawn), the opponent can get some compensation immediately after it. E.g. when you force a Pawn to promotion, the defending King initially defends the promotion square on the edge to delay the promotion aslong as possible, which is a poor location for a King. So when you promote the defending King will improve his position by fleeing to the center, and be appreciably further from the edge by the time you can stop him. So the engine will get the best score by promoting on the last move before the horizon. The first iteration it sees the promotion it will be in the shortest number ofmoves, as any delay would push it beyond the horizon. But two iterations later it will see that the original promotion allows the defending King to move closer to the center, and it will then switch to a line of play that delays the promotion two ply, because the horizon effect makes that seem better. In the end it might delay the promotion forever, if recognitionof repetitions or50-move rule as draws would not prevent it.
User avatar
Luis Babboni
Posts: 464
Joined: Sat Feb 28, 2015 4:37 pm
Location: Argentina

Re: Is correct this reasoning?

Post by Luis Babboni »

hgm wrote:The 'static evaluation' is the score you calculate for the current positions, without searching any moves. This is how you get scores in the leaves of your tree. I am sure you must do something like that too, even if you don't have quiescence search.

The score of a move is the score obtained by 'searching' this move, i.e. actually making it, and then doing some other calculation on the position after it. (Which could be an immediate static evaluation, but could also involve more search.)

The score of a position is the score of the best move in that position.
...
So evaluation of the actual position gives the "static evaluation"
The evaluation of the position reached after n plies using any singular path is the score of this path.
If the search of n plies gives some as the best move, the resulting position score at the end of this path that uses this "best move" as first move after actual position, is the best move score.
Last edited by Luis Babboni on Fri Jun 10, 2016 6:59 pm, edited 3 times in total.
User avatar
hgm
Posts: 27810
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Is correct this reasoning?

Post by hgm »

You do calculate the static evaluation in the tree leaves, don't you? How else could you decide what is the best move in the nodes just before the leaves?
User avatar
Luis Babboni
Posts: 464
Joined: Sat Feb 28, 2015 4:37 pm
Location: Argentina

Re: Is correct this reasoning?

Post by Luis Babboni »

hgm wrote:You do calculate the static evaluation in the tree leaves, don't you? How else could you decide what is the best move in the nodes just before the leaves?
Yes, edited the previous post after use google translation for "leaves" instead of understood it wrong!! :oops: :P
User avatar
Luis Babboni
Posts: 464
Joined: Sat Feb 28, 2015 4:37 pm
Location: Argentina

Re: Is correct this reasoning?

Post by Luis Babboni »

I found this!!!:
http://www.talkchess.com/forum/viewtopic.php?t=16751

I´ll asking you again later!! :D
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Is correct this reasoning?

Post by cdani »

Luis Babboni wrote: For the moment Soberango not have hash tables neither quiescense search.
You think I must have that before try to solve my actual problem?
Quiescense search is a must to have stable search. If not the engine one time thinks is wining material, and in the next iteration it realizes that is not the case, thus killing move ordering, and move ordering is the abc of alpha beta.

Hash tables once work minimally well, will offer your engine a consistent increase in strenght in each iteration, also a clear improvement in time to depth.