aboutsummaryrefslogtreecommitdiff
path: root/src/board.c
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-09-14 02:59:36 +0300
committereug-vs <eugene@eug-vs.xyz>2022-09-14 02:59:36 +0300
commitf7901374649cd76ac52a6c881c79dc8d64e00981 (patch)
tree4bc0f4aaa5c36b9618f70362f4b13f816216c11d /src/board.c
parent87514fc685ea45241dbb00471388638e0be1b229 (diff)
downloadj1chess-f7901374649cd76ac52a6c881c79dc8d64e00981.tar.gz
feat: compute knight attack table
Diffstat (limited to 'src/board.c')
-rw-r--r--src/board.c32
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);
+ }
}