Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: MTD(f)

Author: rasjid chan

Date: 10:10:37 06/18/05

Go up one level in this thread



QUOTE:
int qsearch(int alpha, int beta)
{
  /* Fail soft version - extremly simplified */
  int best, score;
  best = eval();
  if (best > alpha)
  {
    if (best >= beta)
      return best;
    alpha = best;
//my comment-  here alpha changed and so cannot fail low.
  }
  for (all captures)
  {
    if (value of captured piece + margin < alpha)
      continue; /* Futile to try this move */
    makemove();
    score = -qsearch(-beta, -alpha)
    unmakemove();
    if (score > best)
    {
      best = score;
      if (best > alpha)
      {
        if (best >= beta)
          return best;
        alpha = best;
//my comment-  here alpha changed and so cannot fail low.

      }
    }
  }
  return best;
}




UNQUOTE:

I think this is the usual and common way to try writing efficient and shortest
code. But I would be careful not to try using "best" to mislead me about the
best score unless I know what I am doing.

Maybe adding an alpha_start will distinguish fail-low from exact return.

int qsearch(int alpha, int beta)
{
  /* Fail soft version - extremly simplified */
  int best, score, alpha_start = alpha;
  best = eval();
  if (best > alpha)
  {
    if (best >= beta)
      return best;
    alpha = best;
//my comment-  here alpha changed and so cannot fail low.
  }
  for (all captures)
  {
    if (value of captured piece + margin < alpha)
      continue; /* Futile to try this move */
    makemove();
    score = -qsearch(-beta, -alpha)
    unmakemove();
    if (score > best)
    {
      best = score;
      if (best > alpha)
      {
        if (best >= beta)
          return best;
        alpha = best;
//my comment-  here alpha changed and so cannot fail low.

      }
    }
  }

  if (alpha>alpha_start)
  return alpha;
 //else fail-low and soft


  return best;
}

It may still have error; I am single processor.

Best Regards
Rasjid



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.