summaryrefslogtreecommitdiff
path: root/src/engine.c
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-07-06 23:39:55 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-07-06 23:39:55 +0530
commit3c540db464f4034d0a393b076c79a26851f68f47 (patch)
treee9e94fb838b05818948f4f4596f0db6acba4402c /src/engine.c
parent1876294f217d7faa2a07dbaaaab82d142ce42803 (diff)
removed unnescessary stuff + ipc with shared memory + somehow the build is faster?
Diffstat (limited to 'src/engine.c')
-rw-r--r--src/engine.c112
1 files changed, 60 insertions, 52 deletions
diff --git a/src/engine.c b/src/engine.c
index 3c64cce..c5843a4 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -1,63 +1,71 @@
-#include <assert.h>
+#include <stdio.h>
#include <string.h>
-#include "engine/bitboard.h"
+#include <unistd.h>
+
+#include "bitboard.h"
#include "engine/moves.h"
-#include "engine/fen.h"
+#include "fen.h"
#include "fcntl.h"
-#include "ipc.c"
-
-struct sqrstr {
- char data[2];
-};
-struct sqrstr sqr_to_str(int i) {
- assert(i < 64);
- return (struct sqrstr) { .data = {(i / 10) + '0', (i % 10) + '0' } };
-}
-
-int main(void) {
- while (1) {
- char* x = read_queue(rx);
- log_infof("Received: %s", x);
-
- moves_t moves = moves_init();
- struct fen_load result = load_fen(x);
- free(x);
-
- if (result.failed) {
- log_warnf("Invalid fen");
- send_queue(tx, "Failed", 7);
- return 0;
- }
- log_infof("Valid fen");
+#include "uci.h"
+#include "ipc.h"
- position_t position = result.position;
+// struct sqrstr {
+// char data[2];
+// };
+// struct sqrstr sqr_to_str(int i) {
+// assert(i < 64);
+// return (struct sqrstr) { .data = {(i / 10) + '0', (i % 10) + '0' } };
+// }
- get_moves(&moves, position);
- send_queue(tx, "Sending", 8);
- char buf[65];
- int k = 0;
- for (int i = 0; i < moves.length; i++) {
- struct sqrstr from_str = sqr_to_str(moves.moves[i].from);
- struct sqrstr to_str = sqr_to_str(moves.moves[i].to);
- buf[k++] = from_str.data[0];
- buf[k++] = from_str.data[1];
- buf[k++] = to_str.data[0];
- buf[k++] = to_str.data[1];
- if (k != 64) continue;
- buf[k] = 0;
- send_queue(tx, buf, sizeof(buf));
- k = 0;
- }
- if (k != 0) send_queue(tx, buf, sizeof(buf));
- char end_transmission[] = "END-TRANSMISSION";
- int n = strlen(end_transmission);
- log_infof("%s", end_transmission);
- send_queue(tx, end_transmission, n + 1);
+int main(int argc, char** argv) {
+ comms *state = create_shared_memory(sizeof(comms));
+ printf("ENGINE: %p\n", state);
+ state->uci_message_ready = 69;
+ if (fork() == 0) {
+ return uci(state);
}
+ while (1) {}
+ // while (1) {
+ // char* x = read_queue(rx);
+ // log_infof("Received: %s", x);
+ //
+ // moves_t moves = moves_init();
+ // struct fen_load result = load_fen(x);
+ // free(x);
+ //
+ // if (result.failed) {
+ // log_warnf("Invalid fen");
+ // send_queue(tx, "Failed", 7);
+ // return 0;
+ // }
+ // log_infof("Valid fen");
+ //
+ // position_t position = result.position;
+ //
+ // get_moves(&moves, position);
+ // send_queue(tx, "Sending", 8);
+ // char buf[65];
+ // int k = 0;
+ // for (int i = 0; i < moves.length; i++) {
+ // struct sqrstr from_str = sqr_to_str(moves.moves[i].from);
+ // struct sqrstr to_str = sqr_to_str(moves.moves[i].to);
+ // buf[k++] = from_str.data[0];
+ // buf[k++] = from_str.data[1];
+ // buf[k++] = to_str.data[0];
+ // buf[k++] = to_str.data[1];
+ // if (k != 64) continue;
+ // buf[k] = 0;
+ // send_queue(tx, buf, sizeof(buf));
+ // k = 0;
+ // }
+ // if (k != 0) send_queue(tx, buf, sizeof(buf));
+ // char end_transmission[] = "END-TRANSMISSION";
+ // int n = strlen(end_transmission);
+ // log_infof("%s", end_transmission);
+ // send_queue(tx, end_transmission, n + 1);
+ // }
return 0;
}
-#include "engine/bitboard.c"
#include "engine/moves.c"
-#include "engine/fen.c"