aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab/Game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game_tab/Game.cpp')
-rw-r--r--src/game_tab/Game.cpp33
1 files changed, 33 insertions, 0 deletions
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;i<line.size();i++){
+ if(i%2==0){
+ pgn+=std::to_string(count)+".";
+ count+=1;
+ }
+ pgn+=line[i]->move +" ";
+ }
+ // 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();