aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-09 16:36:48 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-09 16:36:48 +0100
commitf4108bc06cd9fa1977267836e9176118e8863b57 (patch)
tree3cd663f6547c6915d4f0fe8cf137fe68a9a1bec4
parent30b7577ab321e70b5ebb2c4ec1b9edfe1d3c0a44 (diff)
Bind live engine analysis to BoardCanvas
-rw-r--r--src/game_tab/GameTab.cpp6
-rw-r--r--src/game_tab/GameTab.hpp2
-rw-r--r--src/game_tab/left_panel/GameTabLeftPanel.cpp6
-rw-r--r--src/game_tab/left_panel/GameTabLeftPanel.hpp4
-rw-r--r--src/game_tab/right_panel/GameTabRightPanel.cpp6
-rw-r--r--src/game_tab/right_panel/GameTabRightPanel.hpp1
-rw-r--r--src/game_tab/right_panel/LiveEngineDialog.cpp11
-rw-r--r--src/game_tab/right_panel/LiveEngineDialog.hpp8
8 files changed, 42 insertions, 2 deletions
diff --git a/src/game_tab/GameTab.cpp b/src/game_tab/GameTab.cpp
index 79f6794..def90f8 100644
--- a/src/game_tab/GameTab.cpp
+++ b/src/game_tab/GameTab.cpp
@@ -2,6 +2,7 @@
#include <wx/clipbrd.h>
wxDEFINE_EVENT(GAME_CHANGE, wxCommandEvent);
+wxDEFINE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent);
GameTab::GameTab(wxFrame *parent, std::shared_ptr<Game> game)
: wxPanel(parent), game(game), TabInfos(TabInfos::GAME) {
@@ -27,6 +28,11 @@ GameTab::GameTab(wxFrame *parent, std::shared_ptr<Game> game)
board_panel->Bind(wxEVT_TOOL,&GameTab::OnToolClick,this);
Bind(GAME_CHANGE, &GameTab::OnGameChange, this, wxID_ANY);
+ Bind(SHOW_ENGINE_EVALUATION, [p=this](wxCommandEvent &event){
+ EngineEvaluation *eval=(EngineEvaluation*)(event.GetClientData());
+ p->board_panel->SetEngineArrows(eval->best_lines);
+ free(eval);
+ });
}
void GameTab::OnToolClick(wxCommandEvent &event){
diff --git a/src/game_tab/GameTab.hpp b/src/game_tab/GameTab.hpp
index d29f1f3..61e4d21 100644
--- a/src/game_tab/GameTab.hpp
+++ b/src/game_tab/GameTab.hpp
@@ -9,9 +9,11 @@
#include <wx/collpane.h>
#include <wx/splitter.h>
#include <wx/textctrl.h>
+#include "right_panel/LiveEngineDialog.hpp"
wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
+wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent);
class GameTab : public wxPanel, public TabInfos {
GameTabRightPanel *editor_panel;
diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp
index 5b8162c..c7be112 100644
--- a/src/game_tab/left_panel/GameTabLeftPanel.cpp
+++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp
@@ -71,6 +71,11 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
Notify(true); // Redraw event is move failed! Otherwise piece not resets to it initial position after dragging
}
+void GameTabLeftPanel::SetEngineArrows(std::vector<std::string> arrows){
+ engine_arrows=arrows;
+ Notify(true);
+}
+
void GameTabLeftPanel::Notify(bool skip_animation) {
// Update fen and captures
std::string fen = game->GetFen();
@@ -107,6 +112,7 @@ void GameTabLeftPanel::Notify(bool skip_animation) {
gs.black=game->GetTag("Black");
gs.mat_black=game->IsCheckmate(true);
gs.mat_white=game->IsCheckmate(false);
+ gs.arrows=engine_arrows;
if(m){
// There should be a valid src_hl or dst_hl ortherwise it explode:
std::string src_hl, dst_hl;
diff --git a/src/game_tab/left_panel/GameTabLeftPanel.hpp b/src/game_tab/left_panel/GameTabLeftPanel.hpp
index 578f8c4..2dec70d 100644
--- a/src/game_tab/left_panel/GameTabLeftPanel.hpp
+++ b/src/game_tab/left_panel/GameTabLeftPanel.hpp
@@ -13,7 +13,8 @@ class GameTabLeftPanel : public TabGameLeftPanel {
BoardCanvas *board_canvas;
bool repeat;
HalfMove *last_move;
-
+ std::vector<std::string> engine_arrows;
+
public:
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
void Notify(bool skip_animation=false);
@@ -22,4 +23,5 @@ public:
void OnRefreshBoard(wxCommandEvent &event);
void ApplyPreferences();
void SetSaveToolEnable(bool state){game_toolbar->EnableTool(0,state);};
+ void SetEngineArrows(std::vector<std::string> arrows);
}; \ No newline at end of file
diff --git a/src/game_tab/right_panel/GameTabRightPanel.cpp b/src/game_tab/right_panel/GameTabRightPanel.cpp
index 7aa8bbd..f421228 100644
--- a/src/game_tab/right_panel/GameTabRightPanel.cpp
+++ b/src/game_tab/right_panel/GameTabRightPanel.cpp
@@ -60,6 +60,12 @@ void GameTabRightPanel::OnLiveAnalysis(wxCommandEvent &event) {
live_engine->Bind(wxEVT_CLOSE_WINDOW,
&GameTabRightPanel::OnLiveEngineClose, this,
ID_LIVE_ENGINE_DIALOG);
+ live_engine->Bind(SHOW_ENGINE_EVALUATION, [p=this](wxCommandEvent &e){
+ wxCommandEvent notifyEvent(SHOW_ENGINE_EVALUATION,p->GetId());
+ notifyEvent.SetEventObject(p);
+ notifyEvent.SetClientData(e.GetClientData());
+ p->ProcessEvent(notifyEvent);
+ });
}
}
}
diff --git a/src/game_tab/right_panel/GameTabRightPanel.hpp b/src/game_tab/right_panel/GameTabRightPanel.hpp
index 6f3aaaa..1b94e86 100644
--- a/src/game_tab/right_panel/GameTabRightPanel.hpp
+++ b/src/game_tab/right_panel/GameTabRightPanel.hpp
@@ -16,6 +16,7 @@ wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
// Foreign events
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
+wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent);
class GameTabRightPanel : public TabGameRightPanel {
std::shared_ptr<Game> game;
diff --git a/src/game_tab/right_panel/LiveEngineDialog.cpp b/src/game_tab/right_panel/LiveEngineDialog.cpp
index 9184216..347c32e 100644
--- a/src/game_tab/right_panel/LiveEngineDialog.cpp
+++ b/src/game_tab/right_panel/LiveEngineDialog.cpp
@@ -104,12 +104,16 @@ void LiveEngineDialog::OnTimerTick(wxTimerEvent &event) {
wxLogDebug("Tick!");
lines_list->DeleteAllItems();
engine->SyncAfter(0);
+ EngineEvaluation *eval=new EngineEvaluation();
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 + " ";
}
+ if(line.second.pv.size()>0){
+ eval->best_lines.push_back(line.second.pv[0]);
+ }
std::string cp_str = std::to_string(line.second.score_cp);
if (line.second.score_cp > 0) {
cp_str = "+" + cp_str;
@@ -117,5 +121,10 @@ void LiveEngineDialog::OnTimerTick(wxTimerEvent &event) {
lines_list->SetItem(index, 1, cp_str);
lines_list->SetItem(index, 2, line_moves);
}
- wxLogDebug("%s", engine->GetBuffer());
+ //wxLogDebug("%s", engine->GetBuffer());
+ // Notify GameTab
+ wxCommandEvent notifyEvent(SHOW_ENGINE_EVALUATION,GetId());
+ notifyEvent.SetEventObject(this);
+ notifyEvent.SetClientData(eval);
+ ProcessEvent(notifyEvent);
} \ No newline at end of file
diff --git a/src/game_tab/right_panel/LiveEngineDialog.hpp b/src/game_tab/right_panel/LiveEngineDialog.hpp
index 0996ba0..d99c3f5 100644
--- a/src/game_tab/right_panel/LiveEngineDialog.hpp
+++ b/src/game_tab/right_panel/LiveEngineDialog.hpp
@@ -1,7 +1,15 @@
+#pragma once
+
#include "UCI.hpp"
#include "ochess.hpp"
#include <wx/timer.h>
+wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent);
+
+typedef struct EngineEvaluation {
+ std::vector<std::string> best_lines;
+} EngineEvaluation;
+
class LiveEngineDialog : public DialogLiveEngine {
uciadapter::UCI *engine;
std::string engine_name;