Skip to content

Commit 876953b

Browse files
committed
Merge branch 'king_moves_half_reset'
``` ELO | 8.86 +- 8.83 (95%) CONF | 8.0+0.08s Threads=1 Hash=8MB GAMES | N: 2864 W: 727 L: 654 D: 1483 ```
2 parents cb23f7f + c2d2594 commit 876953b

File tree

2 files changed

+52
-17
lines changed

2 files changed

+52
-17
lines changed

src_files/board.cpp

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -554,32 +554,64 @@ template<bool prefetch> void Board::move(Move m, TranspositionTable* table) {
554554
m_boardStatusHistory.emplace_back(std::move(newBoardStatus));
555555
this->changeActivePlayer();
556556

557-
if (isCastle(m)) {
558-
// move the rook as well. castling rights are handled below
559-
Square rookSquare = sqFrom + (mType == QUEEN_CASTLE ? -4 : 3);
560-
Square rookTarget = sqTo + (mType == QUEEN_CASTLE ? 1 : -1);
561-
this->unsetPiece(rookSquare);
562-
this->setPiece(rookTarget, ROOK + 8 * color);
557+
558+
bool requires_accumulator_reset = false;
559+
if( nn::kingSquareIndex(sqTo, color) !=
560+
nn::kingSquareIndex(sqFrom, color)
561+
|| fileIndex(sqFrom) + fileIndex(sqTo) == 7){
562+
requires_accumulator_reset = true;
563563
}
564564

565-
this->unsetPiece(sqFrom);
566-
if (isCapture(m)) {
567-
this->replacePiece(sqTo, pFrom);
568-
} else {
569-
this->setPiece(sqTo, pFrom);
565+
// normal handling if no reset is required
566+
if(!requires_accumulator_reset){
567+
if (isCastle(m)) {
568+
// move the rook as well. castling rights are handled below
569+
Square rookSquare = sqFrom + (mType == QUEEN_CASTLE ? -4 : 3);
570+
Square rookTarget = sqTo + (mType == QUEEN_CASTLE ? 1 : -1);
571+
this->unsetPiece(rookSquare);
572+
this->setPiece(rookTarget, ROOK + 8 * color);
573+
}
574+
575+
this->unsetPiece(sqFrom);
576+
if (isCapture(m)) {
577+
this->replacePiece(sqTo, pFrom);
578+
} else {
579+
this->setPiece(sqTo, pFrom);
580+
}
581+
}else{
582+
Square ourKingSq = bitscanForward(getPieceBB(color ,KING));
583+
Square oppKingSq = bitscanForward(getPieceBB(!color,KING));
584+
585+
// handling for when only updates for the opponents accumulator are needed
586+
if (isCastle(m)) {
587+
// move the rook as well. castling rights are handled below
588+
Square rookSquare = sqFrom + (mType == QUEEN_CASTLE ? -4 : 3);
589+
Square rookTarget = sqTo + (mType == QUEEN_CASTLE ? 1 : -1);
590+
this->unsetPiece<false>(rookSquare);
591+
this->setPiece<false>(rookTarget, ROOK + 8 * color);
592+
593+
this->evaluator.setPieceOnSquareAccumulator<false>(!color, ROOK, color, rookSquare, oppKingSq);
594+
this->evaluator.setPieceOnSquareAccumulator<true>(!color , ROOK, color, rookTarget, oppKingSq);
595+
}
596+
this->unsetPiece<false>(sqFrom);
597+
this->evaluator.setPieceOnSquareAccumulator<false>(!color, KING, color, sqFrom, oppKingSq);
598+
if (isCapture(m)) {
599+
this->replacePiece<false>(sqTo, pFrom);
600+
this->evaluator.setPieceOnSquareAccumulator<true>(!color, KING, color, sqTo, oppKingSq);
601+
this->evaluator.setPieceOnSquareAccumulator<false>(!color, getCapturedPieceType(m), !color, sqTo, oppKingSq);
602+
} else {
603+
this->setPiece<false>(sqTo, pFrom);
604+
this->evaluator.setPieceOnSquareAccumulator<true>(!color, KING, color, sqTo, oppKingSq);
605+
}
570606
}
571607

572-
// check if it crossed squares
573-
if( nn::kingSquareIndex(sqTo, color) !=
574-
nn::kingSquareIndex(sqFrom, color)
575-
|| fileIndex(sqFrom) + fileIndex(sqTo) == 7){
608+
// reset accumulator of moving side if required
609+
if(requires_accumulator_reset){
576610
this->evaluator.resetAccumulator(this, color);
577611
}
578612

579613
// we need to compute the repetition count
580614
this->computeNewRepetition();
581-
582-
583615
return;
584616
}
585617

src_files/eval.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,6 @@ template void nn::Evaluator::setPieceOnSquare<true>(bb::PieceType pieceType, bb:
276276
template void nn::Evaluator::setPieceOnSquare<false>(bb::PieceType pieceType, bb::Color pieceColor,
277277
bb::Square square, bb::Square wKingSquare,
278278
bb::Square bKingSquare);
279+
280+
template void nn::Evaluator::setPieceOnSquareAccumulator<false>(bb::Color side, bb::PieceType pieceType, bb::Color pieceColor, bb::Square square, bb::Square kingSquare);
281+
template void nn::Evaluator::setPieceOnSquareAccumulator<true>(bb::Color side, bb::PieceType pieceType, bb::Color pieceColor, bb::Square square, bb::Square kingSquare);

0 commit comments

Comments
 (0)