Rev 33 | Rev 154 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 33 | Rev 108 | ||
|---|---|---|---|
| Line 10... | Line 10... | ||
| 10 | * amount of time used, and then makes any necessary adjustments based on * |
10 | * amount of time used, and then makes any necessary adjustments based on * |
| 11 | * the time controls. * |
11 | * the time controls. * |
| 12 | * * |
12 | * * |
| 13 | ******************************************************************************* |
13 | ******************************************************************************* |
| 14 | */ |
14 | */ |
| 15 | void TimeAdjust(int |
15 | void TimeAdjust(int side, int time_used) { |
| 16 | /* |
16 | /* |
| 17 | ************************************************************ |
17 | ************************************************************ |
| 18 | * * |
18 | * * |
| 19 | * Decrement the number of moves remaining to the next * |
19 | * Decrement the number of moves remaining to the next * |
| 20 | * time control. Then subtract the time the program took * |
20 | * time control. Then subtract the time the program took * |
| Line 35... | Line 35... | ||
| 35 | } |
35 | } |
| 36 | if (tc_increment) |
36 | if (tc_increment) |
| 37 | tc_time_remaining[side] += tc_increment; |
37 | tc_time_remaining[side] += tc_increment; |
| 38 | } |
38 | } |
| 39 | 39 | ||
| 40 | /* last modified |
40 | /* last modified 10/01/14 */ |
| 41 | /* |
41 | /* |
| 42 | ******************************************************************************* |
42 | ******************************************************************************* |
| 43 | * * |
43 | * * |
| 44 | * TimeCheck() is used to determine when the search should stop. It uses * |
44 | * TimeCheck() is used to determine when the search should stop. It uses * |
| 45 | * several conditions to make this determination: (1) The search time has * |
45 | * several conditions to make this determination: (1) The search time has * |
| Line 113... | Line 113... | ||
| 113 | * time has been used so far. * |
113 | * time has been used so far. * |
| 114 | * * |
114 | * * |
| 115 | ************************************************************ |
115 | ************************************************************ |
| 116 | */ |
116 | */ |
| 117 | time_used = (ReadClock() - start_time); |
117 | time_used = (ReadClock() - start_time); |
| 118 | if ( |
118 | if (time_used >= (int) noise_level && display_options & 16 && time_used > burp) { // Pierre-Marie Baty -- added type cast |
| 119 | time_used > burp) { |
- | |
| 120 | Lock(lock_io); |
119 | Lock(lock_io); |
| 121 | if (pondering) |
120 | if (pondering) |
| 122 | printf(" %2i %s%7s? ", |
121 | printf(" %2i %s%7s? ", iteration, Display2Times(time_used), |
| 123 |
|
122 | tree->remaining_moves_text); |
| 124 | else |
123 | else |
| 125 | printf(" %2i %s%7s* ", |
124 | printf(" %2i %s%7s* ", iteration, Display2Times(time_used), |
| 126 |
|
125 | tree->remaining_moves_text); |
| 127 | if (display_options & |
126 | if (display_options & 16) |
| 128 | printf("%d. ", move_number); |
127 | printf("%d. ", move_number); |
| 129 | if ((display_options & |
128 | if ((display_options & 16) && Flip(root_wtm)) |
| 130 | printf("... "); |
129 | printf("... "); |
| 131 | printf("%s(%snps) \r", tree->root_move_text, |
130 | printf("%s(%snps) \r", tree->root_move_text, |
| 132 | DisplayKMB(nodes_per_second)); |
131 | DisplayKMB(nodes_per_second, 0)); |
| 133 | burp = (time_used / 1500) * 1500 + 1500; |
132 | burp = (time_used / 1500) * 1500 + 1500; |
| 134 | fflush(stdout); |
133 | fflush(stdout); |
| 135 | Unlock(lock_io); |
134 | Unlock(lock_io); |
| 136 | } |
135 | } |
| 137 | /* |
136 | /* |
| Line 144... | Line 143... | ||
| 144 | * actually back up a move to play. * |
143 | * actually back up a move to play. * |
| 145 | * * |
144 | * * |
| 146 | ************************************************************ |
145 | ************************************************************ |
| 147 | */ |
146 | */ |
| 148 | if (n_root_moves == 1 && !booking && !annotate_mode && !pondering && |
147 | if (n_root_moves == 1 && !booking && !annotate_mode && !pondering && |
| 149 |
|
148 | iteration > 1 && (time_used > time_limit || time_used > 100)) |
| 150 | return 1; |
149 | return 1; |
| 151 | if ( |
150 | if (iteration <= 2) |
| 152 | return 0; |
151 | return 0; |
| 153 | /* |
152 | /* |
| 154 | ************************************************************ |
153 | ************************************************************ |
| 155 | * * |
154 | * * |
| 156 | * If we are pondering or in analyze mode, we do not * |
155 | * If we are pondering or in analyze mode, we do not * |
| Line 231... | Line 230... | ||
| 231 | if (time_used + 300 > tc_time_remaining[root_wtm]) |
230 | if (time_used + 300 > tc_time_remaining[root_wtm]) |
| 232 | return 1; |
231 | return 1; |
| 233 | return 0; |
232 | return 0; |
| 234 | } |
233 | } |
| 235 | 234 | ||
| 236 | /* last modified |
235 | /* last modified 09/30/14 */ |
| 237 | /* |
236 | /* |
| 238 | ******************************************************************************* |
237 | ******************************************************************************* |
| 239 | * * |
238 | * * |
| 240 | * TimeSet() is called to set the two variables "time_limit" and * |
239 | * TimeSet() is called to set the two variables "time_limit" and * |
| 241 | * "absolute_time_limit" which controls the amount of time taken by the * |
240 | * "absolute_time_limit" which controls the amount of time taken by the * |
| Line 257... | Line 256... | ||
| 257 | * * |
256 | * * |
| 258 | * Check to see if we are in a sudden-death type of time * |
257 | * Check to see if we are in a sudden-death type of time * |
| 259 | * control. If so, we have a fixed amount of time * |
258 | * control. If so, we have a fixed amount of time * |
| 260 | * remaining. Set the search time accordingly and exit. * |
259 | * remaining. Set the search time accordingly and exit. * |
| 261 | * * |
260 | * * |
| - | 261 | * The basic algorithm is to divide the remaining time * |
|
| 262 | * |
262 | * left on the clock by a constant (that is larger for * |
| - | 263 | * ponder=off games since we don't get to ponder and save * |
|
| 263 | * the |
264 | * time as the game progresses) and add the increment. * |
| 264 | * * |
265 | * * |
| 265 | * If we have less than 2.5 seconds on the clock prior to * |
- | |
| 266 | * the increment, then limit our search to half the * |
- | |
| 267 | * increment in an attempt to add some time to our buffer. * |
- | |
| 268 | * * |
- | |
| 269 | * Set our MAX search time to |
266 | * Set our MAX search time to the smaller of 5 * the time * |
| 270 | * * |
- | |
| 271 | * If our search time will drop the clock below 1 second, * |
- | |
| 272 | * |
267 | * limit or 1/2 of the time left on the clock. * |
| 273 | * time. This is done to stop any extensions from * |
- | |
| 274 | * dropping us too low. * |
- | |
| 275 | * * |
268 | * * |
| 276 | ************************************************************ |
269 | ************************************************************ |
| 277 | */ |
270 | */ |
| 278 | if (tc_sudden_death == 1) { |
271 | if (tc_sudden_death == 1) { |
| 279 | if (tc_increment) { |
- | |
| 280 |
|
272 | time_limit = |
| 281 |
|
273 | (tc_time_remaining[root_wtm] - |
| 282 | tc_operator_time * tc_moves_remaining[root_wtm]) / |
- | |
| 283 |
|
274 | tc_safety_margin) / (ponder ? 20 : 26) + tc_increment; |
| 284 | if (tc_time_remaining[root_wtm] < 500 + tc_increment) { |
- | |
| 285 | time_limit = tc_increment; |
- | |
| 286 | if (tc_time_remaining[root_wtm] < 250 + tc_increment) |
- | |
| 287 | time_limit /= 2; |
- | |
| 288 | } |
- | |
| 289 | absolute_time_limit = tc_time_remaining[root_wtm] / 2 + tc_increment; |
- | |
| 290 | if (absolute_time_limit < time_limit || |
- | |
| 291 | tc_time_remaining[root_wtm] - time_limit < 100) |
- | |
| 292 | absolute_time_limit = time_limit; |
- | |
| 293 | if (tc_time_remaining[root_wtm] - time_limit < 50) { |
- | |
| 294 | time_limit = tc_time_remaining[root_wtm] - 50; |
- | |
| 295 | if (time_limit < 5) |
- | |
| 296 | time_limit = 5; |
- | |
| 297 | } |
- | |
| 298 | if (tc_time_remaining[root_wtm] - absolute_time_limit < 25) { |
- | |
| 299 | absolute_time_limit = tc_time_remaining[root_wtm] - 25; |
- | |
| 300 | if (absolute_time_limit < 5) |
- | |
| 301 | absolute_time_limit = 5; |
- | |
| 302 | } |
- | |
| 303 | - | ||
| 304 | } else { |
- | |
| 305 | time_limit = tc_time_remaining[root_wtm] / (ponder ? 20 : 26); |
- | |
| 306 |
|
275 | absolute_time_limit = |
| 307 |
|
276 | Min(time_limit * 5, tc_time_remaining[root_wtm] / 2); |
| 308 | } |
- | |
| 309 | } |
277 | } |
| 310 | /* |
278 | /* |
| 311 | ************************************************************ |
279 | ************************************************************ |
| 312 | * * |
280 | * * |
| 313 | * We are not in a sudden_death situation. We now have * |
281 | * We are not in a sudden_death situation. We now have * |
| 314 | * two choices: If the program has saved enough time to * |
282 | * two choices: If the program has saved enough time to * |
| 315 | * meet the surplus requirement, then we simply divide * |
283 | * meet the surplus requirement, then we simply divide * |
| 316 | * the time left evenly among the moves left. If we * |
284 | * the time left evenly among the moves left. If we * |
| 317 | * haven't yet saved up a cushion so that " |
285 | * haven't yet saved up a cushion so that "hard-moves" * |
| 318 | * |
286 | * can be searched more thoroughly, we simply take the * |
| 319 | * number of moves divided into the total time |
287 | * number of moves divided into the total time as the * |
| 320 | * |
288 | * target. * |
| 321 | * * |
289 | * * |
| 322 | ************************************************************ |
290 | ************************************************************ |
| 323 | */ |
291 | */ |
| 324 | else { |
292 | else { |
| 325 | if (move_number <= tc_moves) |
293 | if (move_number <= tc_moves) |
| 326 | simple_average = |
- | |
| 327 | (tc_time - |
- | |
| 328 |
|
294 | simple_average = (tc_time - tc_safety_margin) / tc_moves; |
| 329 | else |
295 | else |
| 330 | simple_average = |
296 | simple_average = |
| 331 | (tc_secondary_time - |
- | |
| 332 | ( |
297 | (tc_secondary_time - tc_safety_margin) / tc_secondary_moves; |
| 333 | tc_secondary_moves; |
- | |
| 334 | surplus = |
298 | surplus = |
| 335 | Max(tc_time_remaining[root_wtm] - |
299 | Max(tc_time_remaining[root_wtm] - tc_safety_margin - |
| 336 | (tc_operator_time * tc_moves_remaining[root_wtm]) - |
- | |
| 337 | simple_average * tc_moves_remaining[root_wtm], 0); |
300 | simple_average * tc_moves_remaining[root_wtm], 0); |
| 338 | average = |
301 | average = |
| 339 | (tc_time_remaining[root_wtm] - |
302 | (tc_time_remaining[root_wtm] - tc_safety_margin + |
| 340 | (tc_operator_time * tc_moves_remaining[root_wtm]) + |
- | |
| 341 | tc_moves_remaining[root_wtm] * tc_increment) |
303 | tc_moves_remaining[root_wtm] * tc_increment) |
| 342 | / tc_moves_remaining[root_wtm]; |
304 | / tc_moves_remaining[root_wtm]; |
| 343 | if (surplus < tc_safety_margin) |
305 | if (surplus < tc_safety_margin) |
| 344 | time_limit = (average < simple_average) ? average : simple_average; |
306 | time_limit = (average < simple_average) ? average : simple_average; |
| 345 | else |
307 | else |
| 346 | time_limit = |
308 | time_limit = |
| 347 | (average < 2 |
309 | (average < 2 * simple_average) ? average : 2 * simple_average; // Pierre-Marie Baty -- fixed types |
| 348 | } |
310 | } |
| 349 | if (surplus < 0) |
- | |
| 350 | surplus = 0; |
- | |
| 351 | if (tc_increment > 200 && moves_out_of_book < 2) |
311 | if (tc_increment > 200 && moves_out_of_book < 2) |
| 352 |
|
312 | time_limit = (int) (time_limit * 1.2); // Pierre-Marie Baty -- added type cast |
| 353 | if (time_limit <= 0) |
313 | if (time_limit <= 0) |
| 354 | time_limit = 5; |
314 | time_limit = 5; |
| 355 | absolute_time_limit = |
315 | absolute_time_limit = |
| 356 | time_limit + surplus / 2 + |
316 | time_limit + surplus / 2 + (tc_time_remaining[root_wtm] - |
| 357 |
|
317 | tc_safety_margin) / 4; |
| 358 | if (absolute_time_limit > |
318 | if (absolute_time_limit > 5 * time_limit) |
| 359 | absolute_time_limit = |
319 | absolute_time_limit = 5 * time_limit; |
| 360 | if (absolute_time_limit > tc_time_remaining[root_wtm] / 2) |
320 | if (absolute_time_limit > tc_time_remaining[root_wtm] / 2) |
| 361 | absolute_time_limit = tc_time_remaining[root_wtm] / 2; |
321 | absolute_time_limit = tc_time_remaining[root_wtm] / 2; |
| 362 | /* |
322 | /* |
| 363 | ************************************************************ |
323 | ************************************************************ |
| 364 | * * |
324 | * * |
| Line 370... | Line 330... | ||
| 370 | * and instant moves. * |
330 | * and instant moves. * |
| 371 | * * |
331 | * * |
| 372 | ************************************************************ |
332 | ************************************************************ |
| 373 | */ |
333 | */ |
| 374 | if (usage_level) |
334 | if (usage_level) |
| 375 |
|
335 | time_limit = (int) (time_limit * (1.0 + usage_level / 100.0)); // Pierre-Marie Baty -- added type cast |
| 376 | if (first_nonbook_factor && moves_out_of_book < first_nonbook_span) { |
336 | if (first_nonbook_factor && moves_out_of_book < first_nonbook_span) { |
| 377 | mult = |
337 | mult = |
| 378 | (first_nonbook_span - moves_out_of_book + 1) * first_nonbook_factor; |
338 | (first_nonbook_span - moves_out_of_book + 1) * first_nonbook_factor; |
| 379 | extra = time_limit * mult / first_nonbook_span / 100; |
339 | extra = time_limit * mult / first_nonbook_span / 100; |
| 380 | time_limit += extra; |
340 | time_limit += extra; |
| Line 399... | Line 359... | ||
| 399 | time_limit > 3 * tc_time / tc_moves) |
359 | time_limit > 3 * tc_time / tc_moves) |
| 400 | time_limit = 3 * tc_time / tc_moves; |
360 | time_limit = 3 * tc_time / tc_moves; |
| 401 | time_limit = Min(time_limit, absolute_time_limit); |
361 | time_limit = Min(time_limit, absolute_time_limit); |
| 402 | if (search_type != puzzle) { |
362 | if (search_type != puzzle) { |
| 403 | if (!tc_sudden_death) |
363 | if (!tc_sudden_death) |
| 404 | Print( |
364 | Print(32, " time surplus %s ", DisplayTime(surplus)); |
| 405 | else |
365 | else |
| 406 | Print( |
366 | Print(32, " "); |
| 407 | Print( |
367 | Print(32, "time limit %s", DisplayTimeKibitz(time_limit)); |
| 408 | Print(128, " (+%s)", DisplayTimeKibitz(extra)); |
- | |
| 409 | Print( |
368 | Print(32, " (%s)\n", DisplayTimeKibitz(absolute_time_limit)); |
| 410 | if (fabs(usage_level) > 0.0001) { |
- | |
| 411 | Print(128, "/"); |
- | |
| 412 | Print(128, "(%d)", usage_level); |
- | |
| 413 | } |
- | |
| 414 | Print(128, "\n"); |
- | |
| 415 | } |
369 | } |
| 416 | if (time_limit <= 1) { |
370 | if (time_limit <= 1) { |
| 417 | time_limit = 1; |
371 | time_limit = 1; |
| 418 | usage_level = 0; |
372 | usage_level = 0; |
| 419 | } |
373 | } |