aboutsummaryrefslogtreecommitdiff
path: root/src/engine_tab
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-02-26 18:46:06 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-02-26 18:46:06 +0100
commitf329c5f20434a07cc6c64c90d221181c27207a9c (patch)
tree63614bf7082b37728d873319d76bf000f389d1b1 /src/engine_tab
parent65e9049351130ff54b305dd8c82c969456a0797b (diff)
Improve engine support
Diffstat (limited to 'src/engine_tab')
-rw-r--r--src/engine_tab/EngineTab.cpp90
-rw-r--r--src/engine_tab/EngineTab.hpp8
-rw-r--r--src/engine_tab/EngineTabBF.cpp2
-rw-r--r--src/engine_tab/EngineTabBF.h1
4 files changed, 90 insertions, 11 deletions
diff --git a/src/engine_tab/EngineTab.cpp b/src/engine_tab/EngineTab.cpp
index 12b065f..760b416 100644
--- a/src/engine_tab/EngineTab.cpp
+++ b/src/engine_tab/EngineTab.cpp
@@ -1,21 +1,95 @@
#include "EngineTab.hpp"
EngineTab::EngineTab(wxWindow *parent, std::string engine_path_or_name)
- : EngineTabBF(parent), TabInfos(TabInfos::ENGINE) {
+ : EngineTabBF(parent), TabInfos(TabInfos::ENGINE),
+ enginePath(engine_path_or_name) {
SetLabel("New Engine");
engine = new uciadapter::UCI(engine_path_or_name);
engine_location->SetValue(engine_path_or_name);
+ confGroup = "engines/bob";
+ CONFIG_OPEN(conf);
+ conf->DeleteGroup(confGroup);
+ bool configExists = conf->HasGroup(confGroup);
+ conf->Write(confGroup + "/path", wxString(engine_path_or_name));
+ CONFIG_CLOSE(conf);
+ if (!configExists) {
+ InitConfiguration();
+ }
+
+ // Build wxPropertyGrid according to engine configuration
+ CONFIG_OPEN(conf2);
+ long index;
+ std::string optsPath = confGroup + "/options";
+ conf2->SetPath(optsPath);
+ wxString opt_name;
+ if (conf2->GetFirstGroup(opt_name, index)) {
+ do {
+ wxString optPath = opt_name + "/";
+ wxString type = conf2->Read(optPath + "type");
+ wxString default_value_wxString = conf2->Read(optPath + "value");
+ std::string default_value = default_value_wxString.ToStdString();
+ if (type == "check") {
+ engine_parameters->Append(
+ new wxBoolProperty(opt_name, wxPG_LABEL, default_value == "true"));
+ } else if (type == "spin") {
+ engine_parameters->Append(
+ new wxIntProperty(opt_name, wxPG_LABEL, std::stoi(default_value)));
+ } else if (type == "string" || type == "button") {
+ engine_parameters->Append(
+ new wxStringProperty(opt_name, wxPG_LABEL, default_value));
+ }
+ } while (conf2->GetNextGroup(opt_name, index));
+ }
+ CONFIG_CLOSE(conf2);
+
+ Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON);
+}
+
+void EngineTab::OnSave(wxCommandEvent &event) {
+ CONFIG_OPEN(conf2);
+ long index;
+ std::string optsPath = confGroup + "/options";
+ conf2->SetPath(optsPath);
+ wxString opt_name;
+ if (conf2->GetFirstGroup(opt_name, index)) {
+ do {
+ wxString optPath = opt_name + "/";
+ wxString type = conf2->Read(optPath + "type");
+ wxPGProperty *property = engine_parameters->GetProperty(opt_name);
+ wxVariant value = property->GetValue();
+ if (value.IsType(wxPG_VARIANT_TYPE_BOOL)) {
+ conf2->Write(optPath + "/value", value.GetBool());
+ } else if (value.IsType(wxPG_VARIANT_TYPE_LONG)) {
+ conf2->Write(optPath + "/value", value.GetLong());
+ } else if (value.IsType(wxPG_VARIANT_TYPE_STRING)) {
+ conf2->Write(optPath + "/value", value.GetString());
+ }
+ } while (conf2->GetNextGroup(opt_name, index));
+ }
+ CONFIG_CLOSE(conf2);
+}
+
+void EngineTab::InitConfiguration() {
+ wxLogDebug("Called!");
+ CONFIG_OPEN(conf);
+ conf->Write(confGroup + "/path", wxString(enginePath));
+ conf->Write(confGroup + "/name", wxString(engine->GetName()));
+ conf->Write(confGroup + "/authors", wxString(engine->GetAuthor()));
std::vector<uciadapter::Option> opts = engine->GetOptions();
for (uciadapter::Option &opt : opts) {
+ std::string optPath = confGroup + "/options/" + opt.name;
+ conf->Write(wxString(optPath + "/type"), wxString(opt.type));
if (opt.type == "check") {
- engine_parameters->Append(new wxBoolProperty(
- opt.name, wxPG_LABEL, opt.default_value == "true"));
+ conf->Write(wxString(optPath + "/value"), opt.default_value == "true");
} else if (opt.type == "spin") {
- engine_parameters->Append(new wxIntProperty(
- opt.name, wxPG_LABEL, std::stoi(opt.default_value)));
+ conf->Write(wxString(optPath + "/value"), std::stoi(opt.default_value));
+ conf->Write(wxString(optPath + "/min"), std::stoi(opt.min));
+ conf->Write(wxString(optPath + "/max"), std::stoi(opt.max));
} else if (opt.type == "string") {
- engine_parameters->Append(
- new wxStringProperty(opt.name, wxPG_LABEL, opt.default_value));
+ conf->Write(wxString(optPath + "/value"), wxString(opt.default_value));
+ } else if (opt.type == "button") {
+ conf->Write(wxString(optPath + "/name"), wxString(opt.default_value));
}
}
-}
+ CONFIG_CLOSE(conf);
+} \ No newline at end of file
diff --git a/src/engine_tab/EngineTab.hpp b/src/engine_tab/EngineTab.hpp
index 4538d0b..2792bc6 100644
--- a/src/engine_tab/EngineTab.hpp
+++ b/src/engine_tab/EngineTab.hpp
@@ -1,13 +1,17 @@
#include "EngineTabBF.h"
-#include "ochess.hpp"
#include "UCI.hpp"
+#include "ochess.hpp"
class EngineTab : public EngineTabBF, public TabInfos {
uciadapter::UCI *engine;
+ std::string confGroup, enginePath;
+
+ void InitConfiguration();
public:
EngineTab(wxWindow *parent, std::string engine_path_or_name);
void ApplyPreferences() {}
void *GetGame() { return (NULL); }
- void *GetBase() { return (NULL); };
+ void *GetBase() { return (NULL); }
+ void OnSave(wxCommandEvent &event);
}; \ No newline at end of file
diff --git a/src/engine_tab/EngineTabBF.cpp b/src/engine_tab/EngineTabBF.cpp
index e8cb184..0e33939 100644
--- a/src/engine_tab/EngineTabBF.cpp
+++ b/src/engine_tab/EngineTabBF.cpp
@@ -50,7 +50,7 @@ EngineTabBF::EngineTabBF( wxWindow* parent, wxWindowID id, const wxPoint& pos, c
engine_parameters = new wxPropertyGrid(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxPG_DEFAULT_STYLE|wxPG_SPLITTER_AUTO_CENTER);
main_sizer->Add( engine_parameters, 1, wxALL|wxEXPAND, 5 );
- save_button = new wxButton( this, wxID_ANY, wxT("Save"), wxDefaultPosition, wxDefaultSize, 0 );
+ save_button = new wxButton( this, ENGINE_SAVE_CONF_BUTTON, wxT("Save"), wxDefaultPosition, wxDefaultSize, 0 );
main_sizer->Add( save_button, 0, wxALL|wxEXPAND, 5 );
diff --git a/src/engine_tab/EngineTabBF.h b/src/engine_tab/EngineTabBF.h
index 8ce994a..fc65a03 100644
--- a/src/engine_tab/EngineTabBF.h
+++ b/src/engine_tab/EngineTabBF.h
@@ -28,6 +28,7 @@
///////////////////////////////////////////////////////////////////////////
+#define ENGINE_SAVE_CONF_BUTTON 1000
///////////////////////////////////////////////////////////////////////////////
/// Class EngineTabBF