Line data Source code
1 : #pragma once
2 :
3 : #include "definition.hpp"
4 : #include "position.hpp"
5 : #include "transposition.hpp"
6 :
7 : /*!
8 : * This file defines classic tables management such as :
9 : * - Killers
10 : * - History
11 : * - Color/from/to
12 : * - Piece/to
13 : * - CMH history : previous moved piece/previous to/current moved piece & to
14 : * - Counter : from/to
15 : */
16 :
17 : inline constexpr int MAX_CMH_PLY = 1;
18 : using CMHPtrArray = array1d<array1d<ScoreType, NbPiece*NbSquare> *, MAX_CMH_PLY>;
19 :
20 : struct KillerT {
21 : array2d<Move,MAX_DEPTH,2> killers;
22 :
23 : void initKillers();
24 : void update(Move m, DepthType height);
25 : [[nodiscard]] bool isKiller(const Move m, const DepthType height);
26 : };
27 :
28 : struct HistoryT {
29 : array3d<ScoreType,2,NbSquare,NbSquare> history; // Color, from, to
30 : array3d<ScoreType,NbPiece,NbSquare,PieceShift> historyCap; // Piece moved (+color), to, piece taken
31 : array2d<ScoreType,NbPiece,NbSquare> historyP; // Piece, to
32 : array3d<ScoreType,NbPiece,NbSquare,NbPiece*NbSquare> counter_history; // Previous moved piece, previous to, current moved piece * boardsize + current to
33 :
34 : void initHistory();
35 :
36 : template<int S> FORCE_FINLINE void update(DepthType depth, Move m, const Position& p, CMHPtrArray& cmhPtr) {
37 349126 : if (Move2Type(m) == T_std) {
38 491530 : const Color c = p.c;
39 491530 : const Square from = Move2From(m);
40 491530 : assert(isValidSquare(from));
41 491530 : const Square to = Move2To(m); // no need for correctedMove2ToKingDest here (std)
42 491530 : assert(isValidSquare(to));
43 491530 : const ScoreType s = S * HSCORE(depth);
44 491530 : const Piece pp = p.board_const(from);
45 491530 : history[c][from][to] += static_cast<ScoreType>(s - HISTORY_DIV(history[c][from][to] * Abs(s)));
46 491530 : historyP[PieceIdx(pp)][to] += static_cast<ScoreType>(s - HISTORY_DIV(historyP[PieceIdx(pp)][to] * Abs(s)));
47 941585 : for (int i = 0; i < MAX_CMH_PLY; ++i) {
48 491530 : if (cmhPtr[i]) {
49 450055 : ScoreType& item = (*cmhPtr[i])[PieceIdx(p.board_const(from)) * NbSquare + to];
50 450055 : item += static_cast<ScoreType>(s - HISTORY_DIV(item * Abs(s)));
51 : }
52 : }
53 : }
54 142404 : }
55 :
56 : template<int S> FORCE_FINLINE void updateCap(DepthType depth, Move m, const Position& p) {
57 663448 : if (isCaptureNoEP(m)) {
58 655966 : const Square from = Move2From(m);
59 655966 : assert(isValidSquare(from));
60 655966 : const Square to = Move2To(m); // no need for correctedMove2ToKingDest here (std capture)
61 655966 : assert(isValidSquare(to));
62 655966 : const Piece pf = p.board_const(from);
63 655966 : const Piece pt = p.board_const(to); // std capture, no ep
64 655966 : const ScoreType s = S * HSCORE(depth);
65 655966 : historyCap[PieceIdx(pf)][to][Abs(pt)-1] += static_cast<ScoreType>(s - HISTORY_DIV(historyCap[PieceIdx(pf)][to][Abs(pt)-1] * Abs(s)));
66 : }
67 : }
68 : };
69 :
70 : struct CounterT {
71 : array2d<ScoreType,NbSquare,NbSquare> counter;
72 :
73 : void initCounter();
74 : void update(Move m, const Position& p);
75 : };
76 :
77 : void updateTables(Searcher& context, const Position& p, DepthType depth, DepthType height, const Move m, TT::Bound bound, CMHPtrArray& cmhPtr);
|