-
Notifications
You must be signed in to change notification settings - Fork 36
/
counter_move.rs
43 lines (34 loc) · 1.07 KB
/
counter_move.rs
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
use std::ops::{Index,IndexMut};
use pleco::core::masks::*;
use pleco::{SQ,BitMove,Piece};
use super::StatBoard;
/// CounterMoveHistory stores counter moves indexed by [player][piece][to] of the previous
/// move
pub struct CounterMoveHistory {
a: [[BitMove; SQ_CNT]; PIECE_CNT]
}
// [Us][Piece][To SQ]
#[allow(non_camel_case_types)]
type CM_idx = (Piece, SQ);
impl Index<CM_idx> for CounterMoveHistory {
type Output = BitMove;
#[inline(always)]
fn index(&self, idx: CM_idx) -> &Self::Output {
unsafe {
self.a.get_unchecked(idx.0 as usize) // [Piece Moved]
.get_unchecked((idx.1).0 as usize) // [To SQ]
}
}
}
impl IndexMut<CM_idx> for CounterMoveHistory {
#[inline(always)]
fn index_mut(&mut self, idx: CM_idx) -> &mut Self::Output {
unsafe {
self.a.get_unchecked_mut(idx.0 as usize) // [Piece Moved]
.get_unchecked_mut((idx.1).0 as usize) // [To SQ]
}
}
}
impl StatBoard<BitMove, CM_idx> for CounterMoveHistory {
const FILL: BitMove = BitMove::null();
}