Worst advice

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Worst advice

Post by Joost Buijs »

flok wrote:Odd: if I disable quiescence-search of limit it to 1 or 2, then I get silly moves:

Code: Select all

info depth 1 seldepth 1 score cp 40 time 9 nodes 41 pv e2e4
...
info depth 6 seldepth 6 score cp 94 time 2532 nodes 165366 pv d2d4 a7a6 g1f3 d1d3
info depth 6 seldepth 6 score cp -19 time 5379 nodes 370469 pv e2e3 d7d5 d1h5 d8d6 f1b5 b8c6
info depth 7 seldepth 7 score cp 56 time 8557 nodes 593431 pv a2a3 a7a6 e2e4 a6a5 d2d4 e7e5 b1c3
info depth 7 seldepth 7 score cp 67 time 11126 nodes 767157 pv a2a3 b7b6 e2e4 c8a6 d1h5 a6f1 e1f1
That is not odd, you have to make sure that all capture sequences are resolved before you analyze the position statically.

When you disable the quiescence search, or stop the quiescence somewhere in the middle (which has the same effect), you will get an enormous horizon effect which makes your engine play tactical mistakes.
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: Worst advice

Post by Henk »

I forget one which also worked for Skipper: return best move found so far at root level when time is up even if search is not finished. But drawback was that after that I was not able to implement aspiration search correctly.
flok

Re: Worst advice

Post by flok »

Joost Buijs wrote:
flok wrote:Odd: if I disable quiescence-search of limit it to 1 or 2, then I get silly moves:

Code: Select all

info depth 1 seldepth 1 score cp 40 time 9 nodes 41 pv e2e4
...
info depth 6 seldepth 6 score cp 94 time 2532 nodes 165366 pv d2d4 a7a6 g1f3 d1d3
info depth 6 seldepth 6 score cp -19 time 5379 nodes 370469 pv e2e3 d7d5 d1h5 d8d6 f1b5 b8c6
info depth 7 seldepth 7 score cp 56 time 8557 nodes 593431 pv a2a3 a7a6 e2e4 a6a5 d2d4 e7e5 b1c3
info depth 7 seldepth 7 score cp 67 time 11126 nodes 767157 pv a2a3 b7b6 e2e4 c8a6 d1h5 a6f1 e1f1
That is not odd, you have to make sure that all capture sequences are resolved before you analyze the position statically.

When you disable the quiescence search, or stop the quiescence somewhere in the middle (which has the same effect), you will get an enormous horizon effect which makes your engine play tactical mistakes.
So a premature end of the q-search by limitting it to e.g. 2 can cause this. Ok, but I also see this when not checking all capture moves, e.g. when only checking re-captures.
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Worst advice

Post by Joost Buijs »

flok wrote:
Joost Buijs wrote:
flok wrote:Odd: if I disable quiescence-search of limit it to 1 or 2, then I get silly moves:

Code: Select all

info depth 1 seldepth 1 score cp 40 time 9 nodes 41 pv e2e4
...
info depth 6 seldepth 6 score cp 94 time 2532 nodes 165366 pv d2d4 a7a6 g1f3 d1d3
info depth 6 seldepth 6 score cp -19 time 5379 nodes 370469 pv e2e3 d7d5 d1h5 d8d6 f1b5 b8c6
info depth 7 seldepth 7 score cp 56 time 8557 nodes 593431 pv a2a3 a7a6 e2e4 a6a5 d2d4 e7e5 b1c3
info depth 7 seldepth 7 score cp 67 time 11126 nodes 767157 pv a2a3 b7b6 e2e4 c8a6 d1h5 a6f1 e1f1
That is not odd, you have to make sure that all capture sequences are resolved before you analyze the position statically.

When you disable the quiescence search, or stop the quiescence somewhere in the middle (which has the same effect), you will get an enormous horizon effect which makes your engine play tactical mistakes.
So a premature end of the q-search by limitting it to e.g. 2 can cause this. Ok, but I also see this when not checking all capture moves, e.g. when only checking re-captures.
Only checking recaptures is not sufficient, you will miss things like pieces that are overloaded or pinned.
Usually you have to check all winning and equal captures, you can omit losing captures because it is very likely that they won't increase your score.
Equal captures don't increase your material score, but they can have influence on your positional score and that might just be enough to get your total score above alpha.

You can determine upfront how big the increase in score has to be to get above alpha.
For instance when your score is 400 cp below alpha it is not very useful to capture a pawn that gains you 100 cp, although it might be a winning capture you can safely skip this.
Likewise you only have to check equal captures when your score is already very close to alpha.
flok

Re: Worst advice

Post by flok »

Joost Buijs wrote:Only checking recaptures is not sufficient, you will miss things like pieces that are overloaded or pinned.
Usually you have to check all winning and equal captures, you can omit losing captures because it is very likely that they won't increase your score.
That indeed works much better!

info depth 6 seldepth 6 score cp -8 time 2096 nodes 391732 pv e2e3 e7e5 d1h5 d8f6 f2f4 e5e4 f4e5
info depth 7 seldepth 7 score cp 41 time 4431 nodes 864763 pv e2e3 c7c6 b1c3 g8f6 d1f3 d8a5 f3f4 c6b5

I'm not sure about the c7c6.
Equal captures don't increase your material score, but they can have influence on your positional score and that might just be enough to get your total score above alpha.
You can determine upfront how big the increase in score has to be to get above alpha.
For instance when your score is 400 cp below alpha it is not very useful to capture a pawn that gains you 100 cp, although it might be a winning capture you can safely skip this.
Likewise you only have to check equal captures when your score is already very close to alpha.
So do I understand it correctly that I either:

- check if, when capturing, the value of my piece >= opponent piece

- check if the value of opponent piece >= alpha - eval_of_current_position()

right?
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Worst advice

Post by kbhearn »

flok wrote: So do I understand it correctly that I either:

- check if, when capturing, the value of my piece >= opponent piece

- check if the value of opponent piece >= alpha - eval_of_current_position()

right?
second condition is mostly right (you usually add in a margin as well to cover how much you expect the nonmaterial score might be able to shift)

first condition is not quite broad enough (probably). if the opponent's piece is unprotected or insufficiently protected it still should be tried in qsearch.

http://chessprogramming.wikispaces.com/ ... Evaluation
if that quantity is < 0 you can relatively safely ignore the capture in qsearch.
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Worst advice

Post by Joost Buijs »

flok wrote:
So do I understand it correctly that I either:

- check if, when capturing, the value of my piece >= opponent piece

- check if the value of opponent piece >= alpha - eval_of_current_position()

right?
It all comes down to determining the material gain of the capture move you are going to try, you can do this either by using SEE(), or looking at the piece values directly.
When the piece that will be captured is undefended you can take it's full value, when the piece is defended you can take it's full value minus the value of the piece you are capturing with.

You also have to add a safety margin because you don't know in advance what kind of influence the capture will have on the positional score.

When you have a means to determine the material gain, basically the whole algorithm boils down to this:

Code: Select all


int quiescence&#40;int alpha, int beta&#41;

if &#40;in_check&#40;)) &#123;
  do_evasion_moves&#40;);
&#125;
else &#123;

  // stand pat criterion
  int evaluation = evaluate&#40;);
  if &#40;evaluation >= beta&#41;
    return evaluation;
  if &#40;evaluation > alpha&#41;
    alpha = evaluation;

  // try captures
  while &#40;captures&#41; &#123;
    if &#40;evaluation + material_gain&#40;capture&#41; + safety_margin > alpha&#41; &#123;
      do_capture&#40;);
      int score = -quiescence&#40;-beta, -alpha&#41;;
      undo_capture&#40;);
      if &#40;score >= beta&#41;
        return score;
      if &#40;score > alpha&#41;
        alpha = score;
    &#125;
  &#125;
&#125;

Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: Worst advice

Post by Henk »

Also advice not to reduce captures during LMR worked for Skipper.