+ };
+
+ auto collect_for_two = [&](const DirtyPiece& dp1, const DirtyPiece& dp2) {
+ for (Color perspective : { WHITE, BLACK }) {
+ switch (trigger) {
+ case TriggerEvent::kFriendKingMoved:
+ reset[perspective] = dp1.piece[0] == make_piece(perspective, KING)
+ || dp2.piece[0] == make_piece(perspective, KING);
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ if (reset[perspective]) {
+ Derived::CollectActiveIndices(
+ pos, trigger, perspective, &added[perspective]);
+ } else {
+ Derived::CollectChangedIndices(
+ pos, dp1, trigger, perspective,
+ &removed[perspective], &added[perspective]);
+ Derived::CollectChangedIndices(
+ pos, dp2, trigger, perspective,
+ &removed[perspective], &added[perspective]);
+ }
+ }
+ };
+
+ if (pos.state()->previous->accumulator.computed_accumulation) {
+ const auto& prev_dp = pos.state()->dirtyPiece;
+ if (prev_dp.dirty_num == 0) return;
+ collect_for_one(prev_dp);
+ } else {
+ const auto& prev_dp = pos.state()->previous->dirtyPiece;
+ if (prev_dp.dirty_num == 0) {
+ const auto& prev2_dp = pos.state()->dirtyPiece;
+ if (prev2_dp.dirty_num == 0) return;
+ collect_for_one(prev2_dp);