From 63fa6656749d1cdb6a54a001950048a9660f0d73 Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Tue, 24 Feb 2026 22:49:43 +0530 Subject: pawn forward movement works? --- src/search/pawn_moves.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/search/pawn_moves.c') 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 + +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); + } +} -- cgit v1.2.3