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