|
@@ -271,10 +271,41 @@ pub fn sort_moves(game: &mut Game, hash: &mut Cache, killers: &[Move], move_list
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+pub fn sort_moves_least_valuable_attacker(game: &mut Game, move_list: &mut Vec<Move>) {
|
|
|
|
+ const piece_values: [i32; 6] = [
|
|
|
|
+ 100, // Pawn
|
|
|
|
+ 220, // Knight
|
|
|
|
+ 320, // Bishop
|
|
|
|
+ 400, // Rook
|
|
|
|
+ 800, // Queen
|
|
|
|
+ 100000 // King
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ let lva_mvv_score= |mov: &Move| {
|
|
|
|
+ let v = match mov {
|
|
|
|
+ Move::Default { mov: _, piece_type, captured } => {
|
|
|
|
+ let attack = piece_values[*piece_type as usize];
|
|
|
|
+ let victim = captured.map(|ct| piece_values[ct as usize]).unwrap_or(0);
|
|
|
|
+ attack - victim * 5
|
|
|
|
+ },
|
|
|
|
+ Move::Promotion { mov: _, promote_to: _, captured } => {
|
|
|
|
+ let victim = captured.map(|ct| piece_values[ct as usize]).unwrap_or(0);
|
|
|
|
+ piece_values[PAWN as usize] - victim * 5
|
|
|
|
+ },
|
|
|
|
+ _ => 0
|
|
|
|
+ };
|
|
|
|
+ v
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ move_list.sort_by_cached_key(lva_mvv_score)
|
|
|
|
+}
|
|
|
|
+
|
|
pub fn sort_moves_no_hash(game: &mut Game, move_list: &mut Vec<Move>) {
|
|
pub fn sort_moves_no_hash(game: &mut Game, move_list: &mut Vec<Move>) {
|
|
move_list.sort_by_cached_key(|mov| {
|
|
move_list.sort_by_cached_key(|mov| {
|
|
let undo = game.apply(*mov);
|
|
let undo = game.apply(*mov);
|
|
- let eval = crate::evaluate::evaluate(game);
|
|
|
|
|
|
+ let our_material = crate::evaluate::material_value(game, game.turn);
|
|
|
|
+ let their_material = crate::evaluate::material_value(game, !game.turn);
|
|
|
|
+ let eval = our_material - their_material;
|
|
game.undo_move(undo);
|
|
game.undo_move(undo);
|
|
return eval;
|
|
return eval;
|
|
});
|
|
});
|