@@ -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
0 commit comments