diff options
| author | Aargh Rai <aargh.rai+git@gmail.com> | 2026-07-07 14:30:21 +0530 |
|---|---|---|
| committer | Aargh Rai <aargh.rai+git@gmail.com> | 2026-07-07 14:30:21 +0530 |
| commit | 965bf81879b22a25fd9b0d17ce6defd3d51c6173 (patch) | |
| tree | eeadd04afb52e950a3345c7fa4bc51d94446a658 /src/uci/response.c | |
| parent | 3c540db464f4034d0a393b076c79a26851f68f47 (diff) | |
engine can now send updates to uci
Diffstat (limited to 'src/uci/response.c')
| -rw-r--r-- | src/uci/response.c | 81 |
1 files changed, 72 insertions, 9 deletions
diff --git a/src/uci/response.c b/src/uci/response.c index 83a8ee1..dbf4614 100644 --- a/src/uci/response.c +++ b/src/uci/response.c @@ -84,7 +84,11 @@ enum { }; int current_state = STATE_INITIAL; -void handle_uci(uci_state *state, ucicmd cmd) { +void handle_uci( + uci_state *state, + engine_messages *engine_message, + ucicmd cmd +) { if (current_state == STATE_INITIAL) { return handle_initial(state, cmd); } @@ -98,7 +102,7 @@ void handle_uci(uci_state *state, ucicmd cmd) { return handle_ping(state, cmd); } if (current_state == STATE_ACTIVE) { - return handle_active(state, cmd); + return handle_active(state, engine_message, cmd); } return handle_halt(state, cmd); } @@ -117,7 +121,9 @@ void handle_initial(uci_state *state, ucicmd cmd) { current_state = STATE_IDLE; } -void handle_idle(uci_state *state, ucicmd cmd) { +void handle_idle( + uci_state *state, + ucicmd cmd) { if (cmd.empty) return; if (strcmp(cmd.root, "debug") == 0) { state->debug = strcmp(ucicmd_get_arg(cmd, 0), "on") == 0; @@ -139,7 +145,11 @@ void handle_idle(uci_state *state, ucicmd cmd) { *(--cursor) = 0; apply_option(state, name, buffer); } else if (strcmp(cmd.root, "ucinewgame") == 0) { - // clear game state here + if (state->moves != NULL) { + free(state->moves); + state->moves = NULL; + state->moves_count = 0; + } } else if (strcmp(cmd.root, "position") == 0) { int k = 0; char* mode = ucicmd_get_arg(cmd, 0); @@ -152,16 +162,30 @@ void handle_idle(uci_state *state, ucicmd cmd) { if (cmd.args_count >= k) return; assert(strcmp(ucicmd_get_arg(cmd, k++), "moves") == 0); - struct uci_move *moves = malloc((cmd.args_count - k) * sizeof(struct uci_move)); + assert(state->moves_count <= cmd.args_count - k); + int old_move_count = state->moves_count; + state->moves_count = cmd.args_count - k; + if (state->moves == NULL) { + state->moves = malloc( + state->moves_count * sizeof(struct uci_move) + ); + } else { + state->moves = realloc( + state->moves, + state->moves_count * sizeof(struct uci_move) + ); + } int l = 0; + k += old_move_count; + l += old_move_count; for (; k < cmd.args_count; k++) { char* move = ucicmd_get_arg(cmd, k); - moves[l++] = (struct uci_move) { + state->moves[l++] = (struct uci_move) { (move[0] - 'a') * 8 + (move[1] - '1'), (move[2] - 'a') * 8 + (move[3] - '1') }; } - // SENT state->position & struct uci_move to ENGINE + state->go = 1; } else if (strcmp(cmd.root, "stop") == 0) { } else if (strcmp(cmd.root, "quit") == 0) { free(cmd.args); @@ -206,11 +230,50 @@ void handle_ping(uci_state *state, ucicmd cmd) { current_state = STATE_ACTIVE; } -void handle_active(uci_state *state, ucicmd cmd) { +void handle_active( + uci_state *state, + engine_messages* engine_messages, + ucicmd cmd +) { + 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( + "info depth %d seldepth %d multipv %d score cp %d nodes %d nps %d hashfull %d tbhits %d time %d pv", + old->depth, + old->seldepth, + old->multipv, + old->score_cp, + old->nodes, + old->nps, + old->hashfull, + old->tbhits, + old->time + ); + + for (int j = 0; j < old->pv.count; j++) { + struct uci_move move = old->pv.moves[i]; + printf( + " %c%c%c%c", + (move.from / 8) + 'a', + (move.from % 8) + '1', + (move.to / 8) + 'a', + (move.to % 8) + '1' + ); + } + 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); + } + // TODO: this section will call the engine to analysis if (cmd.empty) { return; } - // TODO: this section will call the engine to analysis if (strcmp(cmd.root, "isready") == 0) { current_state = STATE_PING; } else if (strcmp(cmd.root, "stop") == 0) { |
