diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-27 22:17:33 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-27 22:17:33 +0300 |
commit | 63603ce3e510d2c8f8025f39b49c61caf8769276 (patch) | |
tree | 89e393965060a2043c61c3b9b70a5d93e8c6e67f /src/board/engine.rs | |
parent | 6077a6afe1a30ee567d1a75c38084af3d00df5ed (diff) | |
download | chessnost-63603ce3e510d2c8f8025f39b49c61caf8769276.tar.gz |
refactor: separate hash_move function
Diffstat (limited to 'src/board/engine.rs')
-rw-r--r-- | src/board/engine.rs | 28 |
1 files 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<Move> { + 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<Move>) -> Vec<Move> { 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 => {}, } |