Переглянути джерело

improved move application

Nicolas Winkler 3 роки тому
батько
коміт
26df4f0ebc
2 змінених файлів з 4 додано та 55 видалено
  1. 3 4
      src/movegen.rs
  2. 1 51
      src/search.rs

+ 3 - 4
src/movegen.rs

@@ -138,8 +138,7 @@ impl SimpleMove {
 }
 
 
-pub fn generate_moves(game: &Game, side: Side) -> Vec<Move> {
-
+pub fn generate_moves(game: &Game, side: Side, moves: &mut Vec<Move>) {
     let mut moves: Vec<Move> = Vec::with_capacity(128);
     generate_pawn_pushes(game, side, &mut moves);
     generate_pawn_doublepushes(game, side, &mut moves);
@@ -152,7 +151,6 @@ pub fn generate_moves(game: &Game, side: Side) -> Vec<Move> {
     generate_queen_moves(game, side, &mut moves, false);
     generate_king_moves(game, side, &mut moves, false);
     generate_castling_moves(game, side, &mut moves);
-    return moves;
 }
 
 /**
@@ -174,7 +172,8 @@ pub fn generate_possattacking_moves(game: &Game, side: Side) -> Vec<Move> {
 
 
 pub fn generate_legal_moves(game: &Game, side: Side) -> Vec<Move> {
-    let moves = generate_moves(game, side);
+    let mut moves = Vec::new();
+    generate_moves(game, side, &mut moves);
 
     moves.into_iter().filter(|mov| {
         let tryout = super::search::apply_move(game, *mov);

+ 1 - 51
src/search.rs

@@ -57,21 +57,8 @@ pub fn search(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, depth:
     let mut valued_moves: Vec<(Move, PosValue)> = Vec::with_capacity(moves.len());
     let mut cancelled = false;
 
-    let game_before = game.clone();
     for mov in moves {
-        let mut new_game = apply_move(game, mov);
         let undo = game.apply(mov);
-
-        if *game != new_game {
-            info!("move not correct?");
-            info!("move is {}", mov.to_string());
-            info!("game:\n{}", game.beautiful_print());
-            info!("new_game:\n{}", new_game.beautiful_print());
-            info!("CR game: {:?}", game.castling_rights);
-            info!("CR new_game: {:?}", new_game.castling_rights);
-            info!("CR new_game: {:?}", game.castling_rights == new_game.castling_rights);
-            panic!("unequal games");
-        }
         //assert_eq!(new_game, *game, );
 
         let hash_entry: Option<CacheEntry> = None;//hash.lookup(&new_game);
@@ -94,7 +81,7 @@ pub fn search(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, depth:
         }
 
         //info!("searching {}", mov.to_string());
-        let (mut val, ret) = negamax(&mut new_game, sc, hash, -beta, -alpha, depth - 1);
+        let (mut val, ret) = negamax(game, sc, hash, -beta, -alpha, depth - 1);
         val = -val;
 
         if ret {
@@ -121,13 +108,6 @@ pub fn search(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, depth:
         valued_moves.push((mov, -val));
         
         game.undo_move(undo);
-        if *game != game_before {
-            info!("inequal in search");
-            info!("mov was: {}", mov.to_string());
-            info!("game:\n{}", game.beautiful_print());
-            info!("new_game:\n{}", game_before.beautiful_print());
-            panic!("unequal games");
-        }
     }
 
 
@@ -193,7 +173,6 @@ fn negamax(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut alpha:
         }
     }
 
-    let game_before = game.clone();
     for mov in moves {
         let undo = game.apply(mov);
         let (mut val, ret) = negamax(game, sc, hash, -beta, -alpha, depth - 1);
@@ -206,13 +185,6 @@ fn negamax(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut alpha:
 
         if val >= beta {
             game.undo_move(undo);
-            if *game != game_before {
-                info!("move was:\n{}", mov.to_string());
-                info!("unequal in negamax");
-                info!("game:\n{}", game.beautiful_print());
-                info!("new_game:\n{}", game_before.beautiful_print());
-                panic!("unequal games");
-            }
             return (beta, false);
         }
         if val > alpha {
@@ -225,13 +197,6 @@ fn negamax(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut alpha:
             //best_move = mov;
         }
         game.undo_move(undo);
-        if *game != game_before {
-            info!("move was:\n{}", mov.to_string());
-            info!("unequal in negamax");
-            info!("game:\n{}", game.beautiful_print());
-            info!("new_game:\n{}", game_before.beautiful_print());
-            panic!("unequal games");
-        }
     }
 
 
@@ -258,33 +223,18 @@ fn quiescence_search(game: &mut Game, sc: &mut SearchControl, mut alpha: PosValu
 
     let moves = generate_attacking_moves(game, game.turn);
 
-    let game_before = game.clone();
     for mov in moves {
         let undo = game.apply(mov);
 
         let val = -quiescence_search(game, sc, -beta, -alpha, depth - 1);
         if val >= beta {
             game.undo_move(undo);
-            if *game != game_before {
-                info!("move was:\n{}", mov.to_string());
-                info!("unequal in quiescence");
-                info!("game:\n{}", game.beautiful_print());
-                info!("new_game:\n{}", game_before.beautiful_print());
-                panic!("unequal games");
-            }
             return beta;
         }
         if val > alpha {
             alpha = val;
         }
         game.undo_move(undo);
-        if *game != game_before {
-            info!("move was:\n{}", mov.to_string());
-            info!("unequal in quiescence");
-            info!("game:\n{}", game.beautiful_print());
-            info!("new_game:\n{}", game_before.beautiful_print());
-            panic!("unequal games");
-        }
     }
     return alpha;
 }