|
@@ -202,6 +202,48 @@ pub fn generate_legal_moves(game: &mut Game, side: Side) -> Vec<Move> {
|
|
|
}
|
|
|
|
|
|
|
|
|
+pub fn generate_legal_sorted_moves(game: &mut Game, hash: &mut Cache, killers: &[Move], side: Side) -> Vec<Move> {
|
|
|
+ let moves = generate_moves(game, side);
|
|
|
+
|
|
|
+ let illegal_value = crate::evaluate::MAX_VALUE;
|
|
|
+
|
|
|
+ let mut mov_val_and_legality = |mov: &Move| {
|
|
|
+ let undo = game.apply(*mov);
|
|
|
+ let illegal = is_check(game, side);
|
|
|
+
|
|
|
+ if illegal {
|
|
|
+ game.undo_move(undo);
|
|
|
+ return illegal_value;
|
|
|
+ }
|
|
|
+
|
|
|
+ if let Some(e) = hash.lookup(game) {
|
|
|
+ game.undo_move(undo);
|
|
|
+ if let EntryType::Value = e.entry_type {
|
|
|
+ return e.value;
|
|
|
+ }
|
|
|
+ else if let EntryType::LowerBound = e.entry_type {
|
|
|
+ return e.value - 1000;
|
|
|
+ }
|
|
|
+ else if let EntryType::UpperBound = e.entry_type {
|
|
|
+ return e.value + 1000;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return crate::evaluate::evaluate(game) - if killers.contains(mov) { 200 } else { 0 };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ let eval = crate::evaluate::evaluate(game) - if killers.contains(mov) { 200 } else { 0 };
|
|
|
+ game.undo_move(undo);
|
|
|
+ return eval;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ let mut amovs: Vec<_> = moves.iter().map(|m| (*m, mov_val_and_legality(m))).collect();
|
|
|
+ amovs.sort_unstable_by_key(|x| x.1);
|
|
|
+
|
|
|
+ amovs.into_iter().filter(|x| x.1 != illegal_value).map(|(m, _v)| m).collect::<Vec<Move>>()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
pub fn generate_attacking_moves(game: &Game, side: Side) -> Vec<Move> {
|
|
|
let mut moves: Vec<Move> = Vec::with_capacity(32);
|
|
|
generate_pawn_captures(game, side, &mut moves);
|