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