1 #include "phalanx.h"
2
3 typedef struct { unsigned f, t; } killentry;
4 killentry RK[H9][H9]; /* reaction killer */
5
6 unsigned HK[H9][H9]; /* history killer table */
7 unsigned Maxhist = 1;
8
9
init_killers(void)10 void init_killers(void)
11 {
12 memset( RK, 0, H9*H9*sizeof(killentry) );
13 memset( HK, 0, H9*H9*sizeof(unsigned) );
14 Maxhist = 1;
15 }
16
17
18
write_killer(int from,int to)19 void write_killer( int from, int to )
20 {
21
22 if( B[to] == 0 )
23 {
24 RK[G[Counter-1].m.from][G[Counter-1].m.to].f = from;
25 RK[G[Counter-1].m.from][G[Counter-1].m.to].t = to;
26
27 HK[from][to] += Depth/10 + 1;
28 if( HK[from][to] > Maxhist )
29 {
30 Maxhist = HK[from][to];
31 if( Maxhist > 4000 )
32 {
33 int f,t;
34 Maxhist /= 2;
35 for( f=A1; f!=H9; f++ )
36 for( t=A1; t!=H9; t++ )
37 HK[f][t] /= 2;
38 }
39 }
40 }
41
42 }
43
44
45
46 /*
47 * We are in a cut node, but the 1st killer was not successful.
48 * Let's lower the history killer values of the unsuccessful ones
49 * to magnify the importance of the successful one.
50 */
slash_killers(tmove * m,int n)51 void slash_killers( tmove *m, int n )
52 {
53 int i;
54 int findnewmax=0;
55
56 for( i=0; i!=n; i++ )
57 {
58 if( HK[m[i].from][m[i].to] == Maxhist ) findnewmax = 1;
59 HK[m[i].from][m[i].to] /= 2;
60 }
61
62 if( findnewmax )
63 {
64 int f,t;
65 Maxhist /= 2;
66 for( f=A1; f!=H9; f++ ) for( t=A1; t!=H9; t++ )
67 if( HK[f][t] > Maxhist ) Maxhist = HK[f][t];
68 }
69 }
70
71
72
add_killer(tmove * m,int n,thashentry * ht)73 void add_killer( tmove *m, int n, thashentry *ht )
74 {
75
76 int i, f=0, t=0;
77 tmove *mpv = &PV[0][Ply];
78 tmove *mlv = &PV[Ply][Ply];
79
80 if( Depth > 0 )
81 {
82 f = RK[G[Counter-1].m.from][G[Counter-1].m.to].f;
83 t = RK[G[Counter-1].m.from][G[Counter-1].m.to].t;
84 }
85
86 for( i=0; i!=n; i++ )
87 {
88 register tmove *m1 = m+i;
89
90 if( FollowPV )
91 {
92 if(
93 ( mpv->special && mpv->special==m1->special )
94 ||
95 ( !mpv->special && m1->from == mpv->from
96 && m1->to == mpv->to
97 && m1->in2a == mpv->in2a )
98 )
99 m1->value = CHECKMATE;
100 }
101 else
102 {
103 if( m1->from == mlv->from
104 && m1->to == mlv->to
105 && ( mlv->in2 == 0 || m1->in2 == mlv->in2 )
106 && m1->in2a == mlv->in2a ) m1->value += 350;
107
108 if( ht != NULL ) if( ht->move != 0 )
109 if( ht->move == smove(m1) ) m1->value = CHECKMATE;
110 }
111
112 if( m1->value != CHECKMATE )
113 {
114 /* mopv - moving piece value */
115 int mopv = Values[ m1->in2a >> 4 ];
116
117 if( m1->in2 ) /* capture */
118 {
119 m1->value += Values[ m1->in2>>4 ];
120
121 /* capture of last moved piece */
122 if( m1->to == G[Counter-1].m.to ) m1->value += 150;
123
124 if( Color==WHITE )
125 {
126 if( P[m1->to]&0xFF00 )
127 m1->value -= ( mopv / 4 );
128 else m1->value += 150;
129 }
130 else
131 {
132 if( P[m1->to]&0x00FF )
133 m1->value -= ( mopv / 4 );
134 else m1->value += 150;
135 }
136
137 if( m1->value < 30 ) m1->value = 30;
138
139 if( Depth > 200 )
140 {
141 m1->value += see( B, m1->from, m1->to );
142 if(m1->value<0) m1->value=20;
143 }
144 }
145 /* non captures - look at the power tables */
146 else if( mopv>P_VALUE )
147 {
148 if( Color==WHITE )
149 {
150 /* leaving attacked square */
151 if(P[m1->from]&0xFF00) m1->value += mopv/20;
152 /* going to attacked square */
153 if(P[m1->to]&0xFF00) m1->value -= mopv/15;
154 }
155 else
156 {
157 if(P[m1->from]&0x00FF) m1->value += mopv/20;
158 if(P[m1->to]&0x00FF) m1->value -= mopv/15;
159 }
160 }
161
162 if( m1->in1 != m1->in2a ) /* pawn promotion */
163 m1->value += Values[ m1->in2a>>4 ] - P_VALUE;
164
165 if( Depth > 0 )
166 {
167 if( m1->from == f && m1->to == t )
168 m1->value += max(Depth,50);
169 if( HK[ m1->from ][ m1->to ] )
170 m1->value +=
171 1 + HK[ m1->from ][ m1->to ] * 500 / Maxhist;
172 }
173
174 }
175 }
176
177 }
178
179