From a408dc2356fa5efdaa00f59457dac46f8296bf4c Mon Sep 17 00:00:00 2001 From: Daniel Dugovic Date: Sat, 31 Dec 2016 15:24:44 -0600 Subject: [PATCH] Avoid expensive crazyhouse null-move searches (resolves #148) --- src/position.h | 6 ++++-- src/search.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/position.h b/src/position.h index 02dfef18ea3..0c355026bea 100644 --- a/src/position.h +++ b/src/position.h @@ -634,10 +634,12 @@ inline int Position::count_in_hand(Color c, PieceType pt) const { inline void Position::add_to_hand(Color c, PieceType pt) { pieceCountInHand[c][pt]++; + pieceCountInHand[c][ALL_PIECES]++; } inline void Position::remove_from_hand(Color c, PieceType pt) { pieceCountInHand[c][pt]--; + pieceCountInHand[c][ALL_PIECES]--; } inline bool Position::is_promoted(Square s) const { @@ -807,13 +809,13 @@ inline void Position::move_piece(Piece pc, Square from, Square to) { inline void Position::drop_piece(Piece pc, Square s) { assert(pieceCountInHand[color_of(pc)][type_of(pc)]); put_piece(pc, s); - pieceCountInHand[color_of(pc)][type_of(pc)]--; + remove_from_hand(color_of(pc), type_of(pc)); } inline void Position::undrop_piece(Piece pc, Square s) { remove_piece(pc, s); board[s] = NO_PIECE; - pieceCountInHand[color_of(pc)][type_of(pc)]++; + add_to_hand(color_of(pc), type_of(pc)); assert(pieceCountInHand[color_of(pc)][type_of(pc)]); } #endif diff --git a/src/search.cpp b/src/search.cpp index 7665bf68159..1789322711e 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -975,7 +975,14 @@ namespace { if ( !PvNode && eval >= beta && (ss->staticEval >= beta - 35 * (depth / ONE_PLY - 6) || depth >= 13 * ONE_PLY) +#ifdef CRAZYHOUSE + // Do not bother with null-move search if opponent can drop pieces + && (pos.is_house() ? (eval < 2 * VALUE_KNOWN_WIN + && !(depth > 4 * ONE_PLY && pos.count_in_hand(~pos.side_to_move(), ALL_PIECES))) : + pos.non_pawn_material(pos.side_to_move()))) +#else && pos.non_pawn_material(pos.side_to_move())) +#endif { ss->currentMove = MOVE_NULL; ss->counterMoves = nullptr;