Ver código fonte

slight adjust

Nicolas Winkler 2 anos atrás
pai
commit
8f14a0f7ee
2 arquivos alterados com 40 adições e 46 exclusões
  1. 19 0
      src/engine.rs
  2. 21 46
      src/movegen.rs

+ 19 - 0
src/engine.rs

@@ -155,6 +155,23 @@ impl Engine {
         }
     }
 
+    fn reconstruct_pv(&self) -> Vec<Move> {
+        let mut pv: Vec<Move> = Vec::new();
+
+        let mut g = self.game.clone();
+        while true {
+            let mce = self.hash.lookup(&g);
+            if let Some(ce) = mce {
+                pv.push(ce.mov);
+                g.apply(ce.mov);
+            }
+            else {
+                break;
+            }
+        }
+        return pv;
+    }
+
     fn start_search(&mut self, si: &SearchInfo) {
         if let None = self.game.zobrist {
             self.game.zobrist = Some((self.zobrist_table.clone(), self.game.calculate_zobrist(&self.zobrist_table)));
@@ -257,6 +274,8 @@ impl Engine {
                 let nodes = sc.nodes;
                 let nps = (nodes as f64 / elapsed.as_nanos() as f64 * 1000000000.0) as i64;
                 let cp = best_val as i64;
+                
+                //let pv_array = self.reconstruct_pv();
                 let pv = &sc.pv.iter().filter(|&m| !m.is_null()).map(|m| m.to_string()).fold(String::new(), |a, b| a + " " + &b)[0..];
 
                 if let Some(plies) = crate::evaluate::is_mate_in_p1(bv) {

+ 21 - 46
src/movegen.rs

@@ -271,8 +271,13 @@ 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] = [
+
+///
+/// assigns a score to capture moves lower the more valuable the captured piece. Secondly
+/// also higher the more the attacking piece is worth.
+/// 
+fn lva_mvv_score(mov: &Move) -> i32 {
+    const PIECE_VALUES: [i32; 6] = [
         100, // Pawn
         220, // Knight
         320, // Bishop
@@ -281,22 +286,21 @@ pub fn sort_moves_least_valuable_attacker(game: &mut Game, move_list: &mut Vec<M
         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
-    };
+    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
+    }
+}
 
+pub fn sort_moves_least_valuable_attacker(game: &mut Game, move_list: &mut Vec<Move>) {
     move_list.sort_by_cached_key(lva_mvv_score)
 }
 
@@ -311,35 +315,6 @@ pub fn sort_moves_no_hash(game: &mut Game, move_list: &mut Vec<Move>) {
     });
 }
 
-pub fn sort_quiescence(game: &mut Game, move_list: &mut Vec<Move>) {
-    let value_piece = |pt| {
-        match pt {
-            PAWN => 1,
-            KNIGHT => 2,
-            BISHOP => 3,
-            ROOK => 4,
-            QUEEN => 5,
-            KING => 6,
-            _ => 0,
-        }
-    };
-
-    move_list.sort_by_cached_key(|mov| {
-        match *mov {
-            Move::Default{ mov: _, piece_type, captured: Some(c) } => {
-                value_piece(piece_type) - value_piece(c)
-            },
-            Move::Promotion{ mov: _, promote_to: _, captured: Some(c) } => {
-                value_piece(PAWN) - value_piece(c)
-            },
-            Move::EnPassant{ mov: _, beaten } => {
-                value_piece(PAWN) - value_piece(game.get_square(beaten).0)
-            },
-            _ => 0
-        }
-    });
-}
-
 
 fn generate_pawn_pushes(game: &Game, side: Side, move_list: &mut Vec<Move>) {
     let pawns = game.pawns(side);