]> git.sesse.net Git - stockfish/blob - src/movepick.h
Use fail soft in null search
[stockfish] / src / movepick.h
1 /*
2   Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3   Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
4   Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
5
6   Stockfish is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   Stockfish is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21 #if !defined MOVEPICK_H_INCLUDED
22 #define MOVEPICK_H_INCLUDED
23
24 ////
25 //// Includes
26 ////
27
28 #include "depth.h"
29 #include "history.h"
30 #include "position.h"
31
32
33 ////
34 //// Types
35 ////
36
37 struct SearchStack;
38
39 /// MovePicker is a class which is used to pick one legal move at a time from
40 /// the current position. It is initialized with a Position object and a few
41 /// moves we have reason to believe are good. The most important method is
42 /// MovePicker::pick_next_move(), which returns a new legal move each time it
43 /// is called, until there are no legal moves left, when MOVE_NONE is returned.
44 /// In order to improve the efficiency of the alpha beta algorithm, MovePicker
45 /// attempts to return the moves which are most likely to be strongest first.
46
47 class MovePicker {
48
49   MovePicker& operator=(const MovePicker&); // silence a warning under MSVC
50
51 public:
52   MovePicker(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss = NULL, Value beta = -VALUE_INFINITE);
53   Move get_next_move();
54   int number_of_evasions() const;
55
56 private:
57   void score_captures();
58   void score_noncaptures();
59   void score_evasions_or_checks();
60   void go_next_phase();
61
62   const Position& pos;
63   const History& H;
64   MoveStack ttMoves[2], killers[2];
65   int badCaptureThreshold, phase;
66   const uint8_t* phasePtr;
67   MoveStack *curMove, *lastMove, *lastGoodNonCapture, *lastBadCapture;
68   Bitboard pinned;
69   MoveStack moves[256], badCaptures[64];
70 };
71
72
73 ////
74 //// Inline functions
75 ////
76
77 /// MovePicker::number_of_evasions() simply returns the number of moves in
78 /// evasions phase. It is intended to be used in positions where the side to
79 /// move is in check, for detecting checkmates or situations where there is
80 /// only a single reply to check.
81 /// WARNING: It works as long as PH_EVASIONS is the _only_ phase for evasions.
82
83 inline int MovePicker::number_of_evasions() const {
84   return int(lastMove - moves);
85 }
86
87 #endif // !defined(MOVEPICK_H_INCLUDED)