who understands my code

Discussion of chess software programming and technical issues.

Moderator: Ras

flok

who understands my code

Post by flok »

Hi,

I was looking at my quiescence code and found this:

Code: Select all

  if (score > bestVal)
  {
          bestVal = score;
          // remember move for sibling-node-best-move
          selMove = *newCause.causingMove;
  
          if (score > alpha)
          {
                  alpha = score;
  
                  // remember PV
                  newPv.assign(tempPv, false);
  
                  if (score >= beta)
                          break;
          }
  }
I wonder why is there a if (score > bestval) and also a if (score > alpha)?
Because if > bestval then always also > alpha. I think I can just remove that if > alpha and maybe even rewrite things and get rid of bestVal (using alpha instead).

Any opinions on this?

(probably code I copied from somewhere)[/code]
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: who understands my code

Post by stegemma »

It would have sense only if you can start with a bestval < alpha (-infinite, for sample) and your search can returns something less than alpha but greater than actual bestval.
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com
Henk
Posts: 7251
Joined: Mon May 27, 2013 10:31 am

Re: who understands my code

Post by Henk »

Always simplify even it is wrong.

[For code usually only gets more and more complicated. ]
User avatar
hgm
Posts: 28464
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: who understands my code

Post by hgm »

flok wrote:I wonder why is there a if (score > bestval) and also a if (score > alpha)?
Because if > bestval then always also > alpha.
Not if you use fail-soft. Then bestVal starts at -INFINITY even if alpha is much larger. At the end you return bestScore, and in case of a fail low this can still be smaller than alpha (which would then still be the original alpha). With fail-hard one usually does not keep a bestValue at all, as one would return alpha.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: who understands my code

Post by bob »

Normally that is written differently:

if (score > alpha) {
if (score >= beta)
return beta
alpha = score;
}

Seems more rational that way. If score is <= alpha, ignore it. Else if it is > beta, return instantly (beta cutoff) otherwise remember it as best since we now know it is > alpha and < beta...
User avatar
Robert
Posts: 20
Joined: Tue Oct 07, 2008 2:53 am
Location: Brasil

Re: who understands my code

Post by Robert »

Code: Select all

  if (score > bestVal)
  {
          bestVal = score;
          // remember move for sibling-node-best-move
          selMove = *newCause.causingMove;
  
          if (score > alpha)
          {
                  alpha = score;
  
                  // remember PV
                  newPv.assign(tempPv, false);
  
                  if (score >= beta)
                          break;              <= I don't understand This!!!
          }
  }
flok

Re: who understands my code

Post by flok »

Robert wrote:

Code: Select all

  if (score > bestVal)
  {
          bestVal = score;
          // remember move for sibling-node-best-move
          selMove = *newCause.causingMove;
  
          if (score > alpha)
          {
                  alpha = score;
  
                  // remember PV
                  newPv.assign(tempPv, false);
  
                  if (score >= beta)
                          break;              <= I don't understand This!!!
          }
  }
beta cut-off; stop the loop and return the best bestval.
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: who understands my code

Post by kbhearn »

then why'd you write it? ;)

the break in this case does something outside the scope of the quoted code - it removes you from the innermost loop you're currently in perhaps to the final 'return bestVal;' line (which you now have scored as the current score > beta). It may avoid some code duplication if the TT update is similar enough for the fail high and fail low cases to write it in this manner.
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: who understands my code

Post by lauriet »

I'm with Kevin......how is it that you have written code and you don't know what it does ??? How did you write it to start with ???
flok

Re: who understands my code

Post by flok »

copy/paste from somewhere