aboutsummaryrefslogtreecommitdiff
path: root/src/board.c
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-09-14 17:25:09 +0300
committereug-vs <eugene@eug-vs.xyz>2022-09-14 17:25:09 +0300
commit1373e30387bf5e8e7858e10c9dee4413bf20d71c (patch)
tree21ec9888a613cfe454ccdefa3de2d37854a112f1 /src/board.c
parent2dfa7cecdacacf7ef84e1ca768db6d636e225a0c (diff)
downloadj1chess-1373e30387bf5e8e7858e10c9dee4413bf20d71c.tar.gz
refactor: separate bitboard functionality
Diffstat (limited to 'src/board.c')
-rw-r--r--src/board.c87
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;
+ }
+}
+