Skip to content

Commit

Permalink
Allow SF to find mates more easily.
Browse files Browse the repository at this point in the history
Bench: 7698608
  • Loading branch information
jhellis3 committed Nov 30, 2014
1 parent 314d446 commit c6c152e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/movegen.cpp
Expand Up @@ -416,3 +416,22 @@ ExtMove* generate<LEGAL>(const Position& pos, ExtMove* mlist) {

return end;
}

template<>
ExtMove* generate<KING_MOVES>(const Position& pos, ExtMove* mlist) {

ExtMove *end, *cur = mlist;
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
Square ksq = pos.king_square(pos.side_to_move());

end = pos.checkers() ? generate<EVASIONS>(pos, mlist)
: generate<NON_EVASIONS>(pos, mlist);
while (cur != end)
if ( from_sq(cur->move) == ksq
&& pos.legal(cur->move, pinned))
++cur;
else
cur->move = (--end)->move;

return end;
}
3 changes: 2 additions & 1 deletion src/movegen.h
Expand Up @@ -28,7 +28,8 @@ enum GenType {
QUIET_CHECKS,
EVASIONS,
NON_EVASIONS,
LEGAL
LEGAL,
KING_MOVES
};

class Position;
Expand Down
6 changes: 6 additions & 0 deletions src/search.cpp
Expand Up @@ -621,6 +621,7 @@ namespace {
// Step 6. Razoring (skipped when in check)
if ( !PvNode
&& depth < 4 * ONE_PLY
&& abs(eval) < VALUE_MATE_IN_MAX_PLY
&& eval + razor_margin(depth) <= alpha
&& ttMove == MOVE_NONE
&& !pos.pawn_on_7th(pos.side_to_move()))
Expand Down Expand Up @@ -649,6 +650,7 @@ namespace {
&& !ss->skipNullMove
&& depth >= 2 * ONE_PLY
&& eval >= beta
&& abs(eval) < VALUE_MATE_IN_MAX_PLY
&& pos.non_pawn_material(pos.side_to_move()))
{
ss->currentMove = MOVE_NULL;
Expand All @@ -674,6 +676,9 @@ namespace {
if (depth < 12 * ONE_PLY && abs(beta) < VALUE_KNOWN_WIN)
return nullValue;

if (MoveList<KING_MOVES>(pos).size() < 1 || MoveList<LEGAL>(pos).size() < 6)
R = DEPTH_ZERO;

// Do verification search at high depths
ss->skipNullMove = true;
Value v = depth-R < ONE_PLY ? qsearch<NonPV, false>(pos, ss, beta-1, beta, DEPTH_ZERO)
Expand All @@ -692,6 +697,7 @@ namespace {
if ( !PvNode
&& depth >= 5 * ONE_PLY
&& !ss->skipNullMove
&& abs(eval) < VALUE_MATE_IN_MAX_PLY
&& abs(beta) < VALUE_MATE_IN_MAX_PLY)
{
Value rbeta = std::min(beta + 200, VALUE_INFINITE);
Expand Down

3 comments on commit c6c152e

@bunkbail
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could measure its ELO impact by scheduling a fixed 40k games test?

@mcostalba
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate<KING_MOVES>() can be greatly speed up generating only king moves instead of generating all the moves and filter them out later. But this is just a minor optimization because you call it only at high depths.

@cuddlestmonkey
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this ever tested in framework? Apologies if there is some easy way to find out..

Please sign in to comment.