Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixe setoption behaviour. #1945

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ void EngineLoop::CmdIsReady() {
SendResponse("readyok");
}

void EngineLoop::CmdSetOption(const std::string& name, const std::string& value,
void EngineLoop::CmdSetOption(const std::string& name,
const std::string& value,
const std::string& context) {
options_.SetUciOption(name, value, context);
// Set the log filename for the case it was set in UCI option.
Expand Down
31 changes: 25 additions & 6 deletions src/utils/optionsparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#include "utils/commandline.h"
#include "utils/configfile.h"
Expand Down Expand Up @@ -64,17 +66,34 @@ std::vector<std::string> OptionsParser::ListOptionsUci() const {
return result;
}

std::vector<std::string> SplitString(const std::string& str, char delimiter) {
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(str);
while (std::getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
}

void OptionsParser::SetUciOption(const std::string& name,
const std::string& value,
const std::string& context) {
auto option = FindOptionByUciName(name);
if (option) {
option->SetValue(value, GetMutableOptions(context));
return;
}
throw Exception("Unknown option: " + name);
if (name.empty()) {
throw Exception("An option name must be provided");
} else {
auto option = FindOptionByUciName(name);
if (option) {
option->SetValue(value, GetMutableOptions(context));
} else {
// If name is not valid throw an error.
throw Exception("Unknown option: " + name);
}
return;
}
}


void OptionsParser::HideOption(const OptionId& id) {
const auto option = FindOptionById(id);
if (option) option->hidden_ = true;
Expand Down