From 3c540db464f4034d0a393b076c79a26851f68f47 Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Mon, 6 Jul 2026 23:39:55 +0530 Subject: removed unnescessary stuff + ipc with shared memory + somehow the build is faster? --- src/bitboard.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/bitboard.c (limited to 'src/bitboard.c') diff --git a/src/bitboard.c b/src/bitboard.c new file mode 100644 index 0000000..565f425 --- /dev/null +++ b/src/bitboard.c @@ -0,0 +1,58 @@ +#include "bitboard.h" +#include +#include +#include + +position_t position_starting() { + return (position_t) { + .bitboards = { + 16ULL, + 8ULL, + 129ULL, + 36ULL, + 66ULL, + 65280ULL, + 1152921504606846976ULL, + 576460752303423488ULL, + 9295429630892703744ULL, + 2594073385365405696ULL, + 4755801206503243776ULL, + 71776119061217280ULL, + }, + .castling = + WHITE_SHORT_CASTLE | WHITE_LONG_CASTLE | + BLACK_SHORT_CASTLE | BLACK_LONG_CASTLE, + .turn = WHITE_TURN, + .passantable_file = 0, + .halfmove_clock = 0, + .fullmove_clock = 1 + }; +} + +void assert_valid_position(position_t position) { + assert(check_valid_position(position) == true); +} + +bool check_valid_position(position_t position) { + if (position.castling > + ( + WHITE_SHORT_CASTLE | WHITE_LONG_CASTLE | + BLACK_SHORT_CASTLE | BLACK_LONG_CASTLE + ) + ) return false; + if (position.turn != WHITE_TURN && position.turn != BLACK_TURN) return false; + if (position.passantable_file > 8) return false; // 0 means no passant + if (position.bitboards[WHITE_KING] == 0) return false; + if (position.bitboards[BLACK_KING] == 0) return false; + return true; +} + +void print_bitboard(bitboard_t bitboard) { + printf("Bitboard(%" PRIu64 ")\n", bitboard); + for (int i = 7; i >= 0; i--) { + for (int j = 0; j < 8; j++) { + printf("%" PRIu64 "", (bitboard >> (8 * i + j)) & 1); + } + printf("\n"); + } +} -- cgit v1.2.3