1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#include <stdio.h>
#include <stdlib.h>
#include "chess.h"
#include "data.h"
/* last modified 01/07/98 */
/*
********************************************************************************
* *
* LookUp() is used to retrieve entries from the transposition table so that *
* this sub-tree won't have to be searched again if we reach a position that *
* has been searched previously. a transposition table position contains the *
* following data packed into 128 bits with each item taking the number of *
* bits given in the table below: *
* *
* bits name SL description *
* 3 age 61 search id to identify old trans/ref entried. *
* 2 type 59 0->value is worthless; 1-> value represents a fail- *
* low bound; 2-> value represents a fail-high bound; *
* 3-> value is an exact score. *
* 1 threat 58 threat extension flag, 1 -> extend this position. *
* 16 value 21 unsigned integer value of this position + 65536. *
* this might be a good score or search bound. *
* 21 move 0 best move from the current position, according to the *
* search at the time this position was stored. *
* *
* 16 draft 48 the depth of the search below this position, which is *
* used to see if we can use this entry at the current *
* position. note that this is in units of 1/8th of a *
* ply. *
* 48 key 0 leftmost 48 bits of the 64 bit hash key. this is *
* used to "verify" that this entry goes with the *
* current board position. *
* *
********************************************************************************
*/
int LookUp(int ply, int depth, int wtm, int *alpha, int *beta, int *threat)
{
register BITBOARD temp_hash_key;
register HASH_ENTRY *htable;
register int type, draft, avoid_null=WORTHLESS, val;
/*
----------------------------------------------------------
| |
| first, compute the initial hash address and choose |
| which hash table (based on color) to probe. |
| |
----------------------------------------------------------
*/
hash_move[ply]=0;
temp_hash_key=HashKey>>16;
#if !defined(FAST)
transposition_probes++;
#endif
/*
----------------------------------------------------------
| |
| now, check both "parts" of the hash table to see if |
| this position is in either one. |
| |
----------------------------------------------------------
*/
htable=((wtm)?trans_ref_wa:trans_ref_ba)+(((int) HashKey) & hash_maska);
if (!Xor(And(htable->word2,mask_80),temp_hash_key)) do {
#if !defined(FAST)
transposition_hits++;
#endif
hash_move[ply]=((int) htable->word1) & 07777777;
type=((int) Shiftr(htable->word1,59)) & 03;
draft=(int) Shiftr(htable->word2,48);
val=(((int) Shiftr(htable->word1,21)) & 01777777)-65536;
*threat=((int) Shiftr(htable->word1,58)) & 01;
if ((type & UPPER_BOUND) &&
depth-NULL_MOVE_DEPTH-INCREMENT_PLY <= draft &&
val < *beta) avoid_null=AVOID_NULL_MOVE;
if (depth > draft) break;
switch (type) {
case EXACT_SCORE:
if (abs(val) > MATE-100) {
if (val > 0) val-=(ply-1);
else val+=(ply-1);
}
*alpha=val;
return(EXACT_SCORE);
case UPPER_BOUND:
if (val <= *alpha) {
*alpha=val;
return(UPPER_BOUND);
}
break;
case LOWER_BOUND:
if (val >= *beta) {
*beta=val;
return(LOWER_BOUND);
}
break;
}
} while(0);
htable=((wtm)?trans_ref_wb:trans_ref_bb)+(((int) HashKey) & hash_maskb);
if (!Xor(And(htable->word2,mask_80),temp_hash_key)) {
#if !defined(FAST)
transposition_hits++;
#endif
if (hash_move[ply]==0)
hash_move[ply]=((int) htable->word1) & 07777777;
type=((int) Shiftr(htable->word1,59)) & 03;
draft=Shiftr(htable->word2,48);
val=(((int) Shiftr(htable->word1,21)) & 01777777)-65536;
*threat=((int) Shiftr(htable->word1,58)) & 01;
if ((type & UPPER_BOUND) &&
depth-NULL_MOVE_DEPTH-INCREMENT_PLY <= draft &&
val < *beta) avoid_null=AVOID_NULL_MOVE;
if (depth > draft) return(avoid_null);
switch (type) {
case EXACT_SCORE:
if (abs(val) > MATE-100) {
if (val > 0) val-=(ply-1);
else val+=(ply-1);
}
*alpha=val;
return(EXACT_SCORE);
case UPPER_BOUND:
if (val <= *alpha) {
*alpha=val;
return(UPPER_BOUND);
}
return(avoid_null);
case LOWER_BOUND:
if (val >= *beta) {
*beta=val;
return(LOWER_BOUND);
}
return(avoid_null);
}
}
return(avoid_null);
}
|