#include #include #include #include #include #include #include #include "uci/state.h" #include "uci/command.h" #include "uci/response.h" void load_from_message(ucicmd* cmd, const char* message) { char token[MAX_TOKEN_SIZE]; int i = 0, k = 0; while (message[i] != 0 && message[i] != '\n' && message[i] != '\r') { if (message[i] != ' ') { token[k++] = message[i++]; continue; } if (k == 0) { i++; continue; } i++; token[k] = 0; ucicmd_add(cmd, token); k = 0; } token[k] = 0; ucicmd_add(cmd, token); } int main(int argc, char** argv) { // https://stackoverflow.com/a/41559081 fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); uci_state state = {0}; strncpy(state.name, "Gacrux", 32); strncpy(state.author, "Aargh Rai ", 32); int k = 0; state.option_settings[k++] = option_setting_spin( "Threads", 1, 5, 1, &state.threads ); state.option_settings[k++] = option_setting_spin( "Hash", 0, 512, 256, &state.hash ); state.option_settings[k++] = option_setting_button( "Clear Hash", &state.clear_hash ); state.option_settings[k++] = option_setting_check( "UCI_ShowCurrLine", false, &state.uci_showcurrline ); state.option_settings[k++] = option_setting_check( "UCI_ShowRefutations", false, &state.uci_showrefutations ); state.option_settings[k++] = option_setting_check( "UCI_LimitStrength", false, &state.uci_limitstrength ); state.option_settings[k++] = option_setting_spin( "UCI_Elo", 100, 3500, 800, &state.uci_elo ); state.option_settings[k++] = option_setting_check( "UCI_AnalyseMode", false, &state.uci_analysemode ); state.option_settings[k++] = option_setting_string( "UCI_Opponent", "", &state.uci_opponent ); state.option_settings[k++] = option_setting_string( "UCI_EngineAbout", "Gacrux by Aargh Rai, Checkout https://git.aarghrai.com/gacrux", &state.uci_engineabout ); state.option_settings[k++] = option_setting_string( "UCI_SetPositionValue", "", &state.uci_setpositionvalue ); ucicmd cmd = ucicmd_init(); size_t n; char buf[1024]; while (true) { cmd.empty = true; cmd.args_count = 0; ssize_t n = read(STDIN_FILENO, buf, sizeof(buf)); if (n > 0) { load_from_message(&cmd, buf); } handle_uci(&state, cmd); } } #include "uci/command.c" #include "uci/response.c" #include "uci/state.c"