2 Glaurung, a UCI chess playing engine.
3 Copyright (C) 2004-2008 Tord Romstad
5 Glaurung is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 Glaurung is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
40 /// History::clear() clears the history tables.
42 void History::clear() {
43 memset(history
, 0, 2 * 8 * 64 * sizeof(int));
44 memset(successCount
, 0, 2 * 8 * 64 * sizeof(int));
45 memset(failureCount
, 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 move itself, and the
54 void History::success(Piece p
, Move m
, Depth d
) {
55 assert(piece_is_ok(p
));
56 assert(move_is_ok(m
));
58 history
[p
][move_to(m
)] += int(d
) * int(d
);
59 successCount
[p
][move_to(m
)]++;
61 // Prevent history overflow:
62 if(history
[p
][move_to(m
)] >= 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
, Move m
) {
74 assert(piece_is_ok(p
));
75 assert(move_is_ok(m
));
77 failureCount
[p
][move_to(m
)]++;
81 /// History::move_ordering_score() returns an integer value used to order the
82 /// non-capturing moves in the MovePicker class.
84 int History::move_ordering_score(Piece p
, Move m
) const {
85 assert(piece_is_ok(p
));
86 assert(move_is_ok(m
));
88 return history
[p
][move_to(m
)];
92 /// History::ok_to_prune() decides whether a move has been sufficiently
93 /// unsuccessful that it makes sense to prune it entirely.
95 bool History::ok_to_prune(Piece p
, Move m
, Depth d
) const {
96 assert(piece_is_ok(p
));
97 assert(move_is_ok(m
));
99 return (int(d
) * successCount
[p
][move_to(m
)] < failureCount
[p
][move_to(m
)]);