@@ -44,8 +44,7 @@ static int RetrievePV(BOARD *board, MOVE *PV, unsigned int depth)
4444 unsigned int PVlen = 0 ;
4545 MOVE mov = GetHashMove (& hash_table , board -> zobrist_key );
4646 while (mov && PVlen <= depth && IsLegal (board , & mov )){
47- PV [PVlen ] = mov ;
48- PVlen ++ ;
47+ PV [PVlen ++ ] = mov ;
4948 MakeMove (board , & mov );
5049 mov = GetHashMove (& hash_table , board -> zobrist_key );
5150 }
@@ -74,7 +73,11 @@ static int Quiescent(BOARD *board, int alpha, int beta, CONTROL *control)
7473 int nposs_movs , nlegal = 0 ;
7574 int val ;
7675 MOVE poss_moves [MAXMOVES ];
77-
76+
77+ if (!control -> ponder && clock () - control -> init_time >= control -> max_time * CPMS ){
78+ control -> stop = 1 ;
79+ }
80+
7881 val = LazyEval (board );
7982 if (val - LAZYBETA >= beta ) return beta ;
8083 if (val + LAZYALPHA < alpha ) return alpha ;
@@ -109,7 +112,7 @@ static int Quiescent(BOARD *board, int alpha, int beta, CONTROL *control)
109112static int AlphaBeta (BOARD * board , unsigned int depth , int alpha , int beta ,
110113 int root , CONTROL * control , char skip_null , MOVE killers [][2 ])
111114{
112- int nposs_movs , nlegal = 0 ;
115+ int nmoves , nlegal = 0 ;
113116 MOVE poss_moves [MAXMOVES ];
114117 MOVE best_move = 0 ;
115118 char str_mov [MVLEN ];
@@ -131,16 +134,19 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
131134 Takeback (board , null_mv );
132135 if (val >= beta ) return beta ;
133136 }
134- nposs_movs = MoveGen (board , poss_moves , 1 );
135- SortMoves (board , poss_moves , nposs_movs , killers [root ]);
136- for (int i = 0 ; i < nposs_movs ; i ++ ){
137+ nmoves = MoveGen (board , poss_moves , 1 );
138+ SortMoves (board , poss_moves , nmoves , killers [root ]);
139+ for (int i = 0 ; i < nmoves ; i ++ ){
137140 MakeMove (board , & poss_moves [i ]);
138141 control -> node_count ++ ;
139142 if (!LeftInCheck (board )){
140- if (root == 0 && depth > 6 ){
141- MoveToAlgeb (poss_moves [i ], str_mov );
142- printf ("info depth %i hashfull %i currmove %s currmovenumber %i\n" ,
143- depth , hash_table .full /(hash_table .size /1000 ), str_mov , i + 1 );
143+ if (root == 0 ){
144+ if (!control -> best_move ) control -> best_move = poss_moves [0 ]; /* Better than nothing. */
145+ if (depth > 6 && !control -> ponder ){
146+ MoveToAlgeb (poss_moves [i ], str_mov );
147+ printf ("info depth %i hashfull %i currmove %s currmovenumber %i\n" ,
148+ depth , hash_table .full /(hash_table .size /1000 ), str_mov , i + 1 );
149+ }
144150 }
145151 nlegal ++ ;
146152 val = AssesDraw (board );
@@ -153,10 +159,6 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
153159 }else val = - AlphaBeta (board , depth - 1 , - beta , - alpha , root + 1 , control , 0 , killers );
154160 }
155161 Takeback (board , poss_moves [i ]);
156-
157- if (!control -> ponder && clock () - control -> init_time > control -> max_time * CPMS * 0.95 ){
158- control -> stop = 1 ;
159- }
160162 if (control -> stop ) return alpha ;
161163 if (val >= beta ){
162164 UpdateTable (& hash_table , board -> zobrist_key , val , poss_moves [i ], depth , HASH_BETA );
@@ -177,7 +179,7 @@ static int AlphaBeta(BOARD *board, unsigned int depth, int alpha, int beta,
177179 if (root == 0 && !control -> ponder && ((clock () - control -> init_time ) > control -> wish_time * CPMS )){
178180 /* if short of time, don't search anymore after current move */
179181 control -> max_depth = depth ;
180- return alpha ; // val???
182+ return alpha ;
181183 }
182184 }else Takeback (board , poss_moves [i ]);
183185 }
@@ -209,9 +211,10 @@ void IterativeDeep(BOARD *board, CONTROL *control)
209211 int beta = INFINITE ;
210212 unsigned long long nps = 0 ;
211213 MOVE killers [MAXDEPTH ][2 ];
214+ control -> best_move = 0 ;
212215
213216 for (unsigned int depth = 1 ; depth <= control -> max_depth ;){
214- unsigned long long curr_time = clock ();
217+ clock_t curr_time = clock ();
215218 memset (sPV , 0 , SPVLEN );
216219 control -> node_count = 0 ;
217220
@@ -225,19 +228,19 @@ void IterativeDeep(BOARD *board, CONTROL *control)
225228 strcat (sPV , str_mov );
226229 }
227230
228- curr_time = (unsigned long long )(( clock () - curr_time )/CPMS ) ;
231+ curr_time = (clock () - curr_time )/CPMS ;
229232 if (curr_time ){
230233 nps = 1000 * (control -> node_count /curr_time );
231234 }
232235 if (eval > MATE_VALUE /2 && - eval > MATE_VALUE /2 ){
233236 printf ("info depth %u time %llu nodes %llu nps %llu score cp %i pv %s\n" ,
234- depth , curr_time , control -> node_count , nps , eval , sPV );
237+ depth , ( unsigned long long ) curr_time , control -> node_count , nps , eval , sPV );
235238 }else if (- eval < MATE_VALUE /2 ){
236239 printf ("info depth %u time %llu nodes %llu nps %llu score mate %i pv %s\n" ,
237- depth , curr_time , control -> node_count , nps , (pvlen + 1 )/2 , sPV );
240+ depth , ( unsigned long long ) curr_time , control -> node_count , nps , (pvlen + 1 )/2 , sPV );
238241 }else if (eval < MATE_VALUE /2 ){
239242 printf ("info depth %u time %llu nodes %llu nps %llu score mate %i pv %s\n" ,
240- depth , curr_time , control -> node_count , nps , - (pvlen + 1 )/2 , sPV );
243+ depth , ( unsigned long long ) curr_time , control -> node_count , nps , - (pvlen + 1 )/2 , sPV );
241244 }
242245 if (eval <= alpha || eval >= beta ){
243246 alpha = - INFINITE ;
0 commit comments