|  | @@ -5,7 +5,7 @@ use evaluate::*;
 | 
	
		
			
				|  |  |  use log::info;
 | 
	
		
			
				|  |  |  use rand::prelude::*;
 | 
	
		
			
				|  |  |  use std::collections::HashMap;
 | 
	
		
			
				|  |  | -use engine::HashEntry;
 | 
	
		
			
				|  |  | +use hash::{CacheEntry, Cache};
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  enum MoveUndo {
 | 
	
		
			
				|  |  |      Default {
 | 
	
	
		
			
				|  | @@ -39,7 +39,7 @@ pub enum SearchResult {
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * 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 {
 | 
	
		
			
				|  |  |          return SearchResult::Invalid;
 | 
	
	
		
			
				|  | @@ -73,7 +73,7 @@ pub fn search(game: &Game, sc: &mut SearchControl, hash: &mut HashMap<Game, Hash
 | 
	
		
			
				|  |  |      for mov in moves {
 | 
	
		
			
				|  |  |          let new_game = apply_move(game, mov);
 | 
	
		
			
				|  |  |          //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;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if ret {
 | 
	
	
		
			
				|  | @@ -114,6 +114,7 @@ pub fn search(game: &Game, sc: &mut SearchControl, hash: &mut HashMap<Game, Hash
 | 
	
		
			
				|  |  |              return SearchResult::Cancelled(Some((chosen_mov.0, chosen_mov.1)));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          else {
 | 
	
		
			
				|  |  | +            hash.cache(game, CacheEntry::new_value(depth, chosen_mov.1));
 | 
	
		
			
				|  |  |              return SearchResult::Finished(chosen_mov.0, chosen_mov.1);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -122,7 +123,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 {
 | 
	
		
			
				|  |  |          return (quiescence_search(game, sc, alpha, beta, 7), false);
 | 
	
		
			
				|  |  |          let eval = evaluate(game);
 | 
	
	
		
			
				|  | @@ -159,7 +160,7 @@ fn negamax(game: &Game, sc: &mut SearchControl, mut alpha: PosValue, beta: PosVa
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      for mov in moves {
 | 
	
		
			
				|  |  |          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;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if ret {
 | 
	
	
		
			
				|  | @@ -170,7 +171,7 @@ fn negamax(game: &Game, sc: &mut SearchControl, mut alpha: PosValue, beta: PosVa
 | 
	
		
			
				|  |  |              return (beta, false);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if val > alpha {
 | 
	
		
			
				|  |  | -            alpha = (val as f64 * 0.95) as _;
 | 
	
		
			
				|  |  | +            alpha = val;//(val as f64 * 0.95) as _;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //info!(" -> negamaxed {} -> {}", mov.to_string(), depth - 1);
 | 
	
		
			
				|  |  |          if val > best {
 | 
	
	
		
			
				|  | @@ -180,7 +181,7 @@ fn negamax(game: &Game, sc: &mut SearchControl, mut alpha: PosValue, beta: PosVa
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      //info!("best alpha {}", best);
 | 
	
		
			
				|  |  | -    return ((best as f64 * 0.99) as _, false);
 | 
	
		
			
				|  |  | +    return ((alpha as f64 * 0.99) as _, false);
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  fn quiescence_search(game: &Game, si: &mut SearchControl, mut alpha: PosValue, beta: PosValue, depth: i32) -> PosValue {
 |