@@ -393,48 +393,45 @@ void Search::search_root(Depth depth, int alpha, int beta) {
393
393
int Search::search (Depth depth, int alpha, int beta, int ply) {
394
394
// Check TTable before anything else is done.
395
395
auto entry = ttable.probe (position.zobrist_key );
396
- if (entry != nullptr ) {
397
- if (entry->depth () >= depth) {
398
-
399
- switch (entry->bound ()) {
400
-
401
- case Bound::EXACT:
402
- // In the case of exact scores, we can always return
403
- // right away. Just update best move if we exceed alpha.
404
- if (entry->value () > alpha)
405
- save_pv (entry->move (), pv[ply + 1 ], pv[ply]);
406
- update_search (ply);
407
- return entry->value ();
408
-
409
- case Bound::LOWER:
410
- // With a lower bound we check if we should update alpha.
411
- // After all this we
412
- if (entry->value () > alpha) {
413
- save_pv (entry->move (), pv[ply + 1 ], pv[ply]);
414
- alpha = entry->value ();
415
-
416
- // Check for zero-size search window.
417
- if (entry->value () >= beta) {
418
- update_search (ply);
419
- return entry->value ();
420
- }
421
- }
422
- break ;
423
-
424
- case Bound::UPPER:
425
- // For upper bounds, we can stop if the bound
426
- // is leq than alpha because no move will improve alpha.
427
- // If alpha < bound we have no usefull info, as the
428
- // exact value could still be less than alpha, so we
429
- // cannot update alpha and pv yet.
430
- if (entry->value () <= alpha) {
396
+ if (entry != nullptr and entry->depth () >= depth) {
397
+ switch (entry->bound ()) {
398
+
399
+ case Bound::EXACT:
400
+ // In the case of exact scores, we can always return
401
+ // right away. Just update best move if we exceed alpha.
402
+ if (entry->value () > alpha)
403
+ save_pv (entry->move (), pv[ply + 1 ], pv[ply]);
404
+ update_search (ply);
405
+ return entry->value ();
406
+
407
+ case Bound::LOWER:
408
+ // With a lower bound we check if we should update alpha.
409
+ // After all this we
410
+ if (entry->value () > alpha) {
411
+ save_pv (entry->move (), pv[ply + 1 ], pv[ply]);
412
+ alpha = entry->value ();
413
+
414
+ // Check for zero-size search window.
415
+ if (entry->value () >= beta) {
431
416
update_search (ply);
432
417
return entry->value ();
433
418
}
434
- break ;
435
- default :
436
- throw std::exception ();
437
- }
419
+ }
420
+ break ;
421
+
422
+ case Bound::UPPER:
423
+ // For upper bounds, we can stop if the bound
424
+ // is leq than alpha because no move will improve alpha.
425
+ // If alpha < bound we have no usefull info, as the
426
+ // exact value could still be less than alpha, so we
427
+ // cannot update alpha and pv yet.
428
+ if (entry->value () <= alpha) {
429
+ update_search (ply);
430
+ return entry->value ();
431
+ }
432
+ break ;
433
+ default :
434
+ throw std::exception ();
438
435
}
439
436
}
440
437
@@ -500,6 +497,15 @@ int Search::search(Depth depth, int alpha, int beta, int ply) {
500
497
}
501
498
502
499
MoveList<MoveEntry> &moves = move_generators[ply].get_moves (position, depth, is_check);
500
+
501
+ // Killer Move Heuristic:
502
+ // If lookup didn't cause a cutoff, including if we don't have the required depth to use
503
+ // the table entry, lets use the stored move as a killer move,
504
+ // searching it first in the hopes that it will lead to more cutoffs.
505
+ if (entry != nullptr and entry->move () != Move::NO_MOVE) {
506
+ moves.add_killer (entry->move ());
507
+ }
508
+
503
509
for (int i = 0 ; i < moves.size ; i++) {
504
510
Move move = moves.entries [i]->move ;
505
511
int value = best_value;
0 commit comments