]> git.sesse.net Git - stockfish/blob - src/movepick.h
66518ac76861fff4d34a41078e89fa690631100d
[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 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 <<<<<<< HEAD:src/movepick.h
11
12 =======
13   
14 >>>>>>> d3600c39a745179ed6b094b305d0645e83a1ee86:src/movepick.h
15   Stockfish is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   GNU General Public License for more details.
19
20   You should have received a copy of the GNU General Public License
21   along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 */
23
24
25 #if !defined MOVEPICK_H_INCLUDED
26 #define MOVEPICK_H_INCLUDED
27
28 ////
29 //// Includes
30 ////
31
32 #include "depth.h"
33 #include "lock.h"
34 #include "position.h"
35
36
37 ////
38 //// Types
39 ////
40
41 /// MovePicker is a class which is used to pick one legal move at a time from
42 /// the current position.  It is initialized with a Position object and a few
43 /// moves we have reason to believe are good.  The most important method is
44 /// MovePicker::pick_next_move(), which returns a new legal move each time it
45 /// is called, until there are no legal moves left, when MOVE_NONE is returned.
46 /// In order to improve the efficiency of the alpha beta algorithm, MovePicker
47 /// attempts to return the moves which are most likely to be strongest first.
48
49 class MovePicker {
50
51 public:
52
53   enum MovegenPhase {
54     PH_TT_MOVE,        // Transposition table move
55     PH_MATE_KILLER,    // Mate killer from the current ply
56     PH_GOOD_CAPTURES,  // Queen promotions and captures with SEE values >= 0
57     PH_BAD_CAPTURES,   // Queen promotions and captures with SEE valuse <= 0
58     PH_KILLER_1,       // Killer move 1 from the current ply (not used yet).
59     PH_KILLER_2,       // Killer move 2 from the current ply (not used yet).
60     PH_NONCAPTURES,    // Non-captures and underpromotions
61     PH_EVASIONS,       // Check evasions
62     PH_QCAPTURES,      // Captures in quiescence search
63     PH_QCHECKS,        // Checks in quiescence search
64     PH_STOP
65   };
66
67   MovePicker(const Position& p, bool pvnode, Move ttm, Move mk, Move k1, Move k2, Depth d);
68   Move get_next_move();
69   Move get_next_move(Lock &lock);
70   int number_of_moves() const;
71   int current_move_score() const;
72   MovegenPhase current_move_type() 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   int find_best_index();
84
85   const Position& pos;
86   Move ttMove, mateKiller, killer1, killer2;
87   Bitboard pinned, dc;
88   MoveStack moves[256], badCaptures[64];
89   bool pvNode;
90   Depth depth;
91   int phaseIndex;
92   int numOfMoves, numOfBadCaptures;
93   int movesPicked, badCapturesPicked;
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
109   return numOfMoves;
110 }
111
112 /// MovePicker::discovered_check_candidates() returns a bitboard containing
113 /// all pieces which can possibly give discovered check.  This bitboard is
114 /// computed by the constructor function.
115
116 inline Bitboard MovePicker::discovered_check_candidates() const {
117   return dc;
118 }
119
120 #endif // !defined(MOVEPICK_H_INCLUDED)