diff options
Diffstat (limited to 'src/uci/response.c')
| -rw-r--r-- | src/uci/response.c | 79 |
1 files changed, 71 insertions, 8 deletions
diff --git a/src/uci/response.c b/src/uci/response.c index 6208a54..7ebe49c 100644 --- a/src/uci/response.c +++ b/src/uci/response.c @@ -3,8 +3,9 @@ #include <stdlib.h> #include "response.h" -#include "../fen.h" -#include "../bitboard.h" +#include "ipc.h" +#include "fen.h" +#include "bitboard.h" void apply_option(uci_state *state, char *name, char *buffer) { int settings_count = sizeof(state->option_settings)/sizeof(option_setting_t); @@ -212,6 +213,48 @@ void handle_idle( } else if (strcmp(cmd.root, "isready") == 0) { current_state = STATE_SYNC; } else if (strcmp(cmd.root, "go") == 0) { + state->go_args = malloc(sizeof(struct go_args)); + struct go_args *info = state->go_args; + for (int i = 0; i < cmd.args_count; i++) { + if (strcmp(ucicmd_get_arg(cmd, i), "searchmoves") == 0) { + info->searchmoves = comm_moves_init(); + for (i++; i < cmd.args_count; i++) { + char* move_str = ucicmd_get_arg(cmd, i); + if (move_str[1] < '0' || move_str[1] > '9') break; + + add_comm_move(&info->searchmoves, (struct uci_move) { + (move_str[0] - 'a') * 8 + (move_str[1] - '1'), + (move_str[2] - 'a') * 8 + (move_str[3] - '1') + }); + } + i--; + } else if (strcmp(ucicmd_get_arg(cmd, i), "ponder") == 0) { + info->ponder = true; + } else if (strcmp(ucicmd_get_arg(cmd, i), "wtime") == 0) { + info->wtime = atoi(ucicmd_get_arg(cmd, ++i)); + } else if (strcmp(ucicmd_get_arg(cmd, i), "btime") == 0) { + info->btime = atoi(ucicmd_get_arg(cmd, ++i)); + } else if (strcmp(ucicmd_get_arg(cmd, i), "winc") == 0) { + info->winc = atoi(ucicmd_get_arg(cmd, ++i)); + } else if (strcmp(ucicmd_get_arg(cmd, i), "binc") == 0) { + info->binc = atoi(ucicmd_get_arg(cmd, ++i)); + } else if (strcmp(ucicmd_get_arg(cmd, i), "movestogo") == 0) { + info->movestogo = atoi(ucicmd_get_arg(cmd, ++i)); + } else if (strcmp(ucicmd_get_arg(cmd, i), "depth") == 0) { + info->depth = atoi(ucicmd_get_arg(cmd, ++i)); + } else if (strcmp(ucicmd_get_arg(cmd, i), "nodes") == 0) { + info->nodes = atoi(ucicmd_get_arg(cmd, ++i)); + } else if (strcmp(ucicmd_get_arg(cmd, i), "mate") == 0) { + info->mate = atoi(ucicmd_get_arg(cmd, ++i)); + } else if (strcmp(ucicmd_get_arg(cmd, i), "movetime") == 0) { + info->movetime = atoi(ucicmd_get_arg(cmd, ++i)); + } else if (strcmp(ucicmd_get_arg(cmd, i), "infinite") == 0) { + info->infinite = true; + } else if (strcmp(ucicmd_get_arg(cmd, i), "perft") == 0) { + info->perft = atoi(ucicmd_get_arg(cmd, ++i)); + } + } + atomic_store(&state->go, 1); current_state = STATE_ACTIVE; } else { @@ -247,17 +290,31 @@ void handle_active( engine_messages* engine_messages, ucicmd cmd ) { + while (atomic_load(&state->go_ready_receive) == 0); + + bool ended = false; for (int i = 0; i < engine_messages->count; i++) { struct engine_message *old = engine_messages->data[i]; + if (old == NULL) continue; if (!old->ready) continue; 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", + "info depth %d seldepth %d multipv %d ", old->depth, old->seldepth, - old->multipv, - old->score_cp, + old->multipv + ); + if (old->mate) { + printf("mate %d ", old->mate); + } else { + printf("score cp %d ", old->score_cp); + } + if (old->node_limit) { + printf("upperbound "); + } + printf( + "nodes %d nps %d hashfull %d tbhits %d time %d pv", old->nodes, old->nps, old->hashfull, @@ -278,6 +335,7 @@ void handle_active( printf("\n"); if (old->best_move.from != 0 && old->best_move.to != 0) { + ended = true; printf( "bestmove %c%c%c%c", (old->best_move.from / 8) + 'a', @@ -300,8 +358,13 @@ void handle_active( engine_messages->data[i] = old->next; free(old->pv.moves); free(old); + + if (ended) { + printf("ENDED\n"); + atomic_store(&state->cleanup, 1); + current_state = STATE_IDLE; + } } - // TODO: this section will call the engine to analysis if (cmd.empty) { return; } @@ -316,9 +379,9 @@ void handle_active( void handle_halt(uci_state *state, ucicmd cmd) { // TIMEOUT NOTICE: THE FOLLOWING BLOCK SHOULDN'T TAKE MORE THAN 1 SECONDS - + + atomic_store(&state->stop, 1); // --- - printf("bestmove 0000\n"); // TODO: idk get it rn current_state = STATE_IDLE; } |
