From 63603ce3e510d2c8f8025f39b49c61caf8769276 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 27 Jan 2023 22:17:33 +0300 Subject: refactor: separate hash_move function --- src/board/engine.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/board/engine.rs b/src/board/engine.rs index feb3368..e11d96e 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -187,6 +187,18 @@ impl Board { 0.0 } + pub fn hash_move(&self) -> Option { + match self.transposition_table[(self.hash % TTABLE_SIZE) as usize] { + Some(item) => { + if item.hash == self.hash { + return Some(item.best_move) + } + None + } + None => None + } + } + pub fn order_moves(&self, moves: Vec) -> Vec { let mut moves_with_eval: Vec<(Move, f32)> = moves .iter() @@ -216,12 +228,8 @@ impl Board { let mut moves = self.generate_pseudolegal_moves(color); moves = self.order_moves(moves); - match self.transposition_table[(self.hash % TTABLE_SIZE) as usize] { - Some(item) => { - if item.hash == self.hash { - moves.insert(0, item.best_move); - } - } + match self.hash_move() { + Some(mov) => moves.insert(0, mov), None => {}, } @@ -292,12 +300,8 @@ impl Board { let mut moves = self.generate_pseudolegal_moves(color); moves = self.order_moves(moves); - match self.transposition_table[(self.hash % TTABLE_SIZE) as usize] { - Some(item) => { - if item.hash == self.hash { - moves.insert(0, item.best_move); - } - } + match self.hash_move() { + Some(mov) => moves.insert(0, mov), None => {}, } -- cgit v1.2.3