Page 1 of 6

PVS & Embla

Posted: Thu Oct 19, 2017 8:32 pm
by flok
Hi,

I'm trying to add PVS to Embla.
I've added almost exact the code from
https://chessprogramming.wikispaces.com ... seudo Code
to it but to my surprise it lost almost 50 elo.

I've probably overlooked a - or + or something somewhere but I'm not seeing it.
Anyone willing to look at it?
All the code is available
https://github.com/flok99/Embla/tree/PVS


(Brain.cpp, method is ::search() )


regards

Re: PVS & Embla

Posted: Thu Oct 19, 2017 8:52 pm
by AlvaroBegue
If your transposition tables are working well, PVS should not lose Elo. I haven't read your code, but I can give you the pseudo-code for what I do.

Code: Select all

int negamax(Board &board, int alpha, int beta, int depth) {
  if &#40;depth <= 0&#41;
    return quiescence_search&#40;board, alpha, beta&#41;;
  
  for &#40;int i = 0; i < board.n_moves&#40;); ++i&#41; &#123;
    board.make_move&#40;i&#41;;
    if &#40;i > 0&#41; &#123;
      int reduction = 0; // for now; you can implement LMR here
      score = -negamax&#40;-alpha-1, -alpha, depth - 1 - reduction&#41;;
      if &#40;score <= alpha&#41; &#123;
        board.unmake_move&#40;);
        continue;
      &#125;
      if &#40;score >= beta && reduction == 0&#41;
        goto DONE;
    &#125;
    int score = -negamax&#40;-alpha, -beta, depth - 1&#41;;
DONE&#58;;
    board.unmake_move&#40;);
    if &#40;score > alpha&#41; &#123;
      alpha = score;
      if &#40;alpha >= beta&#41;
        break;
    &#125;
  &#125;
  
  return alpha;
&#125;


Re: PVS & Embla

Posted: Thu Oct 19, 2017 8:53 pm
by AndrewGrant
Are you using fail-soft or fail-hard?

Re: PVS & Embla

Posted: Thu Oct 19, 2017 8:56 pm
by elcabesa
i think that line 1119 is wrong.

Code: Select all

if &#40;bSearchPV&#41;
				retry&#58;
					score = -search&#40;sd, &m, depthLeft - 1 + extension, co, -beta, -alpha, newHash, curBestSiblings, false, &tempPv&#41;;
				else &#123;
					score = -search&#40;sd, &m, depthLeft - 1 + extension, co, -alpha - 1, -alpha, newHash, curBestSiblings, false, &tempPv&#41;;
!!! WRONG!!!				if &#40;score > alpha && score < beta&#41;   !!! WRONG!!!!!!
						goto retry;
&#125;
it should probably be :

Code: Select all

if&#40;val>alpha&#41;
because the search in the above line ha limits [alpha, alpha+1] and not [alpha,beta]
[/code]

Re: PVS & Embla

Posted: Thu Oct 19, 2017 8:57 pm
by flok
AndrewGrant wrote:Are you using fail-soft or fail-hard?
Fail soft: the returned score can be outside the bounds.


regards

Re: PVS & Embla

Posted: Thu Oct 19, 2017 9:05 pm
by flok
I'm going to test that. I don't fully understand it because the wiki says that fail-soft should also check for score < beta?

Re: PVS & Embla

Posted: Thu Oct 19, 2017 9:14 pm
by tomitank
Hi flok!

I think, the biggest wasted time here:

Code: Select all

if &#40;useNm && !rootOfTree && nmDepth > 0 && !isCheck && !isNullMove&#41;
add to

Code: Select all

IS_PV = &#40;beta != alpha + 1&#41;;
and

Code: Select all

if (!IS_PV && useNm && nmDepth > 0 && !isCheck && !isNullMove&#41;
(root node = Pv node)

Try this by IID as well.

Your code is difficult to understand for me.
Try to clean the code and you'll notice where the bug is.

Re: PVS & Embla

Posted: Thu Oct 19, 2017 9:40 pm
by flok
That sounds interesting!
A quick TTD test showed no improvement (it got only slower) but maybe a longer run shows better results (I've started that).
thanks

Re: PVS & Embla

Posted: Thu Oct 19, 2017 10:26 pm
by elcabesa
what version of GCC compiler are you using?
because I'm trying to copile it with the makefile you provide, but it doesn't work on my PC

Re: PVS & Embla

Posted: Thu Oct 19, 2017 10:41 pm
by Sven
According to the "Compare" function on github your branch "PVS" seems to have more diffs to the master branch than just the PVS change. This could explain the surprising results. Maybe you had checked out the wrong branch when making the "PVS" branch?