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-2013 Marco Costalba, Joona Kiiski, Tord Romstad
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.
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.
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/>.
20 #ifndef MOVEPICK_H_INCLUDED
21 #define MOVEPICK_H_INCLUDED
23 #include <algorithm> // For std::max
24 #include <cstring> // For std::memset
32 /// The Stats struct stores moves statistics. According to the template parameter
33 /// the class can store History and Countermoves. History records how often
34 /// different moves have been successful or unsuccessful during the current search
35 /// and is used for reduction and move ordering decisions.
36 /// Countermoves store the move that refute a previous one. Entries are stored
37 /// according only to moving piece and destination square, hence two moves with
38 /// different origin but same destination and piece will be considered identical.
42 static const Value Max = Value(2000);
44 const T* operator[](Piece p) const { return table[p]; }
45 void clear() { std::memset(table, 0, sizeof(table)); }
47 void update(Piece p, Square to, Move m) {
49 if (m == table[p][to].first)
52 table[p][to].second = table[p][to].first;
53 table[p][to].first = m;
56 void update(Piece p, Square to, Value v) {
58 if (abs(table[p][to] + v) < Max)
63 T table[PIECE_NB][SQUARE_NB];
66 typedef Stats<Value> HistoryStats;
67 typedef Stats<std::pair<Move, Move> > CountermovesStats;
70 /// MovePicker class is used to pick one pseudo legal move at a time from the
71 /// current position. The most important method is next_move(), which returns a
72 /// new pseudo legal move each time it is called, until there are no moves left,
73 /// when MOVE_NONE is returned. In order to improve the efficiency of the alpha
74 /// beta algorithm, MovePicker attempts to return the moves which are most likely
75 /// to get a cut-off first.
79 MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
82 MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
83 MovePicker(const Position&, Move, const HistoryStats&, PieceType);
84 MovePicker(const Position&, Move, Depth, const HistoryStats&, Move*, Search::Stack*);
86 template<bool SpNode> Move next_move();
89 template<GenType> void score();
93 const HistoryStats& history;
99 Square recaptureSquare;
100 int captureThreshold, stage;
101 ExtMove *cur, *end, *endQuiets, *endBadCaptures;
102 ExtMove moves[MAX_MOVES];
105 #endif // #ifndef MOVEPICK_H_INCLUDED