summaryrefslogtreecommitdiff
path: root/src/uci/response.c
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-07-07 23:37:41 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-07-07 23:37:41 +0530
commit2761f8a533e2b025f209222a1e4ec70b91c7e8ee (patch)
treebb1ce2dfbf3f35fb81f8080776a7cc35e0ed3e3a /src/uci/response.c
parent965bf81879b22a25fd9b0d17ce6defd3d51c6173 (diff)
thread spawning from the uci settings & best move & ponder is now sent
uci setup is ALMOST done, i can sense it
Diffstat (limited to 'src/uci/response.c')
-rw-r--r--src/uci/response.c49
1 files changed, 40 insertions, 9 deletions
diff --git a/src/uci/response.c b/src/uci/response.c
index dbf4614..6208a54 100644
--- a/src/uci/response.c
+++ b/src/uci/response.c
@@ -154,10 +154,22 @@ void handle_idle(
int k = 0;
char* mode = ucicmd_get_arg(cmd, 0);
if (strcmp(mode, "startpos") == 0) {
- state->position = load_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
+ struct fen_load fen = load_fen(
+ "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
+ );
+ if (fen.failed) {
+ printf("info invalid fen\n");
+ return;
+ }
+ state->position = fen.position;
}
else if (strcmp(mode, "fen") == 0) {
- state->position = load_fen(ucicmd_get_arg(cmd, k++));
+ struct fen_load fen = load_fen(ucicmd_get_arg(cmd, k++));
+ if (fen.failed) {
+ printf("info invalid fen\n");
+ return;
+ }
+ state->position = fen.position;
} else { assert(0); }
if (cmd.args_count >= k) return;
@@ -185,7 +197,6 @@ void handle_idle(
(move[2] - 'a') * 8 + (move[3] - '1')
};
}
- state->go = 1;
} else if (strcmp(cmd.root, "stop") == 0) {
} else if (strcmp(cmd.root, "quit") == 0) {
free(cmd.args);
@@ -197,10 +208,11 @@ void handle_idle(
free(setting.value.string->data);
}
- exit(0);
+ atomic_store(&state->quit, 1);
} else if (strcmp(cmd.root, "isready") == 0) {
current_state = STATE_SYNC;
} else if (strcmp(cmd.root, "go") == 0) {
+ atomic_store(&state->go, 1);
current_state = STATE_ACTIVE;
} else {
printf("info violation\n");
@@ -238,7 +250,6 @@ void handle_active(
for (int i = 0; i < engine_messages->count; i++) {
struct engine_message *old = engine_messages->data[i];
if (!old->ready) continue;
- printf("INITIALIZED\n");
old->ready = 0;
printf(
@@ -265,10 +276,30 @@ void handle_active(
);
}
printf("\n");
- // // info depth 1 seldepth 1 multipv 1 score cp 18 nodes 20 nps 4000 hashfull 0 tbhits 0 time 5 pv e2e4
- //
- // engine_messages->data[i] = old->next;
- // free(old);
+
+ if (old->best_move.from != 0 && old->best_move.to != 0) {
+ printf(
+ "bestmove %c%c%c%c",
+ (old->best_move.from / 8) + 'a',
+ (old->best_move.from % 8) + '1',
+ (old->best_move.to / 8) + 'a',
+ (old->best_move.to % 8) + '1'
+ );
+ if (old->ponder.from != 0 && old->ponder.to != 0) {
+ printf(
+ " ponder %c%c%c%c",
+ (old->ponder.from / 8) + 'a',
+ (old->ponder.from % 8) + '1',
+ (old->ponder.to / 8) + 'a',
+ (old->ponder.to % 8) + '1'
+ );
+ }
+ printf("\n");
+ }
+
+ engine_messages->data[i] = old->next;
+ free(old->pv.moves);
+ free(old);
}
// TODO: this section will call the engine to analysis
if (cmd.empty) {