summaryrefslogtreecommitdiff
path: root/src/search/pawn_moves.c
blob: e169c07150706c252de2fcecd82893cfbc07acae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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);
  }
}