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-2015 Marco Costalba, Joona Kiiski, Tord Romstad
5 Copyright (C) 2015-2017 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
7 Stockfish is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Stockfish is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef MOVEPICK_H_INCLUDED
22 #define MOVEPICK_H_INCLUDED
24 #include <cstring> // For std::memset
31 /// HistoryStats records how often quiet moves have been successful or unsuccessful
32 /// during the current search, and is used for reduction and move ordering decisions.
35 static const int Max = 1 << 28;
37 int get(Color c, Move m) const { return table[c][from_sq(m)][to_sq(m)]; }
38 void clear() { std::memset(table, 0, sizeof(table)); }
39 void update(Color c, Move m, int v) {
41 Square from = from_sq(m);
46 assert(abs(v) <= D); // Consistency check for below formula
48 table[c][from][to] -= table[c][from][to] * abs(v) / D;
49 table[c][from][to] += v * 32;
53 int table[COLOR_NB][SQUARE_NB][SQUARE_NB];
57 /// A template struct, used to generate MoveStats and CounterMoveHistoryStats:
58 /// MoveStats store the move that refute a previous one.
59 /// CounterMoveHistoryStats is like HistoryStats, but with two consecutive moves.
60 /// Entries are stored using only the moving piece and destination square, hence
61 /// two moves with different origin but same destination and piece will be
62 /// considered identical.
65 const T* operator[](Piece pc) const { return table[pc]; }
66 T* operator[](Piece pc) { return table[pc]; }
67 void clear() { std::memset(table, 0, sizeof(table)); }
68 void update(Piece pc, Square to, Move m) { table[pc][to] = m; }
69 void update(Piece pc, Square to, int v) {
73 assert(abs(v) <= D); // Consistency check for below formula
75 table[pc][to] -= table[pc][to] * abs(v) / D;
76 table[pc][to] += v * 32;
80 T table[PIECE_NB][SQUARE_NB];
83 typedef Stats<Move> MoveStats;
84 typedef Stats<int> CounterMoveStats;
85 typedef Stats<CounterMoveStats> CounterMoveHistoryStats;
88 /// MovePicker class is used to pick one pseudo legal move at a time from the
89 /// current position. The most important method is next_move(), which returns a
90 /// new pseudo legal move each time it is called, until there are no moves left,
91 /// when MOVE_NONE is returned. In order to improve the efficiency of the alpha
92 /// beta algorithm, MovePicker attempts to return the moves which are most likely
93 /// to get a cut-off first.
94 namespace Search { struct Stack; }
98 MovePicker(const MovePicker&) = delete;
99 MovePicker& operator=(const MovePicker&) = delete;
101 MovePicker(const Position&, Move, Value);
102 MovePicker(const Position&, Move, Depth, Square);
103 MovePicker(const Position&, Move, Depth, Search::Stack*);
105 Move next_move(bool skipQuiets = false);
108 template<GenType> void score();
109 ExtMove* begin() { return cur; }
110 ExtMove* end() { return endMoves; }
113 const Search::Stack* ss;
118 Square recaptureSquare;
121 ExtMove *cur, *endMoves, *endBadCaptures;
122 ExtMove moves[MAX_MOVES];
125 #endif // #ifndef MOVEPICK_H_INCLUDED