diff --git a/src/Makefile b/src/Makefile
index 513e3257..549b7867 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -32,7 +32,7 @@ PGOBENCH = ./$(EXE) bench 32 1 10 default depth
### Object files
OBJS = bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
- misc.o move.o movegen.o history.o movepick.o search.o position.o \
+ misc.o move.o movegen.o movepick.o search.o position.o \
tt.o uci.o ucioption.o book.o bitbase.o benchmark.o timeman.o
diff --git a/src/history.cpp b/src/history.cpp
deleted file mode 100644
index f10e7619..00000000
--- a/src/history.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- Stockfish, a UCI chess playing engine derived from Glaurung 2.1
- Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
- Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
-
- Stockfish is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Stockfish is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-
-////
-//// Includes
-////
-
-#include
-#include
-
-#include "history.h"
-
-
-////
-//// Functions
-////
-
-
-/// Constructor
-
-History::History() { clear(); }
-
-
-/// History::clear() clears the history tables
-
-void History::clear() {
- memset(history, 0, 16 * 64 * sizeof(int));
- memset(maxStaticValueDelta, 0, 16 * 64 * sizeof(int));
-}
-
-
-/// History::success() registers a move as being successful. This is done
-/// whenever a non-capturing move causes a beta cutoff in the main search.
-/// The three parameters are the moving piece, the destination square, and
-/// the search depth.
-
-void History::success(Piece p, Square to, Depth d) {
-
- assert(piece_is_ok(p));
- assert(square_is_ok(to));
-
- history[p][to] += int(d) * int(d);
-}
-
-
-/// History::failure() registers a move as being unsuccessful. The function is
-/// called for each non-capturing move which failed to produce a beta cutoff
-/// at a node where a beta cutoff was finally found.
-
-void History::failure(Piece p, Square to, Depth d) {
-
- assert(piece_is_ok(p));
- assert(square_is_ok(to));
-
- history[p][to] -= int(d) * int(d);
-}
-
-
-/// History::set_gain() and History::gain() store and retrieve the
-/// gain of a move given the delta of the static position evaluations
-/// before and after the move.
-
-void History::set_gain(Piece p, Square to, Value delta) {
-
- if (delta >= maxStaticValueDelta[p][to])
- maxStaticValueDelta[p][to] = delta;
- else
- maxStaticValueDelta[p][to]--;
-}
diff --git a/src/history.h b/src/history.h
index bbe2aab3..9206cdf4 100644
--- a/src/history.h
+++ b/src/history.h
@@ -20,6 +20,8 @@
#if !defined(HISTORY_H_INCLUDED)
#define HISTORY_H_INCLUDED
+#include
+
#include "depth.h"
#include "move.h"
#include "piece.h"
@@ -36,25 +38,41 @@
class History {
public:
- History();
+ History() { clear(); }
void clear();
- void success(Piece p, Square to, Depth d);
- void failure(Piece p, Square to, Depth d);
int value(Piece p, Square to) const;
- void set_gain(Piece p, Square to, Value delta);
+ void update(Piece p, Square to, Value delta);
Value gain(Piece p, Square to) const;
+ void update_gain(Piece p, Square to, Value delta);
private:
- int history[16][64]; // [piece][square]
- int maxStaticValueDelta[16][64]; // [piece][from_square][to_square]
+ Value history[16][64]; // [piece][to_square]
+ Value maxGains[16][64]; // [piece][to_square]
};
+inline void History::clear() {
+ memset(history, 0, 16 * 64 * sizeof(int));
+ memset(maxGains, 0, 16 * 64 * sizeof(int));
+}
+
inline int History::value(Piece p, Square to) const {
return history[p][to];
}
+inline void History::update(Piece p, Square to, Value bonus) {
+ history[p][to] += bonus;
+}
+
inline Value History::gain(Piece p, Square to) const {
- return Value(maxStaticValueDelta[p][to]);
+ return maxGains[p][to];
+}
+
+inline void History::update_gain(Piece p, Square to, Value gain) {
+
+ if (gain >= maxGains[p][to])
+ maxGains[p][to] = gain;
+ else
+ maxGains[p][to]--;
}
#endif // !defined(HISTORY_H_INCLUDED)
diff --git a/src/search.cpp b/src/search.cpp
index 1a8e9ea7..370889cc 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -1909,8 +1909,9 @@ split_point_start: // At split points actual search starts from here
void update_history(const Position& pos, Move move, Depth depth,
Move movesSearched[], int moveCount) {
Move m;
+ Value bonus = Value(int(depth) * int(depth));
- H.success(pos.piece_on(move_from(move)), move_to(move), depth);
+ H.update(pos.piece_on(move_from(move)), move_to(move), bonus);
for (int i = 0; i < moveCount - 1; i++)
{
@@ -1919,7 +1920,7 @@ split_point_start: // At split points actual search starts from here
assert(m != move);
if (!pos.move_is_capture_or_promotion(m))
- H.failure(pos.piece_on(move_from(m)), move_to(m), depth);
+ H.update(pos.piece_on(move_from(m)), move_to(m), -bonus);
}
}
@@ -1947,7 +1948,7 @@ split_point_start: // At split points actual search starts from here
&& after != VALUE_NONE
&& pos.captured_piece_type() == PIECE_TYPE_NONE
&& !move_is_special(m))
- H.set_gain(pos.piece_on(move_to(m)), move_to(m), -(before + after));
+ H.update_gain(pos.piece_on(move_to(m)), move_to(m), -(before + after));
}