mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Retire history.cpp
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
2052407090
commit
7faeab0878
4 changed files with 30 additions and 97 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
////
|
||||
//// Includes
|
||||
////
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#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]--;
|
||||
}
|
|
@ -20,6 +20,8 @@
|
|||
#if !defined(HISTORY_H_INCLUDED)
|
||||
#define HISTORY_H_INCLUDED
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#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)
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue