diff --git a/src/movepick.cpp b/src/movepick.cpp index a70785e76..663c9acb4 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -22,6 +22,10 @@ #include "movepick.h" +int history_slot(Piece pc) { + return pc == NO_PIECE ? 0 : (type_of(pc) == KING ? PIECE_SLOTS - 1 : type_of(pc) % (PIECE_SLOTS - 1)) + color_of(pc) * PIECE_SLOTS; +} + namespace { enum Stages { @@ -112,10 +116,10 @@ void MovePicker::score() { else if (Type == QUIETS) m.value = (*mainHistory)[pos.side_to_move()][from_to(m)] - + (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)] - + (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)] - + (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)] - + (*continuationHistory[5])[pos.moved_piece(m)][to_sq(m)] / 2; + + (*continuationHistory[0])[history_slot(pos.moved_piece(m))][to_sq(m)] + + (*continuationHistory[1])[history_slot(pos.moved_piece(m))][to_sq(m)] + + (*continuationHistory[3])[history_slot(pos.moved_piece(m))][to_sq(m)] + + (*continuationHistory[5])[history_slot(pos.moved_piece(m))][to_sq(m)] / 2; else // Type == EVASIONS { @@ -124,7 +128,7 @@ void MovePicker::score() { - Value(type_of(pos.moved_piece(m))); else m.value = (*mainHistory)[pos.side_to_move()][from_to(m)] - + (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)] + + (*continuationHistory[0])[history_slot(pos.moved_piece(m))][to_sq(m)] - (1 << 28); } } diff --git a/src/movepick.h b/src/movepick.h index 5513d22ca..b42b4c68d 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -79,7 +79,7 @@ template struct Stats : public std::array, Size> {}; /// In stats table, D=0 means that the template parameter is not used -enum StatsParams { NOT_USED = 0 }; +enum StatsParams { NOT_USED = 0, PIECE_SLOTS = 8 }; /// ButterflyHistory records how often quiet moves have been successful or @@ -101,8 +101,9 @@ typedef Stats PieceToHistory; /// ContinuationHistory is the combined history of a given pair of moves, usually /// the current one given a previous one. The nested history table is based on /// PieceToHistory instead of ButterflyBoards. -typedef Stats ContinuationHistory; +typedef Stats ContinuationHistory; +int history_slot(Piece pc); /// MovePicker class is used to pick one pseudo legal move at a time from the /// current position. The most important method is next_move(), which returns a diff --git a/src/search.cpp b/src/search.cpp index c34e3805a..8083a9e2e 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -826,7 +826,7 @@ namespace { probCutCount++; ss->currentMove = move; - ss->continuationHistory = &thisThread->continuationHistory[pos.moved_piece(move)][to_sq(move)]; + ss->continuationHistory = &thisThread->continuationHistory[history_slot(pos.moved_piece(move))][to_sq(move)]; assert(depth >= 5 * ONE_PLY); @@ -998,8 +998,8 @@ namespace { // Countermoves based pruning (~20 Elo) if ( lmrDepth < 3 + ((ss-1)->statScore > 0 || (ss-1)->moveCount == 1) - && (*contHist[0])[movedPiece][to_sq(move)] < CounterMovePruneThreshold - && (*contHist[1])[movedPiece][to_sq(move)] < CounterMovePruneThreshold) + && (*contHist[0])[history_slot(movedPiece)][to_sq(move)] < CounterMovePruneThreshold + && (*contHist[1])[history_slot(movedPiece)][to_sq(move)] < CounterMovePruneThreshold) continue; // Futility pruning: parent node (~2 Elo) @@ -1031,7 +1031,7 @@ namespace { // Update the current move (this must be done after singular extension search) ss->currentMove = move; - ss->continuationHistory = &thisThread->continuationHistory[movedPiece][to_sq(move)]; + ss->continuationHistory = &thisThread->continuationHistory[history_slot(movedPiece)][to_sq(move)]; // Step 15. Make the move pos.do_move(move, st, givesCheck); @@ -1075,9 +1075,9 @@ namespace { r -= 2 * ONE_PLY; ss->statScore = thisThread->mainHistory[us][from_to(move)] - + (*contHist[0])[movedPiece][to_sq(move)] - + (*contHist[1])[movedPiece][to_sq(move)] - + (*contHist[3])[movedPiece][to_sq(move)] + + (*contHist[0])[history_slot(movedPiece)][to_sq(move)] + + (*contHist[1])[history_slot(movedPiece)][to_sq(move)] + + (*contHist[3])[history_slot(movedPiece)][to_sq(move)] - 4000; // Decrease/increase reduction by comparing opponent's stat score (~10 Elo) @@ -1420,7 +1420,7 @@ namespace { } ss->currentMove = move; - ss->continuationHistory = &thisThread->continuationHistory[pos.moved_piece(move)][to_sq(move)]; + ss->continuationHistory = &thisThread->continuationHistory[history_slot(pos.moved_piece(move))][to_sq(move)]; // Make and search the move pos.do_move(move, st, givesCheck); @@ -1507,7 +1507,7 @@ namespace { for (int i : {1, 2, 4, 6}) if (is_ok((ss-i)->currentMove)) - (*(ss-i)->continuationHistory)[pc][to] << bonus; + (*(ss-i)->continuationHistory)[history_slot(pc)][to] << bonus; }