]> git.sesse.net Git - stockfish/blob - src/history.cpp
Implement MaxGain table
[stockfish] / src / history.cpp
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-2009 Marco Costalba
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
21 ////
22 //// Includes
23 ////
24
25 #include <cassert>
26 #include <cstring>
27
28 #include "history.h"
29
30
31 ////
32 //// Functions
33 ////
34
35
36 /// Constructor
37
38 History::History() { clear(); }
39
40
41 /// History::clear() clears the history tables
42
43 void History::clear() {
44   memset(history, 0, 2 * 8 * 64 * sizeof(int));
45 }
46
47
48 /// History::success() registers a move as being successful. This is done
49 /// whenever a non-capturing move causes a beta cutoff in the main search.
50 /// The three parameters are the moving piece, the destination square, and
51 /// the search depth.
52
53 void History::success(Piece p, Square to, Depth d) {
54
55   assert(piece_is_ok(p));
56   assert(square_is_ok(to));
57
58   history[p][to] += int(d) * int(d);
59
60   // Prevent history overflow
61   if (history[p][to] >= HistoryMax)
62       for (int i = 0; i < 16; i++)
63           for (int j = 0; j < 64; j++)
64               history[i][j] /= 2;
65 }
66
67
68 /// History::failure() registers a move as being unsuccessful. The function is
69 /// called for each non-capturing move which failed to produce a beta cutoff
70 /// at a node where a beta cutoff was finally found.
71
72 void History::failure(Piece p, Square to, Depth d) {
73
74   assert(piece_is_ok(p));
75   assert(square_is_ok(to));
76
77   history[p][to] -= int(d) * int(d);
78
79   // Prevent history underflow
80   if (history[p][to] <= -HistoryMax)
81       for (int i = 0; i < 16; i++)
82           for (int j = 0; j < 64; j++)
83               history[i][j] /= 2;
84 }
85
86
87 /// History::move_ordering_score() returns an integer value used to order the
88 /// non-capturing moves in the MovePicker class.
89
90 int History::move_ordering_score(Piece p, Square to) const {
91
92   assert(piece_is_ok(p));
93   assert(square_is_ok(to));
94
95   return history[p][to];
96 }