File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std:: ops:: RangeBounds ;
2
+
1
3
use crate :: bitboard:: Bitboard ;
2
4
3
5
pub struct Board {
@@ -219,6 +221,17 @@ impl Board {
219
221
} ;
220
222
}
221
223
224
+ fn is_starting_position ( & self , color : Color , position : usize ) -> bool {
225
+ match color {
226
+ Color :: White => ( 8 ..16 ) . contains ( & position) ,
227
+ Color :: Black => ( 48 ..56 ) . contains ( & position) ,
228
+ }
229
+ }
230
+
231
+ fn is_square_empty ( & self , index : usize , occupancy : Bitboard ) -> bool {
232
+ !occupancy. is_set ( index)
233
+ }
234
+
222
235
/// Generate all possible moves at the specified square index
223
236
pub fn generate_moves ( & self , index : usize ) -> Vec < usize > {
224
237
let mut moves = Vec :: new ( ) ;
@@ -241,5 +254,12 @@ impl Board {
241
254
if !occupancy. is_set ( single_forward as usize ) {
242
255
moves. push ( single_forward as usize ) ;
243
256
}
257
+
258
+ if self . is_starting_position ( self . turn , position) {
259
+ let double_forward = single_forward + direction;
260
+ if self . is_square_empty ( double_forward as usize , occupancy) {
261
+ moves. push ( double_forward as usize ) ;
262
+ }
263
+ }
244
264
}
245
265
}
You can’t perform that action at this time.
0 commit comments