@@ -63,17 +63,26 @@ void nn::Evaluator::setPieceOnSquareAccumulator(bb::Color side, bb::PieceType pi
6363 bb::Color pieceColor, bb::Square square,
6464 bb::Square kingSquare) {
6565 const int idx = index (pieceType, pieceColor, square, side, kingSquare);
66- addWeightsToAccumulator<value>(idx, history.back ().summation [side]);
66+
67+ if (!accumulator_is_initialised[side]){
68+ addWeightsToAccumulator<value>(idx, history[history_index-1 ].summation [side], history[history_index].summation [side]);
69+ accumulator_is_initialised[side] = true ;
70+ }
71+ else {
72+ addWeightsToAccumulator<value>(idx, history[history_index].summation [side]);
73+ }
6774}
6875
6976void nn::Evaluator::reset (Board* board) {
7077 history.resize (1 );
78+ this ->history_index = 0 ;
7179 resetAccumulator (board, bb::WHITE);
7280 resetAccumulator (board, bb::BLACK);
7381}
7482
7583void nn::Evaluator::resetAccumulator (Board* board, bb::Color color) {
7684 accumulator_table->use (color, board, *this );
85+ accumulator_is_initialised[color] = true ;
7786}
7887
7988int nn::Evaluator::evaluate (bb::Color activePlayer, Board* board) {
@@ -82,8 +91,8 @@ int nn::Evaluator::evaluate(bb::Color activePlayer, Board* board) {
8291 }
8392 constexpr avx_register_type_16 reluBias {};
8493
85- const auto acc_act = (avx_register_type_16*) history. back () .summation [activePlayer];
86- const auto acc_nac = (avx_register_type_16*) history. back () .summation [!activePlayer];
94+ const auto acc_act = (avx_register_type_16*) history[history_index] .summation [activePlayer];
95+ const auto acc_nac = (avx_register_type_16*) history[history_index] .summation [!activePlayer];
8796
8897 // compute the dot product
8998 avx_register_type_32 res {};
@@ -102,24 +111,40 @@ int nn::Evaluator::evaluate(bb::Color activePlayer, Board* board) {
102111
103112nn::Evaluator::Evaluator () {
104113 this ->history .push_back (Accumulator {});
114+ this ->history_index = 0 ;
105115 this ->accumulator_table ->reset ();
106116}
107117
108118nn::Evaluator::Evaluator (const nn::Evaluator& evaluator) {
109119 history = evaluator.history ;
120+ history_index = evaluator.history_index ;
110121}
111122nn::Evaluator& nn::Evaluator::operator =(const nn::Evaluator& evaluator) {
112123 this ->history = evaluator.history ;
124+ this ->history_index = evaluator.history_index ;
113125 return *this ;
114126}
115127
116- void nn::Evaluator::addNewAccumulation () { this ->history .emplace_back (this ->history .back ()); }
128+ void nn::Evaluator::addNewAccumulation () {
129+ history_index ++;
130+ // enlarge history if required
131+ if (history_index >= this ->history .size ()){
132+ this ->history .resize (history_index + 1 );
133+ }
134+ accumulator_is_initialised[bb::WHITE] = false ;
135+ accumulator_is_initialised[bb::BLACK] = false ;
136+ }
117137
118- void nn::Evaluator::popAccumulation () { this ->history .pop_back (); }
138+ void nn::Evaluator::popAccumulation () {
139+ history_index --;
140+ accumulator_is_initialised[bb::WHITE] = true ;
141+ accumulator_is_initialised[bb::BLACK] = true ;
142+ }
119143
120144void nn::Evaluator::clearHistory () {
121145 this ->history .clear ();
122146 this ->history .push_back (Accumulator {});
147+ this ->history_index = 0 ;
123148}
124149
125150template void nn::Evaluator::setPieceOnSquare<true >(bb::PieceType pieceType, bb::Color pieceColor,
0 commit comments