search: fixed a bug in NULL move pruning
[owl.git] / extensions.c
blob2f8db11a6148e9c9a45a8c16029df9e91b2c83aa
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 #include "common.h"
17 #include "attacks.h"
18 #include "board.h"
19 #include "engine.h"
20 #include "move.h"
22 #define DEF_LMR_EXTEND_CHECK 1
23 #define DEF_LMR_REDUCE -1
25 /* check if we should extend or can reduce search */
26 int
27 get_extensions(int move, int in_check, int move_is_check, int depth, int ply)
29 assert(move);
30 assert(in_check == TRUE || in_check == FALSE);
31 assert(move_is_check == TRUE || move_is_check == FALSE);
32 assert(depth >= 0 && depth <= MAX_PLY);
33 assert(ply >= 0 && ply <= MAX_PLY);
35 /* extend if we are in check */
36 if (in_check)
37 return DEF_LMR_EXTEND_CHECK;
39 /* don't reduce checks, tactical moves, killers, moves from transposition
40 table and all moves at low depth */
41 if (!e.lmr || move_is_check || depth < 3 || MOVE_IS_TACTICAL(move) || \
42 move == killers[ply].killer1 || move == killers[ply].killer2 || \
43 move == killers[ply].mate_killer || move == hash_moves[ply])
44 return 0;
46 /* don't reduce passed pawn moves */
47 if (square64[GET_TO(move)] == PAWN)
48 if (!(PAWNS(brd.wtm) & passer_mask[1 ^ brd.wtm][GET_TO(move)]))
49 return 0;
51 #ifdef STATISTIC_COUNTERS
52 counters.reductions++;
53 #endif
54 /* reduce search depth */
55 return DEF_LMR_REDUCE;