summaryrefslogtreecommitdiff
path: root/src/uci
diff options
context:
space:
mode:
Diffstat (limited to 'src/uci')
-rw-r--r--src/uci/response.c81
-rw-r--r--src/uci/response.h13
-rw-r--r--src/uci/state.h3
3 files changed, 86 insertions, 11 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) {
diff --git a/src/uci/response.h b/src/uci/response.h
index 17204f5..16652d2 100644
--- a/src/uci/response.h
+++ b/src/uci/response.h
@@ -1,10 +1,19 @@
#include "command.h"
#include "state.h"
+#include "../ipc.h"
-void handle_uci(uci_state *state, ucicmd cmd);
+void handle_uci(
+ uci_state *state,
+ engine_messages* engine_message,
+ ucicmd cmd
+);
void handle_initial(uci_state *state, ucicmd cmd);
void handle_idle(uci_state *state, ucicmd cmd);
void handle_sync(uci_state *state, ucicmd cmd);
void handle_ping(uci_state *state, ucicmd cmd);
-void handle_active(uci_state *state, ucicmd cmd);
+void handle_active(
+ uci_state *state,
+ engine_messages* engine_message,
+ ucicmd cmd
+);
void handle_halt(uci_state *state, ucicmd cmd);
diff --git a/src/uci/state.h b/src/uci/state.h
index 849a08a..9b09774 100644
--- a/src/uci/state.h
+++ b/src/uci/state.h
@@ -80,7 +80,10 @@ typedef struct {
char author[32];
bool debug;
+ int go;
struct fen_load position;
+ struct uci_move *moves;
+ int moves_count;
option_setting_t option_settings[11];