From c38475eb5d82f6e587faf2956a7eba3085890e99 Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Fri, 29 May 2026 12:19:52 +0530 Subject: logging system works --- src/engine.c | 102 ++++++++++++++++++++--------------------------------------- 1 file changed, 34 insertions(+), 68 deletions(-) (limited to 'src/engine.c') diff --git a/src/engine.c b/src/engine.c index b4a4051..3c55146 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2,16 +2,9 @@ #include #include "engine/bitboard.h" #include "engine/moves.h" - -void comms_main(); -int direct_run(); - -int main(int argc, char** argv) { - if (argc == 1) return direct_run(); - assert(argc == 2); - comms_main(); - return 0; -} +#include "fcntl.h" +#include "ipc.c" +#include "logger/logger.h" struct sqrstr { char data[2]; @@ -21,65 +14,38 @@ struct sqrstr sqr_to_str(int i) { return (struct sqrstr) { .data = {(i / 10) + '0', (i % 10) + '0' } }; } -#include "ipc.c" -void comms_main() { - mqd_t tx = mq_open("/engine_to_server", O_WRONLY); - mqd_t rx = mq_open("/server_to_engine", O_RDONLY); - - while (1) { - char* x = read_queue(rx); - printf("Engine received: %s", x); - free(x); - - send_queue(tx, "Sending", 8); - - moves_t moves = moves_init(); - position_t position = position_starting(); - - get_moves(&moves, position); - char buf[128]; - for (int i = 0; i <= moves.length / 32; i++) { - for (int ii = 0; ii < 32; ii++) { - if (moves.length <= 4 * i + ii) continue; - struct sqrstr from_str = sqr_to_str(moves.moves[4 * i + ii].from); - struct sqrstr to_str = sqr_to_str(moves.moves[4 * i + ii].to); - buf[4 * ii + 0] = from_str.data[0]; - buf[4 * ii + 1] = from_str.data[1]; - buf[4 * ii + 2] = to_str.data[0]; - buf[4 * ii + 3] = to_str.data[1]; - } - send_queue(tx, buf, sizeof(buf)); - } - } -} - -int direct_run() { - moves_t moves = moves_init(); - position_t position = position_starting(); - -position.bitboards[WHITE_KING] = 16ULL; -position.bitboards[WHITE_QUEEN] = 268435456ULL; -position.bitboards[WHITE_ROOK] = 16777344ULL; -position.bitboards[WHITE_BISHOP] = 67108896ULL; -position.bitboards[WHITE_KNIGHT] = 66ULL; -position.bitboards[WHITE_PAWN] = 65280ULL; -position.bitboards[BLACK_KING] = 1152921504606846976ULL; -position.bitboards[BLACK_QUEEN] = 576460752303423488ULL; -position.bitboards[BLACK_ROOK] = 9295429630892703744ULL; -position.bitboards[BLACK_BISHOP] = 2594073385365405696ULL; -position.bitboards[BLACK_KNIGHT] = 4611687117939015680ULL; -position.bitboards[BLACK_PAWN] = 71776119061217280ULL; - - get_queen_moves(&moves, position); - - bitboard_t b = 0; - - for (int i = 0; i < moves.length; i++) { - b |= (bitboard_t)1 << moves.moves[i].to; - printf("%d %d | ", (moves.moves[i].from), (moves.moves[i].to)); - } +int main(void) { + mqd_t logging = mq_open("/logs", O_WRONLY); + log_infof("Hello World"); + // mqd_t tx = mq_open("/engine_to_server", O_WRONLY); + // mqd_t rx = mq_open("/server_to_engine", O_RDONLY); + // + // while (1) { + // char* x = read_queue(rx); + // log_infof("Engine received: %s", x); + // free(x); + // + // send_queue(tx, "Sending", 8); + // + // moves_t moves = moves_init(); + // position_t position = position_starting(); + // + // get_moves(&moves, position); + // char buf[128]; + // for (int i = 0; i <= moves.length / 32; i++) { + // for (int ii = 0; ii < 32; ii++) { + // if (moves.length <= 4 * i + ii) continue; + // struct sqrstr from_str = sqr_to_str(moves.moves[4 * i + ii].from); + // struct sqrstr to_str = sqr_to_str(moves.moves[4 * i + ii].to); + // buf[4 * ii + 0] = from_str.data[0]; + // buf[4 * ii + 1] = from_str.data[1]; + // buf[4 * ii + 2] = to_str.data[0]; + // buf[4 * ii + 3] = to_str.data[1]; + // } + // send_queue(tx, buf, sizeof(buf)); + // } + // } - print_bitboard(b); return 0; } -- cgit v1.2.3