|  | @@ -6,6 +6,7 @@ use log::info;
 | 
											
												
													
														|  |  use rand::prelude::*;
 |  |  use rand::prelude::*;
 | 
											
												
													
														|  |  use std::collections::HashMap;
 |  |  use std::collections::HashMap;
 | 
											
												
													
														|  |  use engine::HashEntry;
 |  |  use engine::HashEntry;
 | 
											
												
													
														|  | 
 |  | +use hash::*;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  enum MoveUndo {
 |  |  enum MoveUndo {
 | 
											
												
													
														|  |      Default {
 |  |      Default {
 | 
											
										
											
												
													
														|  | @@ -39,7 +40,7 @@ pub enum SearchResult {
 | 
											
												
													
														|  |  /**
 |  |  /**
 | 
											
												
													
														|  |   * searches for moves and returns the best move found plus its value
 |  |   * searches for moves and returns the best move found plus its value
 | 
											
												
													
														|  |   */
 |  |   */
 | 
											
												
													
														|  | -pub fn search(game: &Game, sc: &mut SearchControl, hash: &mut HashMap<Game, HashEntry>, depth: i32) -> SearchResult {
 |  | 
 | 
											
												
													
														|  | 
 |  | +pub fn search(game: &Game, sc: &mut SearchControl, hash: &mut Cache, depth: i32) -> SearchResult {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      if depth == 0 {
 |  |      if depth == 0 {
 | 
											
												
													
														|  |          return SearchResult::Invalid;
 |  |          return SearchResult::Invalid;
 | 
											
										
											
												
													
														|  | @@ -72,8 +73,21 @@ pub fn search(game: &Game, sc: &mut SearchControl, hash: &mut HashMap<Game, Hash
 | 
											
												
													
														|  |      let mut cancelled = false;
 |  |      let mut cancelled = false;
 | 
											
												
													
														|  |      for mov in moves {
 |  |      for mov in moves {
 | 
											
												
													
														|  |          let new_game = apply_move(game, mov);
 |  |          let new_game = apply_move(game, mov);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        let hash_entry = hash.lookup(&new_game);
 | 
											
												
													
														|  | 
 |  | +        if let Some(he) = hash_entry {
 | 
											
												
													
														|  | 
 |  | +            match he.entry_type {
 | 
											
												
													
														|  | 
 |  | +                EntryType::Value => {
 | 
											
												
													
														|  | 
 |  | +                    if he.depth >= depth {
 | 
											
												
													
														|  | 
 |  | +                        valued_moves.push((mov, he.value));
 | 
											
												
													
														|  | 
 |  | +                        continue;
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |          //info!("searching {}", mov.to_string());
 |  |          //info!("searching {}", mov.to_string());
 | 
											
												
													
														|  | -        let (mut val, ret) = negamax(&new_game, sc, -beta, -alpha, depth - 1);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        let (mut val, ret) = negamax(&new_game, sc, hash, -beta, -alpha, depth - 1);
 | 
											
												
													
														|  |          val = -val;
 |  |          val = -val;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          if ret {
 |  |          if ret {
 | 
											
										
											
												
													
														|  | @@ -122,7 +136,7 @@ pub fn search(game: &Game, sc: &mut SearchControl, hash: &mut HashMap<Game, Hash
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -fn negamax(game: &Game, sc: &mut SearchControl, mut alpha: PosValue, beta: PosValue, depth: i32) -> (PosValue, bool) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +fn negamax(game: &Game, sc: &mut SearchControl, hash: &mut Cache, mut alpha: PosValue, beta: PosValue, depth: i32) -> (PosValue, bool) {
 | 
											
												
													
														|  |      if depth == 0 {
 |  |      if depth == 0 {
 | 
											
												
													
														|  |          return (quiescence_search(game, sc, alpha, beta, 7), false);
 |  |          return (quiescence_search(game, sc, alpha, beta, 7), false);
 | 
											
												
													
														|  |          let eval = evaluate(game);
 |  |          let eval = evaluate(game);
 | 
											
										
											
												
													
														|  | @@ -159,7 +173,7 @@ fn negamax(game: &Game, sc: &mut SearchControl, mut alpha: PosValue, beta: PosVa
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |      for mov in moves {
 |  |      for mov in moves {
 | 
											
												
													
														|  |          let new_game = apply_move(game, mov);
 |  |          let new_game = apply_move(game, mov);
 | 
											
												
													
														|  | -        let (mut val, ret) = negamax(&new_game, sc, -beta, -alpha, depth - 1);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        let (mut val, ret) = negamax(&new_game, sc, hash, -beta, -alpha, depth - 1);
 | 
											
												
													
														|  |          val = -val;
 |  |          val = -val;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          if ret {
 |  |          if ret {
 |