summaryrefslogtreecommitdiff
path: root/src/engine.c
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-07-07 14:30:21 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-07-07 14:30:21 +0530
commit965bf81879b22a25fd9b0d17ce6defd3d51c6173 (patch)
treeeeadd04afb52e950a3345c7fa4bc51d94446a658 /src/engine.c
parent3c540db464f4034d0a393b076c79a26851f68f47 (diff)
engine can now send updates to uci
Diffstat (limited to 'src/engine.c')
-rw-r--r--src/engine.c83
1 files changed, 30 insertions, 53 deletions
diff --git a/src/engine.c b/src/engine.c
index c5843a4..944c0f4 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <pthread.h>
#include "bitboard.h"
#include "engine/moves.h"
@@ -9,61 +10,37 @@
#include "uci.h"
#include "ipc.h"
-// 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(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);
+ comms *comms = malloc(sizeof(*comms));
+ comms->engine_messages = malloc(sizeof(*comms->engine_messages));
+
+ comms->engine_messages->data = malloc(
+ sizeof(*comms->engine_messages->data) * 1 // TODO: GET FROM UCI SETTINGS
+ );
+ comms->engine_messages->count = 1;
+ comms->engine_messages->data[0] = malloc(sizeof(
+ *comms->engine_messages->data[0]
+ ));
+ comms->engine_messages->data[0]->ready = 0;
+
+ printf("ENGINE: %p\nENGINE MESSAGE: %p\n", comms, comms->engine_messages);
+
+ pthread_t uci_thread;
+ pthread_create(&uci_thread, NULL, &uci, (void*)comms);
+ int k = 0;
+ while (1) {
+ if (k == 0) {
+ struct engine_message *message = comms->engine_messages->data[0];
+ message->depth = 69;
+ message->pv = comm_moves_init();
+ add_comm_move(&message->pv, (struct uci_move) { 14, 24 });
+ message->next = malloc(sizeof(struct engine_message*));
+ printf("\n%p\n", message->pv.moves);
+
+ message->ready = 1;
+ k++;
+ }
}
- 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;
}