3 Copyright (c) Scott Gasch
11 Evaluation score hashing code.
24 extern ULONG g_uIterateDepth;
27 GetRoughEvalScore(IN OUT SEARCHER_THREAD_CONTEXT *ctx,
35 This is meant to be the "one place" that code looks when it needs to
36 get an idea of the estimated evaluation of a position (in mid tree,
37 not at the leaves... at the leaves just call Eval directly).
41 1. The top of the tree (near the root) represents very few nodes
42 which have big subtrees. Use the real Eval here.
44 2. Otherwise possibly probe the eval hash -- if there's a score in
45 it then we can return quickly.
47 3. Otherwise do a (very) rough material estimate.
51 IN OUT SEARCHER_THREAD_CONTEXT *ctx,
62 POSITION *pos = &(ctx->sPosition);
68 return Eval(ctx, iAlpha, iBeta);
70 else if ((fUseHash) || (ctx->uPly <= (g_uIterateDepth / 2)))
72 u64Key = (pos->u64PawnSig ^ pos->u64NonPawnSig);
73 u = (ULONG)u64Key & (EVAL_HASH_TABLE_SIZE - 1);
74 if (ctx->rgEvalHash[u].u64Key == u64Key)
76 ctx->uPositional = ctx->rgEvalHash[u].uPositional;
77 return(ctx->rgEvalHash[u].iEval);
80 return(pos->iMaterialBalance[pos->uToMove] + ctx->uPositional);
85 ProbeEvalHash(IN OUT SEARCHER_THREAD_CONTEXT *ctx)
90 Probe the eval hash; return a real score if there's a hit
91 otherwise return INVALID_SCORE.
95 IN OUT SEARCHER_THREAD_CONTEXT *ctx : note that in the case
96 of a hit, *ctx is modified also.
104 POSITION *pos = &(ctx->sPosition);
105 UINT64 u64Key = (pos->u64PawnSig ^ pos->u64NonPawnSig);
106 ULONG u = (ULONG)u64Key & (EVAL_HASH_TABLE_SIZE - 1);
108 if (ctx->rgEvalHash[u].u64Key == u64Key)
110 ctx->uPositional = ctx->rgEvalHash[u].uPositional;
111 pos->cTrapped[WHITE] = ctx->rgEvalHash[u].cTrapped[WHITE];
112 pos->cTrapped[BLACK] = ctx->rgEvalHash[u].cTrapped[BLACK];
113 return(ctx->rgEvalHash[u].iEval);
115 return(INVALID_SCORE);
119 StoreEvalHash(IN OUT SEARCHER_THREAD_CONTEXT *ctx,
125 Store a score in the eval hash table (which is pointed to
130 SEARCHER_THREAD_CONTEXT *ctx,
139 POSITION *pos = &(ctx->sPosition);
140 UINT64 u64Key = (pos->u64PawnSig ^ pos->u64NonPawnSig);
141 ULONG u = (ULONG)u64Key & (EVAL_HASH_TABLE_SIZE - 1);
142 ctx->rgEvalHash[u].u64Key = u64Key;
143 ctx->rgEvalHash[u].iEval = iScore;
144 ctx->rgEvalHash[u].uPositional = ctx->uPositional;
145 ctx->rgEvalHash[u].cTrapped[WHITE] = pos->cTrapped[WHITE];
146 ctx->rgEvalHash[u].cTrapped[BLACK] = pos->cTrapped[BLACK];