diff options
| author | Aargh Rai <aargh.rai+git@gmail.com> | 2026-07-13 21:58:18 +0530 |
|---|---|---|
| committer | Aargh Rai <aargh.rai+git@gmail.com> | 2026-07-13 21:58:18 +0530 |
| commit | f8c0dc54e36cc201c657aa12e5a22029b092e1bc (patch) | |
| tree | a0dd1a42c9681be98a7508c128db0dacacefc2e7 /src/uci/state.c | |
| parent | 2e8b78ab0ef01eaacd8094ff839ac93b4451e9c3 (diff) | |
restructed all the files + uci done now
also broke the symbol analyser in the process, i didn't help much, i had
to pull out the pen & paper, but it made a cool graph never the less
multithreading was a pain! but it got it in the end
fixed the structs naming convention, if it's used outside by other
files, it's typedeffed, otherwise it's not
fixed the recursive imports issued i had in go_args*, where i was
casting it to void* in uci to make it work
now response.c doesn't deal with ipc, really happy with that change
now every single thing has its own responsibility
Diffstat (limited to 'src/uci/state.c')
| -rw-r--r-- | src/uci/state.c | 223 |
1 files changed, 181 insertions, 42 deletions
diff --git a/src/uci/state.c b/src/uci/state.c index 56e0b04..ac043ed 100644 --- a/src/uci/state.c +++ b/src/uci/state.c @@ -1,80 +1,219 @@ #include <string.h> -#include "state.h" +#include "uci/state.h" -option_setting_t option_setting_combo( - char* option_name, - char** combinations, +void option_setting_combo( + option_setting_t *target, + char *option_name, + char **combinations, int combinations_count, int default_index, combo_t *combo ) { - option_setting_t output = {0}; - strncpy(output.option_name, option_name, 32); - output.type = OPTION_COMBO; - output.data.combo = (option_combo_setting_t) { + strncpy(target->option_name, option_name, 32); + target->type = OPTION_COMBO; + target->data.combo = (option_combo_setting_t) { combinations, combinations_count, default_index }; - output.value.combo = combo; + target->value.combo = combo; *combo = default_index; - return output; } -option_setting_t option_setting_spin( - const char* option_name, +void option_setting_spin( + option_setting_t *target, + const char *option_name, int min, int max, int default_value, spin_t *spin ) { - option_setting_t output = {0}; - strncpy(output.option_name, option_name, 32); - output.type = OPTION_SPIN; - output.data.spin = (option_spin_setting_t) { min, max, default_value }; - output.value.spin = spin; + strncpy(target->option_name, option_name, 32); + target->type = OPTION_SPIN; + target->data.spin = (option_spin_setting_t) { min, max, default_value }; + target->value.spin = spin; *spin = default_value; - return output; } -option_setting_t option_setting_check( - const char* option_name, +void option_setting_check( + option_setting_t *target, + const char *option_name, bool default_value, check_t *check ) { - option_setting_t output = {0}; - strncpy(output.option_name, option_name, 32); - output.type = OPTION_CHECK; - output.data.check_default = default_value; - output.value.check = check; + strncpy(target->option_name, option_name, 32); + target->type = OPTION_CHECK; + target->data.check_default = default_value; + target->value.check = check; *check = default_value; - return output; } -option_setting_t option_setting_string( - const char* option_name, - const char* default_value, +void option_setting_string( + option_setting_t *target, + const char *option_name, + const char *default_value, str_t *string ) { - option_setting_t output = {0}; - strncpy(output.option_name, option_name, 32); - output.type = OPTION_STRING; - output.data.string_default = default_value; - output.value.string = string; + strncpy(target->option_name, option_name, 32); + target->type = OPTION_STRING; + target->data.string_default = default_value; + target->value.string = string; string->length = strlen(default_value); string->data = malloc(string->length); memcpy(string->data, default_value, string->length); - return output; } -option_setting_t option_setting_button( - const char* option_name, +void option_setting_button( + option_setting_t *target, + const char *option_name, button_t *button ) { - option_setting_t output = {0}; - strncpy(output.option_name, option_name, 32); - output.type = OPTION_BUTTON; - output.value.button = button; + strncpy(target->option_name, option_name, 32); + target->type = OPTION_BUTTON; + target->value.button = button; *button = false; - return output; } + +// 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); } +} + +void uci_state_init(uci_state_t *state) { + state->signal = UCI_SIGNAL_NONE; + strncpy(state->name, "Gacrux", 32); + strncpy(state->author, "Aargh Rai <aarghrai.com>", 32); + int k = 0; + option_setting_spin( + state->option_settings + k++, + "Threads", + 1, 5, 1, + &state->threads + ); + option_setting_spin( + state->option_settings + k++, + "Hash", + 0, 512, 256, + &state->hash + ); + option_setting_button( + state->option_settings + k++, + "Clear Hash", + &state->clear_hash + ); + option_setting_check( + state->option_settings + k++, + "UCI_ShowCurrLine", + false, + &state->uci_showcurrline + ); + option_setting_check( + state->option_settings + k++, + "UCI_ShowRefutations", + false, + &state->uci_showrefutations + ); + option_setting_check( + state->option_settings + k++, + "UCI_LimitStrength", + false, + &state->uci_limitstrength + ); + option_setting_spin( + state->option_settings + k++, + "UCI_Elo", + 100, 3500, 800, + &state->uci_elo + ); + option_setting_check( + state->option_settings + k++, + "UCI_AnalyseMode", + false, + &state->uci_analysemode + ); + option_setting_string( + state->option_settings + k++, + "UCI_Opponent", + "<empty>", + &state->uci_opponent + ); + option_setting_string( + state->option_settings + k++, + "UCI_EngineAbout", + "Gacrux by Aargh Rai, Checkout https://git.aarghrai.com/gacrux", + &state->uci_engineabout + ); + option_setting_string( + state->option_settings + k++, + "UCI_SetPositionValue", + "<empty>", + &state->uci_setpositionvalue + ); +} + +void uci_state_deinit(uci_state_t *state) {} + +void apply_option(uci_state_t *state, char *name, char *buffer) { + int settings_count = sizeof(state->option_settings)/sizeof(option_setting_t); + for (int i = 0; i < settings_count; i++) { + option_setting_t setting = state->option_settings[i]; + if (strcmp(setting.option_name, name)) continue; + if (OPTION_SPIN == setting.type) { + option_spin_setting_t data = setting.data.spin; + int num = atoi(buffer); + if (num < data.min) return; + if (num > data.max) return; + *setting.value.spin = num; + } else if (OPTION_COMBO == setting.type) { + option_combo_setting_t data = setting.data.combo; + for (int j = 0; j < data.count; j++) { + if (strcmp(data.combination[i], buffer)) continue; + *setting.value.combo = j; + } + } else if (OPTION_CHECK == setting.type) { + *setting.value.check = strcmp(buffer, "true") == 0; + } else if (OPTION_STRING == setting.type) { + free(setting.value.string->data); + setting.value.string->length = strlen(buffer); + setting.value.string->data = malloc(setting.value.string->length); + memcpy(setting.value.string->data, buffer, setting.value.string->length); + } else if (OPTION_BUTTON == setting.type) { + *setting.value.button = true; + } else { assert(0); } + + memcpy(state->option_settings + i, &setting, sizeof(setting)); + return; + } + if (state->debug) { + printf("info invalid option\n"); + } +} + |
