@@ -116,7 +116,6 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
116116 MOVE moves [MAXMOVES ];
117117 MOVE best_move = 0 ;
118118 char str_mov [MVLEN ];
119- SQUARE checking_sqs [5 ];
120119 int val = ERRORVALUE ;
121120 char hash_flag = HASH_ALPHA ;
122121 int reduce = 0 , LMR = 0 ;
@@ -155,7 +154,7 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
155154 val = AssesDraw (board );
156155 if (val ) {
157156 if (best_move ){
158- LMR = (reduce && i > good ) ? 1 : 0 ;
157+ LMR = (reduce && i > good && ! CAPTMASK ( moves [ i ]) && ! InCheck ( board , 0 ) ) ? 1 : 0 ;
159158 val = - AlphaBeta (board , depth - LMR - 1 , - alpha - 1 , - alpha , root + 1 , control , 0 , killers );
160159 if (val > alpha ){
161160 val = - AlphaBeta (board , depth - 1 , - alpha - 1 , - alpha , root + 1 , control , 0 , killers );
@@ -166,7 +165,7 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
166165 }else val = - AlphaBeta (board , depth - 1 , - beta , - alpha , root + 1 , control , 0 , killers );
167166 }
168167 Takeback (board , moves [i ]);
169- if (control -> stop ) return alpha ;
168+ if (! control -> ponder && control -> stop ) return alpha ;
170169 if (val >= beta ){
171170 UpdateTable (& hash_table , board -> zobrist_key , val , moves [i ], depth , HASH_BETA );
172171 if (CAPTMASK (moves [i ]) == 0
@@ -183,9 +182,9 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
183182 best_move = moves [i ];
184183 if (root == 0 ) control -> best_move = best_move ;
185184 }
186- if (root == 0 && ! control -> ponder && ((clock () - control -> init_time ) > control -> wish_time * CPMS )){
185+ if (root == 0 && ((clock () - control -> init_time ) > control -> wish_time * CPMS )){
187186 /* if short of time, don't search anymore after current move */
188- control -> max_depth = depth ;
187+ control -> stop = 1 ;
189188 return alpha ;
190189 }
191190 }else Takeback (board , moves [i ]);
@@ -216,17 +215,20 @@ void IterativeDeep(BOARD *board, CONTROL *control)
216215 int eval = 0 , pvlen = 0 ;
217216 int alpha = - INFINITE ;
218217 int beta = INFINITE ;
218+ int widening = ASP_WINDOW ;
219219 unsigned long long nps = 0 ;
220220 MOVE killers [MAXDEPTH ][2 ];
221221 control -> best_move = 0 ;
222+
223+ /*printf("time %llu %llu\n", control->max_time, control->wish_time);*/
222224
223225 for (unsigned int depth = 1 ; depth <= control -> max_depth ;){
224226 clock_t curr_time = clock ();
225227 memset (sPV , 0 , SPVLEN );
226228 control -> node_count = 0 ;
227229
228230 eval = AlphaBeta (board , depth , alpha , beta , 0 , control , 1 , killers );
229- if (control -> stop ){
231+ if (control -> stop && ! control -> ponder ){
230232 break ;
231233 }
232234 pvlen = RetrievePV (board , iPV , depth + 10 );
@@ -253,8 +255,9 @@ void IterativeDeep(BOARD *board, CONTROL *control)
253255 alpha = - INFINITE ;
254256 beta = INFINITE ;
255257 }else {
256- if (3 * curr_time > control -> wish_time - (clock ()- control -> init_time )
257- && !control -> ponder ) break ;
258+ if (3 * curr_time > control -> wish_time * CPMS - (clock ()- control -> init_time )){
259+ control -> stop = 1 ;
260+ }
258261 alpha = eval - ASP_WINDOW ;
259262 beta = eval + ASP_WINDOW ;
260263 depth ++ ;
0 commit comments