From 3b11b9d4f3eee5faa656d7ee61077e80726bdc36 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 16 Jan 2023 14:55:48 +0100 Subject: Improve openings database code --- src/game_tab/Game.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/game_tab/Game.cpp') diff --git a/src/game_tab/Game.cpp b/src/game_tab/Game.cpp index 315a4de..9028223 100644 --- a/src/game_tab/Game.cpp +++ b/src/game_tab/Game.cpp @@ -131,6 +131,39 @@ bool Game::Play(std::string move,char promotion) { return (false); } +void Game::GetOpening(std::string &name,std::string &eco){ + HalfMove *m=current; + if(m == nullptr) + m=moves; + if(m!=nullptr){ + // First check if opening already set + std::string cname,ceco; + m->GetOpening(cname,ceco); + if(ceco.size()>0){ + name=cname; + eco=ceco; + }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); + } + } + } +} + void Game::Previous() { if (current != nullptr) { current = current->GetParent(); -- cgit v1.2.3