diff options
Diffstat (limited to 'src/board.c')
-rw-r--r-- | src/board.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/board.c b/src/board.c index bc5855f..59b6043 100644 --- a/src/board.c +++ b/src/board.c @@ -1,10 +1,32 @@ +#include <stdio.h> #include "board.h" -BYTE notation_to_index(char file, int rank) { - return (rank - 1) * 8 + (file - 'a'); +int pop_count(Bitboard bb){ + if (bb == 0) return 0; + return pop_count(bb >> 1) + (bb & 1); } -void index_to_notation(BYTE index, char notation[2]) { - notation[0] = (index & 0b0111) + 'a'; - notation[1] = (index >> 3) + '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 = (U64)1 << 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); + } } |