diff options
Diffstat (limited to 'src/game_tab/editor/LiveEngineDialog.cpp')
| -rw-r--r-- | src/game_tab/editor/LiveEngineDialog.cpp | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/src/game_tab/editor/LiveEngineDialog.cpp b/src/game_tab/editor/LiveEngineDialog.cpp index cad3fdd..f33fcf7 100644 --- a/src/game_tab/editor/LiveEngineDialog.cpp +++ b/src/game_tab/editor/LiveEngineDialog.cpp @@ -1,27 +1,58 @@ #include "LiveEngineDialog.hpp" 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(1, "Moves", wxLIST_FORMAT_LEFT, 300); current_engine->SetLabel(engine_name); - StartEngine(); - Bind(wxEVT_BUTTON, &LiveEngineDialog::TogglePauseEngine, this, LIVE_ENGINE_PAUSE_BUTTON); + InitEngine(); + Bind(wxEVT_BUTTON, &LiveEngineDialog::TogglePauseEngine, this, + LIVE_ENGINE_PAUSE_BUTTON); } -void LiveEngineDialog::StartEngine() { - timer.Start(1000); +void LiveEngineDialog::InitEngine() { + 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); } +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) { if (timer.IsRunning()) { timer.Stop(); engine_pause_button->SetLabel("Continue"); } else { - timer.Start(1000); + timer.Start(interval); engine_pause_button->SetLabel("Pause"); } } -void LiveEngineDialog::OnTimerTick(wxTimerEvent &event) { wxLogDebug("Tick!"); }
\ No newline at end of file +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()); +}
\ No newline at end of file |
