]> git.sesse.net Git - stockfish/blob - src/movepick.h
3d87b9c3b5c7998121366efb615f58525247d5f5
[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-2009 Marco Costalba
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 "lock.h"
30 #include "position.h"
31
32
33 ////
34 //// Types
35 ////
36
37 struct EvalInfo;
38 struct SearchStack;
39
40 extern SearchStack EmptySearchStack;
41
42 /// MovePicker is a class which is used to pick one legal move at a time from
43 /// the current position. It is initialized with a Position object and a few
44 /// moves we have reason to believe are good. The most important method is
45 /// MovePicker::pick_next_move(), which returns a new legal move each time it
46 /// is called, until there are no legal moves left, when MOVE_NONE is returned.
47 /// In order to improve the efficiency of the alpha beta algorithm, MovePicker
48 /// attempts to return the moves which are most likely to be strongest first.
49
50 class MovePicker {
51
52   MovePicker& operator=(const MovePicker&); // silence a warning under MSVC
53
54 public:
55
56   enum MovegenPhase {
57     PH_TT_MOVE,        // Transposition table move
58     PH_MATE_KILLER,    // Mate killer from the current ply
59     PH_GOOD_CAPTURES,  // Queen promotions and captures with SEE values >= 0
60     PH_KILLERS,        // Killer moves from the current ply
61     PH_NONCAPTURES,    // Non-captures and underpromotions
62     PH_BAD_CAPTURES,   // Queen promotions and captures with SEE values < 0
63     PH_EVASIONS,       // Check evasions
64     PH_QCAPTURES,      // Captures in quiescence search
65     PH_QCHECKS,        // Non-capture checks in quiescence search
66     PH_STOP
67   };
68
69   MovePicker(const Position& p, bool pvnode, Move ttm, const SearchStack& ss, Depth d);
70   Move get_next_move();
71   Move get_next_move(Lock& lock);
72   int number_of_moves() const;
73   Bitboard discovered_check_candidates() const;
74
75   static void init_phase_table();
76
77 private:
78   void score_captures();
79   void score_noncaptures();
80   void score_evasions();
81   void score_qcaptures();
82   Move pick_move_from_list();
83
84   const Position& pos;
85   Move ttMove, mateKiller, killer1, killer2;
86   Bitboard pinned, dc;
87   MoveStack moves[256], badCaptures[64];
88   bool pvNode;
89   Depth depth;
90   int phaseIndex;
91   int numOfMoves, numOfBadCaptures;
92   int movesPicked;
93   bool checkKillers, checkLegal;
94   bool finished;
95 };
96
97
98 ////
99 //// Inline functions
100 ////
101
102 /// MovePicker::number_of_moves() simply returns the numOfMoves member
103 /// variable. It is intended to be used in positions where the side to move
104 /// is in check, for detecting checkmates or situations where there is only
105 /// a single reply to check.
106
107 inline int MovePicker::number_of_moves() const {
108   return numOfMoves;
109 }
110
111 /// MovePicker::discovered_check_candidates() returns a bitboard containing
112 /// all pieces which can possibly give discovered check. This bitboard is
113 /// computed by the constructor function.
114
115 inline Bitboard MovePicker::discovered_check_candidates() const {
116   return dc;
117 }
118
119 #endif // !defined(MOVEPICK_H_INCLUDED)