@@ -20,35 +20,51 @@ void SortedMoveGen<chess::movegen::MoveGenType::ALL>::set_score(chess::Move& mov
2020 const chess::Square to = move.to ();
2121 const chess::Piece piece = board.at (from);
2222 const chess::Piece to_piece = board.at (to);
23+ const int from_value = piece_value[static_cast <int >(piece.type ())];
24+
25+ chess::Bitboard attacked_by_pawn = 0 ;
26+
27+ chess::Bitboard pawn_attackers = board.pieces (chess::PieceType::PAWN, ~board.sideToMove ());
28+
29+ while (pawn_attackers)
30+ attacked_by_pawn |= chess::attacks::pawn (~board.sideToMove (), pawn_attackers.pop ());
31+
2332 int score = 0 ;
2433
2534 if ((piece != chess::Piece::WHITEKING) && (piece != chess::Piece::BLACKKING)){
26- score += psm.get_psm (piece, from, to);
35+ score += 100 * psm.get_psm (piece, from, to);
2736 } else {
2837 bool is_endgame = board.occ ().count () <= ENDGAME_PIECE_COUNT;
29- score += psm.get_ksm (piece, is_endgame, to, from);
38+ score += 100 * psm.get_ksm (piece, is_endgame, to, from);
3039 }
3140
41+ if (piece.type () != chess::PieceType::PAWN){
42+ score += bool (attacked_by_pawn & chess::Bitboard::fromSquare (from))
43+ * 40 * from_value * MATERIAL_CHANGE_MULTIPLIER;
44+
45+ score -= bool (attacked_by_pawn & chess::Bitboard::fromSquare (to))
46+ * 41 * from_value * MATERIAL_CHANGE_MULTIPLIER;
47+ }
48+
3249 // captures should be searched early, so
3350 // to_value = piece_value(to) - piece_value(from) doesn't seem to work.
3451 // however, find a way to make these captures even better ?
3552 if (to_piece != chess::Piece::NONE){
36- score += piece_value[static_cast <int >(to_piece.type ())] * MATERIAL_CHANGE_MULTIPLIER;
53+ score += 100 * piece_value[static_cast <int >(to_piece.type ())] * MATERIAL_CHANGE_MULTIPLIER;
3754 }
3855
3956 if (move.typeOf () == chess::Move::PROMOTION){
40- score += piece_value[static_cast <int >(move.promotionType ())] * MATERIAL_CHANGE_MULTIPLIER;
57+ score += 100 * piece_value[static_cast <int >(move.promotionType ())] * MATERIAL_CHANGE_MULTIPLIER;
4158 }
4259
43- if (killer_moves[depth].in_buffer (move)){
44- score += KILLER_SCORE;
60+ if (depth != - 1 && killer_moves[depth].in_buffer (move)){
61+ score += 100 * KILLER_SCORE;
4562 }
4663
47- score += history.get_history_bonus (from.index (), to.index (), board.sideToMove () == chess::Color::WHITE)/100 ; // cant be less than worst move score
48-
49- assert (score < BEST_MOVE_SCORE);
50- assert (score > WORST_MOVE_SCORE);
64+ score += history.get_history_bonus (from.index (), to.index (), board.sideToMove () == chess::Color::WHITE); // cant be less than worst move score
5165
66+ score = std::clamp (score, WORST_MOVE_SCORE + 1 , BEST_MOVE_SCORE - 1 );
67+
5268 move.setScore (score);
5369}
5470
0 commit comments