From 1373e30387bf5e8e7858e10c9dee4413bf20d71c Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 14 Sep 2022 17:25:09 +0300 Subject: refactor: separate bitboard functionality --- src/board.c | 87 ++++++++++++++++++++++++++----------------------------------- 1 file changed, 37 insertions(+), 50 deletions(-) (limited to 'src/board.c') 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 #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; + } +} + -- cgit v1.2.3