Skip to content

Commit 17ff756

Browse files
committed
generate pawn moves p2
1 parent 4e9bf47 commit 17ff756

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/board.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::RangeBounds;
2+
13
use crate::bitboard::Bitboard;
24

35
pub struct Board {
@@ -219,6 +221,17 @@ impl Board {
219221
};
220222
}
221223

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+
222235
/// Generate all possible moves at the specified square index
223236
pub fn generate_moves(&self, index: usize) -> Vec<usize> {
224237
let mut moves = Vec::new();
@@ -241,5 +254,12 @@ impl Board {
241254
if !occupancy.is_set(single_forward as usize) {
242255
moves.push(single_forward as usize);
243256
}
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+
}
244264
}
245265
}

0 commit comments

Comments
 (0)