Skip to content

Commit

Permalink
handle insufficient material draws
Browse files Browse the repository at this point in the history
no measurable elo gain
  • Loading branch information
connormcmonigle committed Oct 18, 2020
1 parent 048f25f commit 5548dc4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 18 additions & 0 deletions include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,24 @@ struct board{
return turn() ? is_passed_push_<color::white>(mv) : is_passed_push_<color::black>(mv);
}

template<color c>
size_t side_num_pieces() const {
return man_.us<c>().pawn().count() +
man_.us<c>().knight().count() +
man_.us<c>().bishop().count() +
man_.us<c>().rook().count() +
man_.us<c>().queen().count() +
man_.us<c>().king().count();
}

size_t num_pieces() const {
return side_num_pieces<color::white>() + side_num_pieces<color::black>();
}

bool is_trivially_drawn() const {
return (num_pieces() == 2) || ((num_pieces() == 3) && (man_.white.knight() | man_.white.bishop() | man_.black.knight() | man_.black.bishop()).any());
}

template<color c>
board forward_(const move& mv) const {
auto cpy = *this;
Expand Down
4 changes: 3 additions & 1 deletion include/thread_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct thread_worker{
if(all_list.size() == 0 && is_check){ return mate_score<T>; }
if(all_list.size() == 0) { return draw_score<T>; }
if(ss.is_three_fold(bd.hash())){ return draw_score<T>; }
if(bd.is_trivially_drawn()){ return draw_score<T>; }

const auto list = is_check ? all_list : all_list.loud();
auto orderer = move_orderer(move_orderer_data{move::null(), move::null(), move::null(), &bd, list, &hh_.us(bd.turn())});
Expand Down Expand Up @@ -131,6 +132,7 @@ struct thread_worker{
if(list.size() == 0 && is_check){ return make_result(mate_score<T>, move::null()); }
if(list.size() == 0) { return make_result(draw_score<T>, move::null()); }
if(ss.is_three_fold(bd.hash())){ return make_result(draw_score<T>, move::null()); }
if(!is_root && bd.is_trivially_drawn()){ return make_result(draw_score<T>, move::null()); }

// don't drop into qsearch if in check
if(is_check && depth <= 0){ depth = 1; }
Expand Down Expand Up @@ -175,7 +177,7 @@ struct thread_worker{
// step 6. static null move pruning
const bool snm_prune =
!is_root && !is_pv &&
!is_check &&
!is_check &&
depth <= constants_ -> snmp_depth() &&
static_eval > beta + constants_ -> snmp_margin<T>(improving, depth) &&
static_eval > mate_score<T>;
Expand Down

0 comments on commit 5548dc4

Please sign in to comment.