]> git.sesse.net Git - stockfish/blob - src/movepick.h
movegen: revert see ordering in score_captures()
[stockfish] / src / movepick.h
1 /*
2   Glaurung, a UCI chess playing engine.
3   Copyright (C) 2004-2008 Tord Romstad
4
5   Glaurung is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9   
10   Glaurung is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14   
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20 #if !defined MOVEPICK_H_INCLUDED
21 #define MOVEPICK_H_INCLUDED
22
23 ////
24 //// Includes
25 ////
26
27 #include "depth.h"
28 #include "lock.h"
29 #include "position.h"
30
31
32 ////
33 //// Types
34 ////
35
36 /// MovePicker is a class which is used to pick one legal move at a time from
37 /// the current position.  It is initialized with a Position object and a few
38 /// moves we have reason to believe are good.  The most important method is
39 /// MovePicker::pick_next_move(), which returns a new legal move each time it
40 /// is called, until there are no legal moves left, when MOVE_NONE is returned.
41 /// In order to improve the efficiency of the alpha beta algorithm, MovePicker
42 /// attempts to return the moves which are most likely to be strongest first.
43
44 class MovePicker {
45
46 public:
47
48   enum MovegenPhase {
49     PH_TT_MOVE,        // Transposition table move
50     PH_MATE_KILLER,    // Mate killer from the current ply
51     PH_GOOD_CAPTURES,  // Queen promotions and captures with SEE values >= 0
52     PH_BAD_CAPTURES,   // Queen promotions and captures with SEE valuse <= 0
53     PH_KILLER_1,       // Killer move 1 from the current ply (not used yet).
54     PH_KILLER_2,       // Killer move 2 from the current ply (not used yet).
55     PH_NONCAPTURES,    // Non-captures and underpromotions
56     PH_EVASIONS,       // Check evasions
57     PH_QCAPTURES,      // Captures in quiescence search
58     PH_QCHECKS,        // Checks in quiescence search
59     PH_STOP
60   };
61
62   MovePicker(const Position& p, bool pvnode, Move ttm, Move mk, Move k1, Move k2, Depth d);
63   Move get_next_move();
64   Move get_next_move(Lock &lock);
65   int number_of_moves() const;
66   int current_move_score() const;
67   MovegenPhase current_move_type() const;
68   Bitboard discovered_check_candidates() const;
69
70   static void init_phase_table();
71
72 private:
73   void score_captures();
74   void score_noncaptures();
75   void score_evasions();
76   void score_qcaptures();
77   Move pick_move_from_list();
78   int find_best_index();
79   
80   const Position& pos;
81   Move ttMove, mateKiller, killer1, killer2;
82   Bitboard pinned, dc;
83   MoveStack moves[256], badCaptures[64];
84   bool pvNode;
85   Depth depth;
86   int phaseIndex;
87   int numOfMoves, numOfBadCaptures;
88   int movesPicked, badCapturesPicked;
89   bool finished;
90 };
91
92
93 ////
94 //// Inline functions
95 ////
96
97 /// MovePicker::number_of_moves() simply returns the numOfMoves member
98 /// variable. It is intended to be used in positions where the side to move
99 /// is in check, for detecting checkmates or situations where there is only
100 /// a single reply to check.
101
102 inline int MovePicker::number_of_moves() const {
103   return numOfMoves;
104 }
105
106 /// MovePicker::discovered_check_candidates() returns a bitboard containing
107 /// all pieces which can possibly give discovered check.  This bitboard is
108 /// computed by the constructor function.
109
110 inline Bitboard MovePicker::discovered_check_candidates() const {
111   return dc;
112 }
113
114 #endif // !defined(MOVEPICK_H_INCLUDED)