diff --git a/src/game_tab/Game.cpp b/src/game_tab/Game.cpp index 9028223..c1aa605 100644 --- a/src/game_tab/Game.cpp +++ b/src/game_tab/Game.cpp @@ -145,21 +145,8 @@ void Game::GetOpening(std::string &name,std::string &eco){ }else { // If not, get the current move line (or first move) // and try to guess opening - auto line=m->GetLine(); // Vector of HalfMove - std::string pgn; - int count=1; - for(int i=0;imove +" "; - } - // If there is a line, try to guess the opening - if(pgn.size()>0){ - wxGetApp().GetBook().GuessOpening(pgn,name,eco); - m->SetOpening(name,eco); - } + wxGetApp().GetBook().GuessOpening(m->GetLineAsSAN(),name,eco); + m->SetOpening(name,eco); } } } diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp index 0bac980..e152ce0 100644 --- a/src/game_tab/HalfMove.cpp +++ b/src/game_tab/HalfMove.cpp @@ -48,10 +48,27 @@ std::vector HalfMove::GetLine(){ else m=m->parent; } + // Reverse the order to get it in the played order: std::reverse(line.begin(), line.end()); return line; } +std::string HalfMove::GetLineAsSAN(){ + // If not, get the current move line (or first move) + // and try to guess opening + auto line=GetLine(); // Vector of HalfMove + std::string pgn; + int count=1; + for(int i=0;imove +" "; + } + return pgn; +} + HalfMove::HalfMove(HalfMove *m){ src=m->src; dst=m->dst; @@ -271,6 +288,12 @@ void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) { m->fen = arbiter.GetFEN(); if (m->mainline != nullptr) { BuildAndVerify(m->mainline, arbiter.GetFEN()); + } else { + // Otherwise we are on a leaf! So, guess the opening: + std::string name,eco; + wxGetApp().GetBook().GuessOpening(m->GetLineAsSAN(),name,eco); + if(eco.size()>0) + m->SetOpening(name,eco); } for (HalfMove *v : m->variations) { BuildAndVerify(v, fen); diff --git a/src/game_tab/HalfMove.hpp b/src/game_tab/HalfMove.hpp index bc56557..297ca50 100644 --- a/src/game_tab/HalfMove.hpp +++ b/src/game_tab/HalfMove.hpp @@ -53,6 +53,7 @@ public: std::vector GetVariations(); /// @brief Retrieve the list of moves from the current one to the first one std::vector GetLine(); + std::string GetLineAsSAN(); std::map GetLineCaptures(); /// @brief The opening name of current line void SetOpening(const std::string &name, const std::string &eco); diff --git a/tools/assets/icons/screenshot.jpg b/tools/assets/icons/screenshot.jpg index 115252b..d2b3ebb 100644 Binary files a/tools/assets/icons/screenshot.jpg and b/tools/assets/icons/screenshot.jpg differ