aboutsummaryrefslogtreecommitdiff
path: root/src/CGEHalfMove.cpp
blob: 669b5683d5b17999739815e2ca5ba41d91b56bf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "CGEHalfMove.hpp"

namespace cgeditor {

CGEHalfMove::CGEHalfMove()
    : MainLine(NULL), IsBlack(false), Number(1), Parent(NULL) {}

CGEHalfMove::CGEHalfMove(CGEHalfMove *parent) {
  CGEHalfMove();
  Parent = parent;
  Parent->MainLine = this;
  if (parent->IsBlack) {
    Number = parent->Number + 1;
    IsBlack = false;
  } else {
    Number = parent->Number;
    IsBlack = true;
  }
}

CGEHalfMove::CGEHalfMove(std::string move)
    : MainLine(NULL), IsBlack(false), Number(0), Parent(NULL) {
  this->move = move;
}

void CGEHalfMove::SetComment(const std::string &c) {
  if (c.size() > 0) {
    NbLineComment = 1;
    for (const char &c : c) {
      if (c == '\n') {
        NbLineComment++;
      }
    }
    this->comment = c;
  }
  else {
    this->comment="";
    NbLineComment=0;
  }
}

std::string CGEHalfMove::GetComment() { return (comment); }

std::uint16_t CGEHalfMove::GetNbLineComment() { return (this->NbLineComment); }

void CGEHalfMove::RemoveChild(CGEHalfMove *m) {
  std::uint32_t i = 0;
  bool found = false;
  for (i; i < variations.size(); i++) {
    if (variations[i] == m) {
      found = true;
      break;
    }
  }
  if (found) {
    variations.erase(variations.begin() + i);
  }
  if (MainLine == m) {
    MainLine = NULL;
  }
}

} // namespace cgeditor