1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
pub mod root_moves_list;
use std::cmp::Ordering as CmpOrder;
use pleco::core::score::*;
use pleco::BitMove;
const MAX_MOVES: usize = 250;
#[derive(Copy, Clone,Eq)]
pub struct RootMove {
pub score: i32,
pub prev_score: i32,
pub bit_move: BitMove,
pub depth_reached: i16,
}
impl RootMove {
#[inline]
pub fn new(bit_move: BitMove) -> Self {
RootMove {
bit_move,
score: NEG_INFINITE as i32,
prev_score: NEG_INFINITE as i32,
depth_reached: 0,
}
}
#[inline]
pub fn rollback_insert(&mut self, score: i32, depth: i16) {
self.prev_score = self.score;
self.score = score;
self.depth_reached = depth;
}
#[inline]
pub fn insert(&mut self, score: i32, depth: i16) {
self.score = score;
self.depth_reached = depth;
}
#[inline]
pub fn rollback(&mut self) {
self.prev_score = self.score;
}
}
impl Ord for RootMove {
#[inline]
fn cmp(&self, other: &RootMove) -> CmpOrder {
let value_diff = self.score - other.score;
if value_diff == 0 {
let prev_value_diff = self.prev_score - other.prev_score;
if prev_value_diff == 0 {
return CmpOrder::Equal;
} else if prev_value_diff > 0 {
return CmpOrder::Less;
}
} else if value_diff > 0 {
return CmpOrder::Less;
}
CmpOrder::Greater
}
}
impl PartialOrd for RootMove {
fn partial_cmp(&self, other: &RootMove) -> Option<CmpOrder> {
Some(self.cmp(other))
}
}
impl PartialEq for RootMove {
fn eq(&self, other: &RootMove) -> bool {
self.score == other.score && self.prev_score == other.prev_score
}
}