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.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp
index 32924e1..0bac980 100644
--- a/src/game_tab/HalfMove.cpp
+++ b/src/game_tab/HalfMove.cpp
@@ -20,6 +20,38 @@ HalfMove::~HalfMove() {
}
}
+void HalfMove::SetOpening(const std::string &name, const std::string &eco){
+ HalfMove *m=this;
+ while(m!=nullptr){
+ m->opening=name;
+ m->eco=eco;
+ if(m->parent != nullptr && m->parent->mainline==m)
+ m=m->parent;
+ else
+ break;
+ }
+}
+
+void HalfMove::GetOpening(std::string &name, std::string &eco){
+ name=this->opening;
+ eco=this->eco;
+}
+
+std::vector<HalfMove *> HalfMove::GetLine(){
+ std::vector<HalfMove *> line;
+ HalfMove *m=this;
+ while(m!=nullptr){
+ line.push_back(m);
+ // Check if in a variation:
+ if(m->parent!=nullptr && m->parent->mainline!=m)
+ m=m->parent->parent; // Because we are in a variation
+ else
+ m=m->parent;
+ }
+ std::reverse(line.begin(), line.end());
+ return line;
+}
+
HalfMove::HalfMove(HalfMove *m){
src=m->src;
dst=m->dst;