|
@@ -1,4 +1,5 @@
|
|
|
use bitboard::Bitboard;
|
|
|
+use bitboard::*;
|
|
|
use search::Game;
|
|
|
|
|
|
pub type Square = u8;
|
|
@@ -9,12 +10,12 @@ pub const BLACK: Side = true;
|
|
|
|
|
|
pub type PieceType = u8;
|
|
|
|
|
|
-pub const PAWN: PieceType = 0;
|
|
|
-pub const KNIGHT: PieceType = 1;
|
|
|
-pub const BISHOP: PieceType = 2;
|
|
|
-pub const ROOK: PieceType = 3;
|
|
|
-pub const QUEEN: PieceType = 4;
|
|
|
-pub const KING: PieceType = 5;
|
|
|
+pub const PAWN: PieceType = 0;
|
|
|
+pub const KNIGHT: PieceType = 1;
|
|
|
+pub const BISHOP: PieceType = 2;
|
|
|
+pub const ROOK: PieceType = 3;
|
|
|
+pub const QUEEN: PieceType = 4;
|
|
|
+pub const KING: PieceType = 5;
|
|
|
|
|
|
|
|
|
pub struct SimpleMove {
|
|
@@ -23,13 +24,17 @@ pub struct SimpleMove {
|
|
|
}
|
|
|
|
|
|
pub enum Move {
|
|
|
- Default { mov: SimpleMove, capture: PieceType },
|
|
|
- Castling { side: Side, left: bool },
|
|
|
- EnPassant { side: Side, column: u8},
|
|
|
- Promotion { side: Side, column: u8, promote_to: PieceType },
|
|
|
+ Default { mov: SimpleMove, piece_type: PieceType, capture: PieceType },
|
|
|
+ Castling { side: Side, left: bool },
|
|
|
+ EnPassant { side: Side, column: u8 },
|
|
|
+ Promotion { side: Side, column: u8, promote_to: PieceType, capture: PieceType },
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+/**
|
|
|
+ * \brief Iterator to serialize bitboard bit for bit
|
|
|
+ *
|
|
|
+ * Extracts each bit out of the bitboard and returns each one as a separate bitboard.
|
|
|
+ */
|
|
|
pub struct BitboardIterator { pub board: Bitboard }
|
|
|
|
|
|
impl Iterator for BitboardIterator {
|
|
@@ -41,28 +46,65 @@ impl Iterator for BitboardIterator {
|
|
|
self.board &= !lsb;
|
|
|
//Some(lsb.trailing_zeros())
|
|
|
Some(lsb)
|
|
|
+ } else {
|
|
|
+ None
|
|
|
}
|
|
|
- else {
|
|
|
- None
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-fn generate_pawn_moves(game: &Game, side: Side)
|
|
|
-{
|
|
|
+pub fn generate_pawn_moves(game: &Game, side: Side) -> Bitboard {
|
|
|
+ let pushed = generate_pawn_pushes(game, side);
|
|
|
+ let iter = BitboardIterator { board: pushed };
|
|
|
+ for p in iter {
|
|
|
+ println!("{}", p.trailing_zeros());
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+fn generate_pawn_pushes(game: &Game, side: Side) -> Bitboard {
|
|
|
let pawns = game.pawns(side);
|
|
|
+ let others = game.get_all_side(!side);
|
|
|
+ let moved_pawns =
|
|
|
+ match side {
|
|
|
+ WHITE => north_one(pawns),
|
|
|
+ BLACK => south_one(pawns)
|
|
|
+ }
|
|
|
+ & !(ROW_1 | ROW_8);
|
|
|
+
|
|
|
+ let possible_pushes = moved_pawns & !others;
|
|
|
+ return possible_pushes;
|
|
|
}
|
|
|
|
|
|
+fn generate_pawn_captures(game: &Game, side: Side, move_list: &mut Vec<Move>) {
|
|
|
+ let pawns = game.pawns(side);
|
|
|
+ let others = game.get_all_side(!side);
|
|
|
+ let moved_pawns_left =
|
|
|
+ match side {
|
|
|
+ WHITE => northeast_one(pawns),
|
|
|
+ BLACK => southeast_one(pawns)
|
|
|
+ };
|
|
|
+ let moved_pawns_right =
|
|
|
+ match side {
|
|
|
+ WHITE => northwest_one(pawns),
|
|
|
+ BLACK => southwest_one(pawns)
|
|
|
+ };
|
|
|
+
|
|
|
+ let left_captures = moved_pawns_left & others;
|
|
|
+ let right_captures = moved_pawns_right & others;
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
use search::Game;
|
|
|
use movegen::*;
|
|
|
+
|
|
|
#[test]
|
|
|
fn pawn_pushes() {
|
|
|
- let game: Game = Game::default();
|
|
|
+ let mut game: Game = Game::default();
|
|
|
let pawn_moves = generate_pawn_moves(&game, WHITE);
|
|
|
assert_eq!(pawn_moves, ());
|
|
|
}
|