Skip to content

Commit 8331f4d

Browse files
Simplify away quiet history factorizer (#1037)
STC Elo | -2.31 +- 1.82 (95%) SPRT | 8.0+0.08s Threads=1 Hash=16MB LLR | -2.97 (-2.94, 2.94) [-2.75, 0.25] Games | N: 36876 W: 9275 L: 9520 D: 18081 Penta | [154, 4421, 9488, 4266, 109] https://recklesschess.space/test/14827/ LTC Elo | -0.01 +- 1.06 (95%) SPRT | 40.0+0.40s Threads=1 Hash=64MB LLR | 2.89 (-2.25, 2.89) [-2.75, 0.25] Games | N: 94916 W: 23415 L: 23418 D: 48083 Penta | [60, 10778, 25774, 10797, 49] https://recklesschess.space/test/14753/ Bench: 3686905
1 parent 5e669a6 commit 8331f4d

1 file changed

Lines changed: 9 additions & 37 deletions

File tree

src/history.rs

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,23 @@ fn apply_bonus<const MAX: i32>(entry: &mut i16, bonus: i32) {
1111
*entry += (bonus - bonus.abs() * (*entry) as i32 / MAX) as i16;
1212
}
1313

14-
struct QuietHistoryEntry {
15-
factorizer: i16,
16-
buckets: [[i16; 2]; 2],
17-
}
18-
19-
impl QuietHistoryEntry {
20-
const MAX_FACTORIZER: i32 = 1833;
21-
const MAX_BUCKET: i32 = 6441;
22-
23-
pub const fn bucket(&self, threats: Bitboard, mv: Move) -> i16 {
24-
let from_threatened = threats.contains(mv.from()) as usize;
25-
let to_threatened = threats.contains(mv.to()) as usize;
26-
27-
self.buckets[from_threatened][to_threatened]
28-
}
29-
30-
pub fn update_factorizer(&mut self, bonus: i32) {
31-
let entry = &mut self.factorizer;
32-
apply_bonus::<{ Self::MAX_FACTORIZER }>(entry, bonus);
33-
}
34-
35-
pub fn update_bucket(&mut self, threats: Bitboard, mv: Move, bonus: i32) {
36-
let from_threatened = threats.contains(mv.from()) as usize;
37-
let to_threatened = threats.contains(mv.to()) as usize;
38-
39-
let entry = &mut self.buckets[from_threatened][to_threatened];
40-
apply_bonus::<{ Self::MAX_BUCKET }>(entry, bonus);
41-
}
42-
}
43-
4414
pub struct QuietHistory {
45-
entries: Box<[FromToHistory<QuietHistoryEntry>; 2]>,
15+
// [side_to_move][from_threatened][to_threatened][from][to]
16+
entries: Box<[[[FromToHistory<i16>; 2]; 2]; 2]>,
4617
}
4718

4819
impl QuietHistory {
20+
const MAX_HISTORY: i32 = 8192;
21+
4922
pub fn get(&self, threats: Bitboard, stm: Color, mv: Move) -> i32 {
50-
let entry = &self.entries[stm][mv.from()][mv.to()];
51-
(entry.factorizer + entry.bucket(threats, mv)) as i32
23+
self.entries[stm][threats.contains(mv.from()) as usize][threats.contains(mv.to()) as usize][mv.from()][mv.to()]
24+
as i32
5225
}
5326

5427
pub fn update(&mut self, threats: Bitboard, stm: Color, mv: Move, bonus: i32) {
55-
let entry = &mut self.entries[stm][mv.from()][mv.to()];
56-
57-
entry.update_factorizer(bonus);
58-
entry.update_bucket(threats, mv, bonus);
28+
let entry = &mut self.entries[stm][threats.contains(mv.from()) as usize][threats.contains(mv.to()) as usize]
29+
[mv.from()][mv.to()];
30+
apply_bonus::<{ Self::MAX_HISTORY }>(entry, bonus);
5931
}
6032
}
6133

0 commit comments

Comments
 (0)