aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-06-03 12:34:53 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2023-06-03 12:34:53 +0200
commit9bc06b941a1499543a51c2c2032042d18596badd (patch)
tree151c5016cfcd79e2ea7aeba50a79a499bbeb2c15
parentd60a8bb5c12d906dce3b0880a39640a3e3f08837 (diff)
Debug duplicated move in games
-rw-r--r--TODO.md2
-rw-r--r--src/game_tab/Game.cpp19
-rw-r--r--src/game_tab/HalfMove.cpp14
-rw-r--r--src/game_tab/HalfMove.hpp8
4 files changed, 39 insertions, 4 deletions
diff --git a/TODO.md b/TODO.md
index c49f470..4d4e5c6 100644
--- a/TODO.md
+++ b/TODO.md
@@ -14,7 +14,7 @@
- [x] Debug engine name in the EngineTab configuration (use id for engine entry instead of name (otherwise name clash/bugs etc.))
- [x] Use static libraries for dependencies
- [x] Update PGNP to last commit
- - [ ] Remove duplicated variations (currently if variation is played more than once it is added anyway to the move list)
+ - [x] Remove duplicated variations (currently if variation is played more than once it is added anyway to the move list)
- [ ] Debug the Preference window on OS X (GetIcon() must be overridden)
## Additional Features
diff --git a/src/game_tab/Game.cpp b/src/game_tab/Game.cpp
index c7ecced..2ddd968 100644
--- a/src/game_tab/Game.cpp
+++ b/src/game_tab/Game.cpp
@@ -120,13 +120,28 @@ bool Game::Play(std::string move,char promotion) {
m->SetCapture(capture);
}
if (current != nullptr) {
- current->AddMove(m);
+ if(current->GetMainline()!=nullptr){
+ HalfMove* curmainline=static_cast<HalfMove*>(current->GetMainline());
+ HalfMove* movefound=curmainline->GetCurrentMoveWithFEN(arbiter.GetFEN());
+ if(movefound!=nullptr){
+ current=movefound;
+ }
+ else {
+ current->AddMove(m);
+ current = m;
+ }
+ }
+ else{
+ current->AddMove(m);
+ current = m;
+ }
} else if (moves != nullptr) {
moves->AddVariation(m);
+ current = m;
}
- current = m;
if (moves == nullptr) {
moves = m;
+ current = m;
}
return (true);
}
diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp
index e7850ff..c5527c6 100644
--- a/src/game_tab/HalfMove.cpp
+++ b/src/game_tab/HalfMove.cpp
@@ -163,6 +163,20 @@ bool HalfMove::IsVariation() {
std::string HalfMove::GetFen() { return (fen); }
+HalfMove* HalfMove::GetCurrentMoveWithFEN(const std::string fen){
+ if(this->fen == fen){
+ return this;
+ }
+ else {
+ for(auto var: GetVariations()){
+ HalfMove* m=static_cast<HalfMove*>(var);
+ if(m->fen == fen)
+ return m;
+ }
+ }
+ return nullptr;
+}
+
void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) {
arbiter.Setup(fen);
std::string move_absolute=arbiter.ParseSAN(m->GetSAN());
diff --git a/src/game_tab/HalfMove.hpp b/src/game_tab/HalfMove.hpp
index 19deb2f..eefee21 100644
--- a/src/game_tab/HalfMove.hpp
+++ b/src/game_tab/HalfMove.hpp
@@ -46,7 +46,13 @@ public:
void SetCapture(char c);
void GetAbsoluteMove(std::string &src,std::string &dst);
void SetAbsoluteMove(const std::string &move_absolute);
-
+ /**
+ * @brief Search if current move (move or its variations)
+ * contains a specific fen (usefull to not add moves that already exist)
+ * @param fen
+ * @return HalfMove* the move if found or nullptr
+ */
+ HalfMove* GetCurrentMoveWithFEN(const std::string fen);
/**
* @brief Build current move
* Verify and play all the moves in the game