From f7901374649cd76ac52a6c881c79dc8d64e00981 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 14 Sep 2022 02:59:36 +0300 Subject: feat: compute knight attack table --- src/board.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'src/board.c') 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 #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); + } } -- cgit v1.2.3