]> git.sesse.net Git - stockfish/blob - src/movepick.h
Retire history.h
[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-2012 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 #if !defined MOVEPICK_H_INCLUDED
21 #define MOVEPICK_H_INCLUDED
22
23 #include "position.h"
24 #include "search.h"
25 #include "types.h"
26
27
28 /// The History class stores statistics about how often different moves
29 /// have been successful or unsuccessful during the current search. These
30 /// statistics are used for reduction and move ordering decisions. History
31 /// entries are stored according only to moving piece and destination square,
32 /// in particular two moves with different origin but same destination and
33 /// same piece will be considered identical.
34
35 class History {
36 public:
37
38   static const Value Max = Value(2000);
39
40   const Value* operator[](Piece p) const { return &history[p][0]; }
41   Value gain(Piece p, Square to) const { return gains[p][to]; }
42
43   void clear();
44   void update(Piece p, Square to, Value bonus);
45   void update_gain(Piece p, Square to, Value gain);
46
47 private:
48   Value history[PIECE_NB][SQUARE_NB];
49   Value gains[PIECE_NB][SQUARE_NB];
50 };
51
52
53 /// MovePicker class is used to pick one pseudo legal move at a time from the
54 /// current position. The most important method is next_move(), which returns a
55 /// new pseudo legal move each time it is called, until there are no moves left,
56 /// when MOVE_NONE is returned. In order to improve the efficiency of the alpha
57 /// beta algorithm, MovePicker attempts to return the moves which are most likely
58 /// to get a cut-off first.
59
60 class MovePicker {
61
62   MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
63
64 public:
65   MovePicker(const Position&, Move, Depth, const History&, Search::Stack*, Value);
66   MovePicker(const Position&, Move, Depth, const History&, Square);
67   MovePicker(const Position&, Move, const History&, PieceType);
68   template<bool SpNode> Move next_move();
69
70 private:
71   void score_captures();
72   void score_noncaptures();
73   void score_evasions();
74   void generate_next();
75
76   const Position& pos;
77   const History& H;
78   Search::Stack* ss;
79   Depth depth;
80   Move ttMove;
81   MoveStack killers[2];
82   Square recaptureSquare;
83   int captureThreshold, phase;
84   MoveStack *cur, *end, *endQuiets, *endBadCaptures;
85   MoveStack moves[MAX_MOVES];
86 };
87
88 #endif // !defined(MOVEPICK_H_INCLUDED)