1
+ use std:: usize;
1
2
use std:: { ops, sync:: LazyLock } ;
2
3
3
4
use crate :: interface:: { RepresentableType , SetType } ;
@@ -30,7 +31,7 @@ crate::interface::game_details!(
30
31
31
32
impl BitBoard {
32
33
pub fn new ( raw : u64 ) -> BitBoard {
33
- BitBoard ( raw)
34
+ BitBoard :: from ( raw)
34
35
}
35
36
36
37
pub fn shift ( & self , dir : Direction ) -> BitBoard {
@@ -59,16 +60,16 @@ impl BitBoard {
59
60
}
60
61
61
62
pub fn between ( sq_1 : Square , sq_2 : Square ) -> BitBoard {
62
- BETWEEN [ sq_1 as usize ] [ sq_2 as usize ]
63
+ BETWEEN [ u8 :: from ( sq_1) as usize ] [ sq_2. into ( ) ]
63
64
}
64
65
65
66
pub fn between2 ( sq_1 : Square , sq_2 : Square ) -> BitBoard {
66
- BETWEEN [ sq_1 as usize ] [ sq_2 as usize ] | sq_2
67
+ BETWEEN [ u8 :: from ( sq_1) as usize ] [ sq_2. into ( ) ] | sq_2
67
68
}
68
69
}
69
70
70
71
static DIAGONAL : LazyLock < [ BitBoard ; 15 ] > = LazyLock :: new ( || {
71
- const MAIN_DIAGONAL : BitBoard = BitBoard ( 0x8040201008040201u64 ) ;
72
+ const MAIN_DIAGONAL : BitBoard = BitBoard :: from ( 0x8040201008040201u64 ) ;
72
73
73
74
let mut diagonals = [ BitBoard :: EMPTY ; 15 ] ;
74
75
@@ -90,7 +91,7 @@ static DIAGONAL: LazyLock<[BitBoard; 15]> = LazyLock::new(|| {
90
91
} ) ;
91
92
92
93
static ANTI_DIAGONAL : LazyLock < [ BitBoard ; 15 ] > = LazyLock :: new ( || {
93
- const MAIN_ANTI_DIAGONAL : BitBoard = BitBoard ( 0x0102040810204080u64 ) ;
94
+ const MAIN_ANTI_DIAGONAL : BitBoard = BitBoard :: from ( 0x0102040810204080u64 ) ;
94
95
95
96
let mut anti_diagonals = [ BitBoard :: EMPTY ; 15 ] ;
96
97
@@ -147,7 +148,7 @@ static BETWEEN: LazyLock<[[BitBoard; Square::N]; Square::N]> =
147
148
// The intersection between the two blocked rays will be the between
148
149
// BitBoard + Squares 1 and 2. Therefore, to get the between BitBoard, a
149
150
// final intersection operator with the union of Squares 1 and 2 is do
150
- between[ square_1 as usize ] [ square_2 as usize ] =
151
+ between[ square_1. into ( ) ] [ square_2. into ( ) ] =
151
152
moves:: hyperbola ( square_1, blockers, mask)
152
153
& moves:: hyperbola ( square_2, blockers, mask) ;
153
154
}
@@ -172,15 +173,15 @@ impl Square {
172
173
}
173
174
174
175
pub fn shift ( self , dir : Direction ) -> Square {
175
- unsafe { Square :: unsafe_from ( ( self as i8 + dir as i8 ) as u8 ) }
176
+ unsafe { Square :: unsafe_from ( ( u8 :: from ( self ) as i8 + dir as i8 ) as u8 ) }
176
177
}
177
178
178
179
pub fn diagonal ( self ) -> usize {
179
- 7 + self . rank ( ) as usize - self . file ( ) as usize
180
+ 7usize + u8 :: from ( self . rank ( ) ) as usize - self . file ( ) . into ( )
180
181
}
181
182
182
183
pub fn anti_diagonal ( self ) -> usize {
183
- self . rank ( ) as usize + self . file ( ) as usize
184
+ self . rank ( ) . into ( ) + self . file ( ) . into ( )
184
185
}
185
186
}
186
187
0 commit comments