File: learn.c

package info (click to toggle)
phalanx 22%2Bd051004-14
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 1,444 kB
  • ctags: 973
  • sloc: ansic: 11,916; sh: 80; makefile: 44
file content (92 lines) | stat: -rw-r--r-- 1,666 bytes parent folder | download | duplicates (7)
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
#include "phalanx.h"

#define LREHASH 8

tpbook Learn;

typedef struct
{	unsigned hashboard;
	short depth, value;
} tlearn;


void wlearn( int depth, int value )
{

int size, pos;
int i;
int bdepth, bpos;
tlearn cell;

if( Flag.learn == 0 || Learn.f == NULL || depth <= 400 ) return;

size = Learn.filesize/sizeof(tlearn);
pos = G[Counter].hashboard % size;

if( fseek( Learn.f, pos*sizeof(tlearn), SEEK_SET ) != 0 ) return;
myfread( &cell, sizeof(tlearn), Learn.f );

bdepth = -1000;
bpos   = pos;

for( i=0; i<LREHASH; i++ )
{
	if( fseek( Learn.f, ((pos+i)%size)*sizeof(tlearn), SEEK_SET ) != 0 )
		return;
	myfread( &cell, sizeof(tlearn), Learn.f );

	if( cell.hashboard == 0 || cell.hashboard == G[Counter].hashboard )
	{ bpos = pos+i; bdepth = cell.depth; break; }

	if( cell.depth > bdepth )
	{ bdepth = cell.depth; bpos = pos+i; }
}

if( cell.hashboard == G[Counter].hashboard && cell.depth > depth )
	return;

if( fseek( Learn.f, (bpos%size)*sizeof(tlearn), SEEK_SET ) != 0 )
	return;

cell.hashboard = G[Counter].hashboard;
cell.depth = depth;
cell.value = value;

myfwrite( &cell, sizeof(tlearn), Learn.f );

}



int rlearn( void )
{

int size, pos;
int i;
tlearn cell;

if( Flag.learn == 0 || Learn.f == NULL ) return NOVALUE;

size = Learn.filesize/sizeof(tlearn);
pos = G[Counter].hashboard % size;

for( i=0; i<LREHASH; i++ )
{
	if( fseek( Learn.f, ((pos+i)%size)*sizeof(tlearn), SEEK_SET ) != 0 )
		return NOVALUE;
	myfread( &cell, sizeof(tlearn), Learn.f );

	if( cell.hashboard == 0 ) return NOVALUE;

	if( cell.hashboard == G[Counter].hashboard )
	{
		if( cell.depth >= Depth ) return cell.value;
		else return NOVALUE;
	}
}

return NOVALUE;

}