]> git.sesse.net Git - stockfish/blob - src/history.cpp
Better interface to get the current move type
[stockfish] / src / history.cpp
1 /*
2   Glaurung, a UCI chess playing engine.
3   Copyright (C) 2004-2008 Tord Romstad
4
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.
9   
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.
14   
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/>.
17 */
18
19
20 ////
21 //// Includes
22 ////
23
24 #include <cassert>
25
26 #include "history.h"
27
28
29 ////
30 //// Functions
31 ////
32
33 /// Constructor
34
35 History::History() {
36   this->clear();
37 }
38
39
40 /// History::clear() clears the history tables.
41
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));
46 }
47
48
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
52 /// search depth.
53
54 void History::success(Piece p, Move m, Depth d) {
55   assert(piece_is_ok(p));
56   assert(move_is_ok(m));
57
58   history[p][move_to(m)] += int(d) * int(d);
59   successCount[p][move_to(m)]++;
60
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++)
65         history[i][j] /= 2;
66 }
67
68
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.
72
73 void History::failure(Piece p, Move m) {
74   assert(piece_is_ok(p));
75   assert(move_is_ok(m));
76
77   failureCount[p][move_to(m)]++;
78 }
79
80
81 /// History::move_ordering_score() returns an integer value used to order the
82 /// non-capturing moves in the MovePicker class.
83
84 int History::move_ordering_score(Piece p, Move m) const {
85   assert(piece_is_ok(p));
86   assert(move_is_ok(m));
87
88   return history[p][move_to(m)];
89 }
90
91
92 /// History::ok_to_prune() decides whether a move has been sufficiently
93 /// unsuccessful that it makes sense to prune it entirely. 
94
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));
98
99   return (int(d) * successCount[p][move_to(m)] < failureCount[p][move_to(m)]);
100 }