mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Improve engine dialog
This commit is contained in:
parent
40a56b72fe
commit
08e6015303
3 changed files with 45 additions and 10 deletions
|
@ -17,8 +17,10 @@ EditorPanel::EditorPanel(wxFrame *parent, Game *game)
|
||||||
tagTextCtrl->SetHint("Tag");
|
tagTextCtrl->SetHint("Tag");
|
||||||
valueTextCtrl->SetHint("Value");
|
valueTextCtrl->SetHint("Value");
|
||||||
|
|
||||||
LiveEngineDialog *diag=new LiveEngineDialog(this, "stockfish");
|
/*LiveEngineDialog *diag=new LiveEngineDialog(this, "Stockfish");
|
||||||
diag->Show();
|
diag->SetFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
||||||
|
|
||||||
|
diag->Show();*/
|
||||||
RefreshTagsList();
|
RefreshTagsList();
|
||||||
|
|
||||||
// Bind events
|
// Bind events
|
||||||
|
|
|
@ -1,27 +1,58 @@
|
||||||
#include "LiveEngineDialog.hpp"
|
#include "LiveEngineDialog.hpp"
|
||||||
|
|
||||||
LiveEngineDialog::LiveEngineDialog(wxWindow *parent, std::string engine_name)
|
LiveEngineDialog::LiveEngineDialog(wxWindow *parent, std::string engine_name)
|
||||||
: LiveEngineDialogFB(parent), engine_name(engine_name) {
|
: LiveEngineDialogFB(parent), engine_name(engine_name), interval(1000),
|
||||||
|
engine(NULL) {
|
||||||
lines_list->InsertColumn(0, "#", wxLIST_FORMAT_LEFT, 50);
|
lines_list->InsertColumn(0, "#", wxLIST_FORMAT_LEFT, 50);
|
||||||
lines_list->InsertColumn(1, "Moves", wxLIST_FORMAT_LEFT, 300);
|
lines_list->InsertColumn(1, "Moves", wxLIST_FORMAT_LEFT, 300);
|
||||||
current_engine->SetLabel(engine_name);
|
current_engine->SetLabel(engine_name);
|
||||||
StartEngine();
|
InitEngine();
|
||||||
Bind(wxEVT_BUTTON, &LiveEngineDialog::TogglePauseEngine, this, LIVE_ENGINE_PAUSE_BUTTON);
|
Bind(wxEVT_BUTTON, &LiveEngineDialog::TogglePauseEngine, this,
|
||||||
|
LIVE_ENGINE_PAUSE_BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiveEngineDialog::StartEngine() {
|
void LiveEngineDialog::InitEngine() {
|
||||||
timer.Start(1000);
|
if (engine == NULL) {
|
||||||
|
wxLogDebug("Start engine: %s", engine_name);
|
||||||
|
CONFIG_OPEN(conf);
|
||||||
|
engine = new uciadapter::UCI(
|
||||||
|
conf->Read("engines/" + engine_name + "/path").ToStdString());
|
||||||
|
engine->ucinewgame();
|
||||||
|
CONFIG_CLOSE(conf);
|
||||||
|
}
|
||||||
|
timer.Start(interval);
|
||||||
timer.Bind(wxEVT_TIMER, &LiveEngineDialog::OnTimerTick, this);
|
timer.Bind(wxEVT_TIMER, &LiveEngineDialog::OnTimerTick, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LiveEngineDialog::SetFEN(std::string fen) {
|
||||||
|
timer.Stop();
|
||||||
|
engine->position(fen);
|
||||||
|
uciadapter::Go args;
|
||||||
|
engine->go(args);
|
||||||
|
timer.Start(interval);
|
||||||
|
}
|
||||||
|
|
||||||
void LiveEngineDialog::TogglePauseEngine(wxCommandEvent &event) {
|
void LiveEngineDialog::TogglePauseEngine(wxCommandEvent &event) {
|
||||||
if (timer.IsRunning()) {
|
if (timer.IsRunning()) {
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
engine_pause_button->SetLabel("Continue");
|
engine_pause_button->SetLabel("Continue");
|
||||||
} else {
|
} else {
|
||||||
timer.Start(1000);
|
timer.Start(interval);
|
||||||
engine_pause_button->SetLabel("Pause");
|
engine_pause_button->SetLabel("Pause");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiveEngineDialog::OnTimerTick(wxTimerEvent &event) { wxLogDebug("Tick!"); }
|
void LiveEngineDialog::OnTimerTick(wxTimerEvent &event) {
|
||||||
|
wxLogDebug("Tick!");
|
||||||
|
lines_list->DeleteAllItems();
|
||||||
|
engine->SyncAfter(0);
|
||||||
|
for (auto const &line : engine->GetLines()) {
|
||||||
|
long index = lines_list->InsertItem(0, std::to_string(line.first));
|
||||||
|
std::string line_moves;
|
||||||
|
for(std::string move:line.second.pv){
|
||||||
|
line_moves+=move + " ";
|
||||||
|
}
|
||||||
|
lines_list->SetItem(index, 1, line_moves);
|
||||||
|
}
|
||||||
|
wxLogDebug("%s", engine->GetBuffer());
|
||||||
|
}
|
|
@ -7,10 +7,12 @@ class LiveEngineDialog : public LiveEngineDialogFB {
|
||||||
uciadapter::UCI *engine;
|
uciadapter::UCI *engine;
|
||||||
std::string engine_name;
|
std::string engine_name;
|
||||||
wxTimer timer;
|
wxTimer timer;
|
||||||
|
std::uint32_t interval;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LiveEngineDialog(wxWindow *parent, std::string engine_name);
|
LiveEngineDialog(wxWindow *parent, std::string engine_name);
|
||||||
void StartEngine();
|
void InitEngine();
|
||||||
void TogglePauseEngine(wxCommandEvent &event);
|
void TogglePauseEngine(wxCommandEvent &event);
|
||||||
void OnTimerTick(wxTimerEvent &event);
|
void OnTimerTick(wxTimerEvent &event);
|
||||||
|
void SetFEN(std::string fen);
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue