summaryrefslogtreecommitdiff
path: root/src/search/pawn_moves.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/search/pawn_moves.c')
-rw-r--r--src/search/pawn_moves.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/search/pawn_moves.c b/src/search/pawn_moves.c
index e69de29..58eac83 100644
--- a/src/search/pawn_moves.c
+++ b/src/search/pawn_moves.c
@@ -0,0 +1,47 @@
+#include "../search.h"
+#include <assert.h>
+
+void get_white_pawn_moves(moves_t* moves, position_t position) {
+ bitboard_t enemy_bitboard = blacks(position);
+ bitboard_t friendly_pieces =
+ position.bitboards[WHITE_KING] |
+ position.bitboards[WHITE_QUEEN] |
+ position.bitboards[WHITE_ROOK] |
+ position.bitboards[WHITE_BISHOP] |
+ position.bitboards[WHITE_KNIGHT];
+ bitboard_t friendly_pawns = position.bitboards[WHITE_PAWN];
+ bitboard_t y = friendly_pieces | enemy_bitboard;
+ bitboard_t x = ~((friendly_pawns << 8) & y) & (friendly_pawns << 8);
+ bitboard_t first_move_x = x | BITMASK_RANK_C;
+
+ first_move_x |= (first_move_x << 8) & (~y);
+ x |= first_move_x;
+
+ print_bitboard(x);
+}
+void get_black_pawn_moves(moves_t* moves, position_t position) {
+ bitboard_t enemy_bitboard = whites(position);
+ bitboard_t friendly_pieces =
+ position.bitboards[BLACK_KING] |
+ position.bitboards[BLACK_QUEEN] |
+ position.bitboards[BLACK_ROOK] |
+ position.bitboards[BLACK_BISHOP] |
+ position.bitboards[BLACK_KNIGHT];
+ bitboard_t friendly_pawns = position.bitboards[BLACK_PAWN];
+ bitboard_t y = friendly_pieces | enemy_bitboard;
+ bitboard_t x = ~((friendly_pawns << 8) & y) & (friendly_pawns << 8);
+ bitboard_t first_move_x = x | BITMASK_RANK_F;
+
+ first_move_x |= (first_move_x >> 8) & (~y);
+ x |= first_move_x;
+}
+
+void get_pawn_moves(moves_t* moves, position_t position) {
+ assert_valid_position(position);
+
+ if (position.turn == WHITE_TURN) {
+ get_white_pawn_moves(moves, position);
+ } else {
+ get_black_pawn_moves(moves, position);
+ }
+}