summaryrefslogtreecommitdiff
path: root/src/uci/response.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uci/response.c')
-rw-r--r--src/uci/response.c65
1 files changed, 52 insertions, 13 deletions
diff --git a/src/uci/response.c b/src/uci/response.c
index b27bf76..1f32f55 100644
--- a/src/uci/response.c
+++ b/src/uci/response.c
@@ -2,6 +2,39 @@
#include <assert.h>
#include "response.h"
+// examples from uci_min.txt
+// "option name Nullmove type check default true\n"
+// "option name Selectivity type spin default 2 min 0 max 4\n"
+// "option name Style type combo default Normal var Solid var Normal var Risky\n"
+// "option name NalimovPath type string default c:\\n"
+// "option name Clear Hash type button\n"
+void print_setting(option_setting_t setting) {
+ printf("option name %s type ", setting.option_name);
+ // accidently did the yoda style if statement, i am keeping it
+ if (OPTION_SPIN == setting.type) {
+ option_spin_setting_t data = setting.data.spin;
+ printf(
+ "spin default %d min %d max %d\n",
+ data.default_value,
+ data.min,
+ data.max
+ );
+ } else if (OPTION_COMBO == setting.type) {
+ option_combo_setting_t data = setting.data.combo;
+ printf("combo default %s", data.combination[data.default_index]);
+ for (int i = 0; i < data.count; i++) {
+ printf(" var %s", data.combination[i]);
+ }
+ printf("\n");
+ } else if (OPTION_CHECK == setting.type) {
+ printf("check default %d\n", setting.data.check_default);
+ } else if (OPTION_STRING == setting.type) {
+ printf("string default %s\n", setting.data.string_default);
+ } else if (OPTION_BUTTON == setting.type) {
+ printf("button\n");
+ } else { assert(0); }
+}
+
enum {
STATE_INITIAL,
STATE_IDLE,
@@ -17,32 +50,38 @@ void todo() {
assert(0);
}
-void handle_uci(ucicmd cmd) {
+void handle_uci(uci_state *state, ucicmd cmd) {
if (current_state == STATE_INITIAL) {
- return handle_initial(cmd);
+ return handle_initial(state, cmd);
}
if (current_state == STATE_IDLE) {
- return handle_idle(cmd);
+ return handle_idle(state, cmd);
}
if (current_state == STATE_SYNC) {
- return handle_sync(cmd);
+ return handle_sync(state, cmd);
}
if (current_state == STATE_PING) {
- return handle_ping(cmd);
+ return handle_ping(state, cmd);
}
if (current_state == STATE_ACTIVE) {
- return handle_active(cmd);
+ return handle_active(state, cmd);
}
- return handle_halt(cmd);
+ return handle_halt(state, cmd);
}
-void handle_initial(ucicmd cmd) {
+void handle_initial(uci_state *state, ucicmd cmd) {
if (cmd.empty || strcmp(cmd.root, "uci") != 0) return;
+ printf("id name %s\n", state->name);
+ printf("id author %s\n", state->author);
+ int settings_count = sizeof(state->option_settings)/sizeof(option_setting_t);
+ for (int i = 0; i < settings_count; i++) {
+ print_setting(state->option_settings[i]);
+ }
printf("uciok\n");
current_state = STATE_IDLE;
}
-void handle_idle(ucicmd cmd) {
+void handle_idle(uci_state *state, ucicmd cmd) {
if (cmd.empty) return;
if (strcmp(cmd.root, "debug") == 0) {
debug = strcmp(ucicmd_get_arg(cmd, 0), "on") == 0;
@@ -62,14 +101,14 @@ void handle_idle(ucicmd cmd) {
}
}
-void handle_sync(ucicmd cmd) {
+void handle_sync(uci_state *state, ucicmd cmd) {
// when i come up with some info to give:
// printf("info\n");
printf("readyok\n");
current_state = STATE_IDLE;
}
-void handle_ping(ucicmd cmd) {
+void handle_ping(uci_state *state, ucicmd cmd) {
// when i come up with some info to give:
// printf("info\n");
//
@@ -81,7 +120,7 @@ void handle_ping(ucicmd cmd) {
current_state = STATE_ACTIVE;
}
-void handle_active(ucicmd cmd) {
+void handle_active(uci_state *state, ucicmd cmd) {
if (cmd.empty) {
return;
}
@@ -95,7 +134,7 @@ void handle_active(ucicmd cmd) {
}
}
-void handle_halt(ucicmd cmd) {
+void handle_halt(uci_state *state, ucicmd cmd) {
// when i come up with some info to give:
// printf("info\n");
printf("bestmove 0000\n"); // TODO: idk get it rn