1 #include "phalanx.h"
2
3 #define LREHASH 8
4
5 tpbook Learn;
6
7 typedef struct
8 { unsigned hashboard;
9 short depth, value;
10 } tlearn;
11
12
wlearn(int depth,int value)13 void wlearn( int depth, int value )
14 {
15
16 int size, pos;
17 int i;
18 int bdepth, bpos;
19 tlearn cell;
20
21 if( Flag.learn == 0 || Learn.f == NULL || depth <= 400 ) return;
22
23 size = Learn.filesize/sizeof(tlearn);
24 pos = G[Counter].hashboard % size;
25
26 if( fseek( Learn.f, pos*sizeof(tlearn), SEEK_SET ) != 0 ) return;
27 myfread( &cell, sizeof(tlearn), Learn.f );
28
29 bdepth = -1000;
30 bpos = pos;
31
32 for( i=0; i<LREHASH; i++ )
33 {
34 if( fseek( Learn.f, ((pos+i)%size)*sizeof(tlearn), SEEK_SET ) != 0 )
35 return;
36 myfread( &cell, sizeof(tlearn), Learn.f );
37
38 if( cell.hashboard == 0 || cell.hashboard == G[Counter].hashboard )
39 { bpos = pos+i; bdepth = cell.depth; break; }
40
41 if( cell.depth > bdepth )
42 { bdepth = cell.depth; bpos = pos+i; }
43 }
44
45 if( cell.hashboard == G[Counter].hashboard && cell.depth > depth )
46 return;
47
48 if( fseek( Learn.f, (bpos%size)*sizeof(tlearn), SEEK_SET ) != 0 )
49 return;
50
51 cell.hashboard = G[Counter].hashboard;
52 cell.depth = depth;
53 cell.value = value;
54
55 myfwrite( &cell, sizeof(tlearn), Learn.f );
56
57 }
58
59
60
rlearn(void)61 int rlearn( void )
62 {
63
64 int size, pos;
65 int i;
66 tlearn cell;
67
68 if( Flag.learn == 0 || Learn.f == NULL ) return NOVALUE;
69
70 size = Learn.filesize/sizeof(tlearn);
71 pos = G[Counter].hashboard % size;
72
73 for( i=0; i<LREHASH; i++ )
74 {
75 if( fseek( Learn.f, ((pos+i)%size)*sizeof(tlearn), SEEK_SET ) != 0 )
76 return NOVALUE;
77 myfread( &cell, sizeof(tlearn), Learn.f );
78
79 if( cell.hashboard == 0 ) return NOVALUE;
80
81 if( cell.hashboard == G[Counter].hashboard )
82 {
83 if( cell.depth >= Depth ) return cell.value;
84 else return NOVALUE;
85 }
86 }
87
88 return NOVALUE;
89
90 }
91
92
93