@@ -221,17 +221,26 @@ impl Board {
221
221
} ;
222
222
}
223
223
224
- fn is_starting_position ( & self , color : Color , position : usize ) -> bool {
224
+ /// Check if pawn position is starting position
225
+ fn is_pawn_starting_position ( & self , color : Color , position : usize ) -> bool {
225
226
match color {
226
227
Color :: White => ( 8 ..16 ) . contains ( & position) ,
227
228
Color :: Black => ( 48 ..56 ) . contains ( & position) ,
228
229
}
229
230
}
230
231
232
+ /// Check is square is empty
231
233
fn is_square_empty ( & self , index : usize , occupancy : Bitboard ) -> bool {
232
234
!occupancy. is_set ( index)
233
235
}
234
236
237
+ fn is_square_enemy ( & self , color : Color , position : usize ) -> bool {
238
+ match color {
239
+ Color :: White => self . black_occupancy . is_set ( position) ,
240
+ Color :: Black => self . white_occupancy . is_set ( position) ,
241
+ }
242
+ }
243
+
235
244
/// Generate all possible moves at the specified square index
236
245
pub fn generate_moves ( & self , index : usize ) -> Vec < usize > {
237
246
let mut moves = Vec :: new ( ) ;
@@ -255,11 +264,20 @@ impl Board {
255
264
moves. push ( single_forward as usize ) ;
256
265
}
257
266
258
- if self . is_starting_position ( self . turn , position) {
267
+ if self . is_pawn_starting_position ( self . turn , position) {
259
268
let double_forward = single_forward + direction;
260
269
if self . is_square_empty ( double_forward as usize , occupancy) {
261
270
moves. push ( double_forward as usize ) ;
262
271
}
263
272
}
273
+
274
+ let left_capture = single_forward - 1 ;
275
+ let right_capture = single_forward + 1 ;
276
+ if self . is_square_enemy ( self . turn , left_capture as usize ) {
277
+ moves. push ( left_capture as usize ) ;
278
+ }
279
+ if self . is_square_enemy ( self . turn , right_capture as usize ) {
280
+ moves. push ( right_capture as usize ) ;
281
+ }
264
282
}
265
283
}
0 commit comments