- if(!PruneDefendingMoves && threat != MOVE_NONE
- && (piece_value_midgame(pos.piece_on(tfrom))
- >= piece_value_midgame(pos.piece_on(tto)))
- && pos.move_attacks_square(m, tto))
+ if ( !PruneDefendingMoves
+ && threat != MOVE_NONE
+ && pos.type_of_piece_on(tto) != NO_PIECE_TYPE
+ && ( pos.midgame_value_of_piece_on(tfrom) >= pos.midgame_value_of_piece_on(tto)
+ || pos.type_of_piece_on(tfrom) == KING)
+ && pos.move_attacks_square(m, tto))