aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMI.cpp67
-rw-r--r--src/CMI.hpp42
2 files changed, 92 insertions, 17 deletions
diff --git a/src/CMI.cpp b/src/CMI.cpp
index dfca22d..ae963a1 100644
--- a/src/CMI.cpp
+++ b/src/CMI.cpp
@@ -1,6 +1,73 @@
#include "CMI.hpp"
namespace CMI{
+
+ HalfMove::HalfMove(): number(1), isBlack(false){
+ }
+
+ HalfMove::~HalfMove() {
+ if(mainline!=nullptr)
+ delete mainline;
+ for(HalfMove *v:variations)
+ delete v;
+ }
+
+ void HalfMove::SetParent(CMI::HalfMove* m){
+ parent=static_cast<HalfMove*>(m);
+ }
+
+
+ std::vector<CMI::HalfMove*> HalfMove::GetVariations() const {
+ std::vector<CMI::HalfMove*> vars;
+ for(HalfMove *v:variations){
+ vars.push_back(static_cast<CMI::HalfMove*>(v));
+ }
+ return vars;
+ }
+ void HalfMove::SetVariations(std::vector<CMI::HalfMove*> vars){
+ variations.clear();
+ for(auto *v: vars){
+ variations.push_back(static_cast<HalfMove*>(v));
+ }
+ }
+
+
+ void HalfMove::SetMainline(CMI::HalfMove* m) {
+ mainline = static_cast<HalfMove*>(m);
+ if(m!=nullptr){
+ if (!this->isBlack) {
+ m->SetIsBlack(true);
+ m->SetNumber(this->number);
+ } else {
+ m->SetIsBlack(false);
+ m->SetNumber(this->number + 1);
+ }
+ m->SetParent(static_cast<CMI::HalfMove*>(this));
+ }
+ }
+
+
+
+ CMI::HalfMove* HalfMove::GetMainline() const {return mainline;};
+ CMI::HalfMove* HalfMove::GetParent() const {return parent;};
+ std::string HalfMove::GetSAN() const {return SAN;};
+ void HalfMove::SetSAN(std::string newSAN) {SAN=newSAN;};
+ std::uint16_t HalfMove::GetNumber() const {return number;};
+ void HalfMove::SetNumber(std::uint16_t n) {number=n;};
+ std::uint8_t HalfMove::GetNAG() const {return NAG;};
+ void HalfMove::SetNAG(std::uint8_t n) {NAG=n;};
+ std::string HalfMove::GetComment() const {return comment;};
+ void HalfMove::SetComment(std::string c) { comment=c;};
+ bool HalfMove::IsBlack() const {return isBlack;};
+ void HalfMove::SetIsBlack(bool b) {isBlack=b;};
+
+
+
+
+
+
+ // ---------- Implementation of various common operations ----------
+
void HalfMove::Promote(){
HalfMove *broot=GetBranchRoot();
if(broot!=nullptr){
diff --git a/src/CMI.hpp b/src/CMI.hpp
index 46d8aa4..283ffd0 100644
--- a/src/CMI.hpp
+++ b/src/CMI.hpp
@@ -14,56 +14,64 @@ namespace CMI {
* to the CMI::HalfMove remains in the move tree.
*/
class HalfMove {
+ HalfMove *parent = nullptr;
+ HalfMove *mainline = nullptr;
+ std::vector<HalfMove *> variations;
+ std::string SAN,comment;
+ std::uint16_t number;
+ std::uint8_t NAG;
+ bool isBlack;
public:
+ HalfMove();
/// @brief Ensure that the destructor of the child class is called
- virtual ~HalfMove() {};
+ virtual ~HalfMove();
/**
* @brief Return a pointer to the next CMI::HalfMove
*
* @return HalfMove* if any and nullptr otherwise
*/
- virtual HalfMove* GetMainline() const = 0;
+ virtual HalfMove* GetMainline() const;
/**
* @brief Set the next CMI::HalfMove
* Existing main line pointer will be overriten (NOT DELETED) and the internal state (Number, IsBlack) of the new move
* must be ajusted in the implementation of this method.
*/
- virtual void SetMainline(HalfMove*) = 0;
+ virtual void SetMainline(HalfMove*);
/**
* @brief Get the previous CMI::HalfMove
*
* @return HalfMove* if any and nullptr otherwise
*/
- virtual HalfMove* GetParent() const = 0;
+ virtual HalfMove* GetParent() const;
/**
* @brief Set the parent of current CMI::HalfMove
*
*/
- virtual void SetParent(HalfMove*) = 0;
+ virtual void SetParent(HalfMove*);
/// @brief Return the current move using the SAN notation e.g: "Qxc5+" or "a4"
- virtual std::string GetSAN() const = 0;
+ virtual std::string GetSAN() const;
/// @brief Setter to replace current SAN
- virtual void SetSAN(std::string) = 0;
+ virtual void SetSAN(std::string);
/// @brief Return the HalfMove move number e.g 1 for the first white's and black's move
- virtual std::uint16_t GetNumber() const = 0;
+ virtual std::uint16_t GetNumber() const;
/// @brief Setter to replace current Number
- virtual void SetNumber(std::uint16_t) = 0;
+ virtual void SetNumber(std::uint16_t);
/// @brief Return the Numeric Annotation Glyphs code
- virtual std::uint8_t GetNAG() const = 0;
+ virtual std::uint8_t GetNAG() const;
/// @brief Setter to replace current NAG
- virtual void SetNAG(std::uint8_t) = 0;
+ virtual void SetNAG(std::uint8_t);
/// @brief Return the comment linked to the current move or empty string
- virtual std::string GetComment() const = 0;
+ virtual std::string GetComment() const;
/// @brief Setter to replace current comment
- virtual void SetComment(std::string) = 0;
+ virtual void SetComment(std::string);
/// @brief Return true if the current HalfMove was played by black
- virtual bool IsBlack() const = 0;
+ virtual bool IsBlack() const;
/// @brief Setter to replace that determined the return values of HalfMove::IsBlack()
- virtual void SetIsBlack(bool) = 0;
+ virtual void SetIsBlack(bool);
/// @brief All the variations of the current move
- virtual std::vector<HalfMove*> GetVariations() const = 0;
+ virtual std::vector<HalfMove*> GetVariations() const;
/// @brief Setter to replace current variations
- virtual void SetVariations(std::vector<HalfMove*>) = 0;
+ virtual void SetVariations(std::vector<HalfMove*>);
// ---------- Implementation of various common operations ----------