diff options
Diffstat (limited to 'src/board.c')
| -rw-r--r-- | src/board.c | 87 | 
1 files changed, 37 insertions, 50 deletions
| diff --git a/src/board.c b/src/board.c index 0c133a8..d88c1ee 100644 --- a/src/board.c +++ b/src/board.c @@ -2,56 +2,6 @@  #include <string.h>  #include "board.h" -int pop_count(Bitboard bb){ -  if (bb == 0) return 0; -  return pop_count(bb >> 1) + (bb & 1); -} - -void print_bitboard(Bitboard bb) { -  for (U64 index = 0; index < 64; index++) { -    printf("%lu", (bb >> index) & 1); -    if ((index + 1) % 8 == 0) printf("\n"); -  } -  printf("\n\n"); -} - - -void precompute_knight_attack_table(Bitboard attacks[64]) { -  for (int index = 0; index < 64; index++) { -    U64 position = BIT << index; - -    attacks[index] = -      ((position & notAFile & notBFile) << 6) | -      ((position & notGFile & notHFile) << 10) | -      ((position & notAFile) << 15) | -      ((position & notHFile) << 17) | -      ((position & notGFile & notHFile) >> 6) | -      ((position & notAFile & notBFile) >> 10) | -      ((position & notHFile) >> 15) | -      ((position & notAFile) >> 17); -  } -} - -void precompute_king_attack_table(Bitboard attacks[64]) { -  for (int index = 0; index < 64; index++) { -    U64 position = BIT << index; - -    attacks[index] = -      (position & notAFile) << 7 | (position << 8) | (position & notHFile) << 9 | -      (position & notAFile) >> 1 |                   (position & notHFile) << 1 | -      (position & notAFile) >> 9 | (position >> 8) | (position & notHFile) >> 7; -  } -} - -void precompute_pawn_attack_table(Bitboard attacks[64], BYTE color) { -  for (int index = 0; index < 64; index++) { -    U64 position = BIT << index; - -    if (color == WHITE) attacks[index] = (position & notAFile) << 7 | (position & notHFile) << 9; -    else                attacks[index] = (position & notAFile) >> 9 | (position & notHFile) >> 7; -  } -} -  Board parse_FEN(char* FEN) {    Board board;    for (int i = 0; i < 12; i++) board.pieces[i] = 0; @@ -138,3 +88,40 @@ void print_board(Board board) {    }    printf("  a b c d e f g h\n");  } + +void precompute_knight_attack_table(Bitboard attacks[64]) { +  for (int index = 0; index < 64; index++) { +    U64 position = BIT << index; + +    attacks[index] = +      ((position & notAFile & notBFile) << 6) | +      ((position & notGFile & notHFile) << 10) | +      ((position & notAFile) << 15) | +      ((position & notHFile) << 17) | +      ((position & notGFile & notHFile) >> 6) | +      ((position & notAFile & notBFile) >> 10) | +      ((position & notHFile) >> 15) | +      ((position & notAFile) >> 17); +  } +} + +void precompute_king_attack_table(Bitboard attacks[64]) { +  for (int index = 0; index < 64; index++) { +    U64 position = BIT << index; + +    attacks[index] = +      (position & notAFile) << 7 | (position << 8) | (position & notHFile) << 9 | +      (position & notAFile) >> 1 |                   (position & notHFile) << 1 | +      (position & notAFile) >> 9 | (position >> 8) | (position & notHFile) >> 7; +  } +} + +void precompute_pawn_attack_table(Bitboard attacks[64], BYTE color) { +  for (int index = 0; index < 64; index++) { +    U64 position = BIT << index; + +    if (color == WHITE) attacks[index] = (position & notAFile) << 7 | (position & notHFile) << 9; +    else                attacks[index] = (position & notAFile) >> 9 | (position & notHFile) >> 7; +  } +} + | 
