aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-19 13:06:36 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-19 13:06:36 +0100
commita84b210ca397194ad360175cf89451f319121e6c (patch)
treef44e9396fd5bf0abfd731d5bf897811e95384c32 /examples
parent5e18d43a6ba4fd378178418de6b2ca7a67d64c21 (diff)
Integrate CMI
Diffstat (limited to 'examples')
-rw-r--r--examples/wxWidgets/CMakeLists.txt2
-rw-r--r--examples/wxWidgets/MyHalfMove.cpp122
-rw-r--r--examples/wxWidgets/MyHalfMove.hpp27
-rw-r--r--examples/wxWidgets/main.cpp23
4 files changed, 26 insertions, 148 deletions
diff --git a/examples/wxWidgets/CMakeLists.txt b/examples/wxWidgets/CMakeLists.txt
index af76025..61c1396 100644
--- a/examples/wxWidgets/CMakeLists.txt
+++ b/examples/wxWidgets/CMakeLists.txt
@@ -4,3 +4,5 @@ find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
add_executable(wxwidgets_example main.cpp MyHalfMove.cpp)
target_link_libraries(wxwidgets_example cgeditor ${wxWidgets_LIBRARIES})
+target_link_libraries(wxwidgets_example ChessMoveInterface)
+
diff --git a/examples/wxWidgets/MyHalfMove.cpp b/examples/wxWidgets/MyHalfMove.cpp
index 0e08113..510ff70 100644
--- a/examples/wxWidgets/MyHalfMove.cpp
+++ b/examples/wxWidgets/MyHalfMove.cpp
@@ -1,114 +1,6 @@
#include "MyHalfMove.hpp"
-MyHalfMove::MyHalfMove(std::string move) { this->move = move; }
-MyHalfMove::~MyHalfMove() {}
-
-void MyHalfMove::AddVariation(MyHalfMove *m) {
- m->IsBlack = this->IsBlack;
- m->Number = this->Number;
- MyHalfMove::variations.push_back(m);
- cgeditor::CGEHalfMove::variations.push_back(m);
- m->SetParent(this);
-}
-
-void MyHalfMove::SetMainline(MyHalfMove *m) {
- if (!this->IsBlack) {
- m->IsBlack = true;
- m->Number = this->Number;
- } else {
- m->IsBlack = false;
- m->Number = this->Number + 1;
- }
- MyHalfMove::mainline = m;
- cgeditor::CGEHalfMove::MainLine = m;
- if (m != NULL) {
- m->SetParent(this);
- }
-}
-void MyHalfMove::SetParent(MyHalfMove *m) {
- MyHalfMove::parent = m;
- CGEHalfMove::Parent = m;
-}
-void MyHalfMove::RemoveChild(MyHalfMove *m) {
- std::uint32_t i = 0;
- bool found = false;
- for (i; i < MyHalfMove::variations.size(); i++) {
- if (MyHalfMove::variations[i] == m) {
- found = true;
- break;
- }
- }
- if (found) {
- MyHalfMove::variations.erase(MyHalfMove::variations.begin() + i);
- }
- if (MyHalfMove::MainLine == m) {
- MyHalfMove::MainLine = NULL;
- }
- cgeditor::CGEHalfMove::RemoveChild((CGEHalfMove *)m);
-}
-
-MyHalfMove *MyHalfMove::GetParent() { return (parent); }
-
-MyHalfMove *MyHalfMove::GetRoot() {
- MyHalfMove *m = this;
- MyHalfMove *p = MyHalfMove::parent;
- while (p != NULL) {
- if (p->mainline != m) {
- return (m);
- }
- m = p;
- p = m->MyHalfMove::parent;
- }
- return (m);
-}
-
-void MyHalfMove::SetAsMainline() {
- MyHalfMove *root = GetRoot();
- MyHalfMove *lastRoot;
- do {
- lastRoot = root;
- root->MyHalfMove::Promote();
- root = GetRoot();
- } while (root != lastRoot);
-
- // std::cout << IsVariation() << std::endl << std::flush;
-}
-
-void MyHalfMove::Promote() {
- if (MyHalfMove::parent != NULL) {
- MyHalfMove *p = MyHalfMove::parent;
- if (p->MyHalfMove::mainline != this) {
- if (MyHalfMove::parent->MyHalfMove::parent != NULL) {
- MyHalfMove *pp = MyHalfMove::parent->MyHalfMove::parent;
- if (pp->MyHalfMove::mainline == p) {
- pp->MyHalfMove::SetMainline(this);
- } else {
- pp->AddVariation(this);
- pp->MyHalfMove::RemoveChild(p);
- }
- }
- if (p->MyHalfMove::mainline == this) {
- p->MyHalfMove::SetMainline(NULL);
- } else {
- p->MyHalfMove::RemoveChild(this);
- }
- this->AddVariation(p);
- }
- }
-}
-
-bool MyHalfMove::IsVariation() {
- MyHalfMove *m = this;
- MyHalfMove *p = MyHalfMove::parent;
- while (p != NULL) {
- if (p->mainline != m) {
- return (true);
- }
- m = p;
- p = m->MyHalfMove::parent;
- }
- return (false);
-}
+MyHalfMove::MyHalfMove(std::string move){SetSAN(move); }
MyHalfMove *BuildExampleGame() {
MyHalfMove *m = new MyHalfMove("e4");
@@ -128,7 +20,7 @@ MyHalfMove *BuildExampleGame() {
m2 = new MyHalfMove("Bc4");
m->SetMainline(m2);
- m->comment="Italian Opening";
+ m->SetComment("Italian Opening");
m = m2;
m2 = new MyHalfMove("Bc5");
@@ -136,7 +28,7 @@ MyHalfMove *BuildExampleGame() {
m = m2;
m2 = new MyHalfMove("c3");
- m2->comment="Giuoco Pianissimo";
+ m2->SetComment("Giuoco Pianissimo");
m->SetMainline(m2);
m = m2;
@@ -158,7 +50,7 @@ MyHalfMove *BuildExampleGame() {
{
MyHalfMove *var = new MyHalfMove("Re1");
- var->comment="Also possible";
+ var->SetComment("Also possible");
m->AddVariation(var);
MyHalfMove *var2 = new MyHalfMove("a6");
@@ -185,8 +77,8 @@ MyHalfMove *BuildExampleGame() {
m2 = new MyHalfMove("a6");
m->SetMainline(m2);
- m->comment="Test for a very long comment, to see how line breaks are handle by the framework.";
- m->comment+="Test for a very long comment, to see how line breaks are handle by the framework.";
+ m->SetComment("Test for a very long comment, to see how line breaks are handle by the framework.");
+ m->SetComment(m->GetComment()+"Test for a very long comment, to see how line breaks are handle by the framework.");
m = m2;
m2 = new MyHalfMove("Bb3");
@@ -198,7 +90,7 @@ MyHalfMove *BuildExampleGame() {
m = m2;
m2 = new MyHalfMove("Re1");
- m2->nag="!!";
+ m2->SetNAG(3);
m->SetMainline(m2);
m = m2;
diff --git a/examples/wxWidgets/MyHalfMove.hpp b/examples/wxWidgets/MyHalfMove.hpp
index dfb8860..84cc5e6 100644
--- a/examples/wxWidgets/MyHalfMove.hpp
+++ b/examples/wxWidgets/MyHalfMove.hpp
@@ -1,5 +1,6 @@
+#pragma once
+
#include "CGEditor.hpp"
-#include <vector>
/**
* @brief Create your custom half move class
@@ -8,32 +9,10 @@
* an overview of how to keep your move sync with the one of CGEditor
*
*/
-class MyHalfMove : public cgeditor::CGEHalfMove {
- MyHalfMove *parent = NULL;
- MyHalfMove *mainline = NULL;
- std::vector<MyHalfMove *> variations;
+class MyHalfMove : public CMI::HalfMove {
public:
MyHalfMove(std::string move);
- ~MyHalfMove();
- /// @brief Add variation to current move
- void AddVariation(MyHalfMove *m);
- /// @brief Remove the specified child from mainline and/or variations
- void RemoveChild(MyHalfMove *m);
- /// @brief Set value of the mailine
- void SetMainline(MyHalfMove *m);
- /// @brief Set this move as mainline
- void SetAsMainline();
- /// @brief Promote the current move and submove
- void Promote();
- /// @brief Check if current half move is within a variation
- bool IsVariation();
- /// @brief Get the root of a variation
- MyHalfMove* GetRoot();
- /// @brief Get parent of the current move
- MyHalfMove* GetParent();
- /// @brief Set parent of the current move
- void SetParent(MyHalfMove *m);
};
/// @brief Build the example game to use in the editor
diff --git a/examples/wxWidgets/main.cpp b/examples/wxWidgets/main.cpp
index 7d2f59e..303d014 100644
--- a/examples/wxWidgets/main.cpp
+++ b/examples/wxWidgets/main.cpp
@@ -38,7 +38,7 @@ private:
CGEditor::status.CanvasWidth = sz.GetWidth();
CGEditor::status.CanvasHeight = sz.GetHeight();
CGEditor::status.UseMoveIcons =
- true; // Piece image should be drawn before the move ?
+ false; // Piece image should be drawn before the move ?
const wxPoint pt = wxGetMousePosition();
CGEditor::status.MouseX = pt.x - this->GetScreenPosition().x;
@@ -90,7 +90,7 @@ private:
e.y + (e.height - sz.GetHeight()) / 2));
}
- /**
+ /**
* @brief CGEditor is going to call this method with the elements to draw on
* the canvas
*
@@ -161,22 +161,27 @@ private:
str = "Comment Selected";
else if (e.type == cgeditor::Event::Type::Promote) {
str = "Promote";
- static_cast<MyHalfMove *>(e.move)->MyHalfMove::Promote();
+ e.move->Promote();
+ SyncCache();
} else if (e.type == cgeditor::Event::Type::Delete) {
str = "Delete";
- if (e.move->Parent != NULL) {
- static_cast<MyHalfMove *>(e.move)->GetParent()->MyHalfMove::RemoveChild(
- (MyHalfMove *)e.move);
+ if (e.move->GetParent() != nullptr) {
+ static_cast<MyHalfMove *>((e.move)->GetParent())->RemoveChild(static_cast<MyHalfMove *>(e.move));
+ delete static_cast<MyHalfMove *>(e.move);
+ SyncCache(); // Do not forget to sync the cache
} else {
- CGEditor::status.Moves = NULL;
+ CGEditor::status.Moves = nullptr;
}
} else if (e.type == cgeditor::Event::Type::SetAsMainline) {
str = "Set as main line";
- static_cast<MyHalfMove *>(e.move)->MyHalfMove::SetAsMainline();
+ e.move->SetAsMainline();
+ SyncCache();
} else if (e.type == cgeditor::Event::Type::Goto) {
str = "Goto move";
}
- std::cout << "Event received: " << str << std::endl << std::flush;
+ wxLogDebug("Event received: %s", str);
+ if(CGEditor::status.Moves != nullptr && !CGEditor::status.Moves->IsConsistent())
+ wxLogError("ERROR!! The tree of moves is not consistent anymore! Something wrong happends");
}
// wxWidgets specific