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-2010 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/>.
38 History::History() { clear(); }
41 /// History::clear() clears the history tables
43 void History::clear() {
44 memset(history, 0, 2 * 8 * 64 * sizeof(int));
45 memset(maxStaticValueDelta, 0, 2 * 8 * 64 * sizeof(int));
49 /// History::success() registers a move as being successful. This is done
50 /// whenever a non-capturing move causes a beta cutoff in the main search.
51 /// The three parameters are the moving piece, the destination square, and
54 void History::success(Piece p, Square to, Depth d) {
56 assert(piece_is_ok(p));
57 assert(square_is_ok(to));
59 history[p][to] += int(d) * int(d);
61 // Prevent history overflow
62 if (history[p][to] >= HistoryMax)
63 for (int i = 0; i < 16; i++)
64 for (int j = 0; j < 64; j++)
69 /// History::failure() registers a move as being unsuccessful. The function is
70 /// called for each non-capturing move which failed to produce a beta cutoff
71 /// at a node where a beta cutoff was finally found.
73 void History::failure(Piece p, Square to, Depth d) {
75 assert(piece_is_ok(p));
76 assert(square_is_ok(to));
78 history[p][to] -= int(d) * int(d);
80 // Prevent history underflow
81 if (history[p][to] <= -HistoryMax)
82 for (int i = 0; i < 16; i++)
83 for (int j = 0; j < 64; j++)
88 /// History::move_ordering_score() returns an integer value used to order the
89 /// non-capturing moves in the MovePicker class.
91 int History::move_ordering_score(Piece p, Square to) const {
93 assert(piece_is_ok(p));
94 assert(square_is_ok(to));
96 return history[p][to];
100 /// History::set_gain() and History::gain() store and retrieve the
101 /// gain of a move given the delta of the static position evaluations
102 /// before and after the move.
104 void History::set_gain(Piece p, Square to, Value delta)
106 if (delta >= maxStaticValueDelta[p][to])
107 maxStaticValueDelta[p][to] = delta;
109 maxStaticValueDelta[p][to]--;
112 Value History::gain(Piece p, Square to) const
114 return Value(maxStaticValueDelta[p][to]);