Computer Chess Club Archives


Search

Terms

Messages

Subject: Two-Tier Hashtable vs. One-Tier

Author: Stuart Cracraft

Date: 14:36:47 09/21/04


Hi -- this past weekend I switched from single-tier replace
always to two-tier place 1st tier in 2nd if incoming position
is searched to a >= depth than currently stored at hash entry
and store incoming position in 1st tier, otherwise always replace
2nd tier if depth is.

This is represented by the actual code below.

After doing this, I expected least the same result or slightly
better (than 250/300 on Win-at-Chess). Instead I scored 248/300
(consistently) with Two-Tier and 250/300 consistently with One-Tier.

I am asking that some of the talented folks look this over
and tell me if this is grossly wrong (expectation -or- code.)

Or what might be the best methods for evaluating the function of
the two methods...

Thanks,

Stuart

#ifdef TT
int retrieve(int *length, int *score, char *flag, mv *hashmv)
{
  HASHE * phashe = &hash_table[hashkey % MAXHASH];
  ttprobes++;
  if (phashe->key == hashkey) {
    *length = phashe->depth;
    *score = phashe->val;
    *flag = phashe->flags;
    savemove(hashmv, phashe->best);
    ttmatches++;
    return(1);
  }
#ifdef TTTWOTIER
  else if ((phashe+1)->key == hashkey) {
    *length = (phashe+1)->depth;
    *score = (phashe+1)->val;
    *flag = (phashe+1)->flags;
    savemove(hashmv, (phashe+1)->best);
    ttmatches++;
    return(1);
  }
#endif
  return(0);
}
void store(int length, int score, char flag, mv hashmv)
{
  HASHE * phashe = &hash_table[hashkey % MAXHASH];
  // If position to be stored has depth greater than or equal to entry
  // backup 1st level to 2nd level and then store at 1st level.
  // If position to be stored has depth less than entry, store at 2nd level.
  if (length >= phashe->depth) {
#ifdef TTTWOTIER
    (phashe+1)->key = phashe->key;
    (phashe+1)->val = phashe->val;
    (phashe+1)->flags = phashe->flags;
    (phashe+1)->depth = phashe->depth;
    savemove(&(phashe+1)->best,phashe->best);
#endif
    phashe->key = hashkey;
    savemove(&phashe->best,hashmv);
    phashe->val = score;
    phashe->flags = flag;
    phashe->depth = length;
#ifdef TTTWOTIER
  } else {
    (phashe+1)->key = hashkey;
    (phashe+1)->val = score;
    (phashe+1)->flags = flag;
    (phashe+1)->depth = length;
    savemove(&(phashe+1)->best,hashmv);
#endif
  }
}

in search() usage is:

search(alpha,beta,depth)
:
:
#ifdef TT
  // Probe hash table. If seen before with equal or greater draft, return.
  // Otherwise, set alpha and beta bounds if available.
  // Last, if alpha exceeds or equals beta, return.
  if (retrieve(&length, &score, &flag, &hashmv)) {
    if (length >= sdepth) {     // sdepth is original value of depth at entry
                                // to search, not including extensions.
      if (flag == VALID) {
        savemove(&npv[ply][ply],hashmv);
        for (j=ply+1;j<pvl[ply+1];++j)
	  savemove(&npv[ply][j],npv[ply+1][j]);
        pvl[ply]=pvl[ply+1];
        return(score);
      }
      if (flag == LBOUND) alpha = MAX(alpha, score);
      if (flag == UBOUND) beta = MIN(beta, score);
      if (alpha >= beta) return(score);
      if (legalmove2(bd,hashmv)) hashed = 1;
    }
  }
#endif
:
:
main search
:
:
at search best >= beta or the best alpha (stored in best)
after all moves checked:

#ifdef TT
done:
  flag = VALID;
  if (best <= alpha) flag = UBOUND;
  if (best >= beta)  flag = LBOUND;
  if (length <= depth && at least one legal move searched and scored) {
    store(depth,best,flag,sml[bestmvi]);
  }
  return(best);
}




This page took 0.01 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.