add-fen-loader (#5)
All checks were successful
Python tests (make) / test (push) Successful in 10s

Reviewed-on: #5
Co-authored-by: Josh <josh@joshuaschuett.com>
Co-committed-by: Josh <josh@joshuaschuett.com>
This commit is contained in:
2025-08-16 16:51:53 +00:00
committed by Josh
parent b9d2f096e0
commit c02ec7875d
7 changed files with 351 additions and 32 deletions

View File

@@ -1,4 +1,5 @@
#include "bitboard.h"
#include <stdio.h>
uint64_t PAWN_ATTACKS[2][64];
uint64_t KNIGHT_ATTACKS[64];
@@ -58,4 +59,45 @@ void create_king_attack_cache(void) {
KING_ATTACKS[sq] = mask;
}
}
static int first_set_index(uint64_t bb) {
for (int i = 0; i < 64; ++i) {
if ((bb >> i) & 1ULL) return i;
}
return -1;
}
static int pop_lsb_index(uint64_t *bb) {
if (*bb == 0) return -1;
int idx = first_set_index(*bb);
// Clears bit.
*bb &= ~(1ULL << idx);
return idx;
}
void print_board(const struct Board *b) {
static const char PIECE_CH[12] = {
'P','N','B','R','Q','K',
'p','n','b','r','q','k'
};
char grid[64];
for (int i = 0; i < 64; ++i) grid[i] = '.';
for (int p = 0; p < 12; ++p) {
uint64_t bb = b->pieces[p];
while (bb) {
int sq = pop_lsb_index(&bb);
grid[sq] = PIECE_CH[p];
}
}
for (int r = 7; r >= 0; --r) {
for (int f = 0; f < 8; ++f) {
putchar(grid[r * 8 + f]);
if (f < 7) putchar(' ');
}
putchar('\n');
}
}