From 4e85af5e08b86fb32d6698836f3a227bc6f086b3 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 1 Jan 2023 18:18:27 +0100 Subject: Update Game tab --- src/game_tab/HalfMove.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/game_tab/HalfMove.cpp') diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp index 7f19480..a78eb0d 100644 --- a/src/game_tab/HalfMove.cpp +++ b/src/game_tab/HalfMove.cpp @@ -177,6 +177,18 @@ void HalfMove::Promote() { } } +bool HalfMove::HasChild(HalfMove *m){ + if(m!=mainline){ + for(auto var: variations){ + if(m== var){ + return(true); + } + } + return false; + } + return true; +} + bool HalfMove::IsVariation() { HalfMove *m = this; HalfMove *p = HalfMove::parent; -- cgit v1.2.3 From bbf3282839eb9efe57b1451763ef0859198c33af Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 1 Jan 2023 19:05:15 +0100 Subject: Update Game tab --- src/game_tab/Game.hpp | 2 ++ src/game_tab/HalfMove.cpp | 12 ------------ src/game_tab/HalfMove.hpp | 2 -- src/game_tab/left_panel/GameTabLeftPanel.cpp | 9 ++++----- src/game_tab/left_panel/GameTabLeftPanel.hpp | 5 ++--- 5 files changed, 8 insertions(+), 22 deletions(-) (limited to 'src/game_tab/HalfMove.cpp') diff --git a/src/game_tab/Game.hpp b/src/game_tab/Game.hpp index 25284ee..9398056 100644 --- a/src/game_tab/Game.hpp +++ b/src/game_tab/Game.hpp @@ -5,6 +5,8 @@ #include "ochess.hpp" #include +#define UNPACK_ABSOLUTE_MOVE(MOVE,SRC,DST) {(SRC)=(MOVE).substr(0,2);(DST)=(MOVE).substr(2,2);} + class Game { std::string board; std::string initial_fen; diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp index a78eb0d..7f19480 100644 --- a/src/game_tab/HalfMove.cpp +++ b/src/game_tab/HalfMove.cpp @@ -177,18 +177,6 @@ void HalfMove::Promote() { } } -bool HalfMove::HasChild(HalfMove *m){ - if(m!=mainline){ - for(auto var: variations){ - if(m== var){ - return(true); - } - } - return false; - } - return true; -} - bool HalfMove::IsVariation() { HalfMove *m = this; HalfMove *p = HalfMove::parent; diff --git a/src/game_tab/HalfMove.hpp b/src/game_tab/HalfMove.hpp index 7bc8b22..3d5177e 100644 --- a/src/game_tab/HalfMove.hpp +++ b/src/game_tab/HalfMove.hpp @@ -45,8 +45,6 @@ public: void Promote(); /// @brief Check if current half move is within a variation bool IsVariation(); - /// @brief Return true if current moves has m as mainline or variation - bool HasChild(HalfMove *m); /// @brief Get the root of a variation HalfMove *GetRoot(); /// @brief Get parent of the current move diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index e986653..1142e99 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -21,7 +21,6 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr game) // Configure FEN field fen_text_field->SetFont(wxFont(*wxNORMAL_FONT).Bold().Larger()); - last_move=game->GetCurrentMove(); // Bind events: Bind(PLAY_MOVE_EVENT, &GameTabLeftPanel::OnPlay, this, wxID_ANY); @@ -68,6 +67,7 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { event.SetEventObject(this); ProcessEvent(event); } + Notify(true); } void GameTabLeftPanel::Notify(bool skip_animation) { @@ -78,12 +78,13 @@ void GameTabLeftPanel::Notify(bool skip_animation) { bool animate=false; HalfMove *m = game->GetCurrentMove(); std::string src,dst; - if (m) + if (m){ captures = m->GetLineCaptures(); + } // Update board canvas: - if(!skip_animation || animate){ + if(skip_animation || !animate){ board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board, game->IsBlackToPlay(), captures, game->GetTag("White"),game->GetTag("Black")); @@ -92,8 +93,6 @@ void GameTabLeftPanel::Notify(bool skip_animation) { board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board, game->IsBlackToPlay(), captures,src,dst,repeat); } - // Update last move - last_move=m; // Update fen field: fen_text_field->SetValue(game->GetFen()); } diff --git a/src/game_tab/left_panel/GameTabLeftPanel.hpp b/src/game_tab/left_panel/GameTabLeftPanel.hpp index 5073e9c..359b815 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.hpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.hpp @@ -11,10 +11,9 @@ wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent); class GameTabLeftPanel : public TabGameLeftPanel { std::shared_ptr game; BoardCanvas *board_canvas; - std::string last_absolute_move; bool repeat; - HalfMove *last_move; - + std::string last_absolute_move; + public: GameTabLeftPanel(wxFrame *parent, std::shared_ptr game); void Notify(bool skip_animation=false); -- cgit v1.2.3 From dcf6c01e54c5306fac464706cff81e75ee8f05bf Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 1 Jan 2023 19:13:34 +0100 Subject: Update Game tab --- src/game_tab/HalfMove.cpp | 15 +++++++++++++++ src/game_tab/HalfMove.hpp | 2 ++ 2 files changed, 17 insertions(+) (limited to 'src/game_tab/HalfMove.cpp') diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp index 7f19480..01621e2 100644 --- a/src/game_tab/HalfMove.cpp +++ b/src/game_tab/HalfMove.cpp @@ -177,6 +177,21 @@ void HalfMove::Promote() { } } +bool HalfMove::HasParent(HalfMove*m){ + return m==parent; +} + +bool HalfMove::HasChild(HalfMove*m){ + if(mainline==m){ + return true; + } + for(auto var: variations){ + if(var == m) + return true; + } + return false; +} + bool HalfMove::IsVariation() { HalfMove *m = this; HalfMove *p = HalfMove::parent; diff --git a/src/game_tab/HalfMove.hpp b/src/game_tab/HalfMove.hpp index 3d5177e..08a190b 100644 --- a/src/game_tab/HalfMove.hpp +++ b/src/game_tab/HalfMove.hpp @@ -46,6 +46,8 @@ public: /// @brief Check if current half move is within a variation bool IsVariation(); /// @brief Get the root of a variation + bool HasParent(HalfMove*m); + bool HasChild(HalfMove*m); HalfMove *GetRoot(); /// @brief Get parent of the current move HalfMove *GetParent(); -- cgit v1.2.3 From 3e40032109886786e469796dced8523d60b90ee4 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 2 Jan 2023 10:12:20 +0100 Subject: Simplify absolute moves --- src/game_tab/Game.hpp | 2 -- src/game_tab/HalfMove.cpp | 22 +++++++++++++++++----- src/game_tab/HalfMove.hpp | 7 +++---- src/game_tab/left_panel/GameTabLeftPanel.cpp | 10 ++++------ 4 files changed, 24 insertions(+), 17 deletions(-) (limited to 'src/game_tab/HalfMove.cpp') diff --git a/src/game_tab/Game.hpp b/src/game_tab/Game.hpp index e0337ce..bc00c5a 100644 --- a/src/game_tab/Game.hpp +++ b/src/game_tab/Game.hpp @@ -5,8 +5,6 @@ #include "ochess.hpp" #include -#define UNPACK_ABSOLUTE_MOVE(MOVE,SRC,DST) {(SRC)=(MOVE).substr(0,2);(DST)=(MOVE).substr(2,2);} - class Game { std::string board; std::string initial_fen; diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp index 01621e2..ae63527 100644 --- a/src/game_tab/HalfMove.cpp +++ b/src/game_tab/HalfMove.cpp @@ -1,13 +1,13 @@ #include "HalfMove.hpp" HalfMove::HalfMove(std::string move_absolute,std::string move_san) : capture(' ') { - this->move_absolute=move_absolute; + SetAbsoluteMove(move_absolute); this->move = move_san; fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; } HalfMove::HalfMove(std::string move_absolute, std::string move_san, std::string fen) : fen(fen), capture(' ') { - this->move_absolute=move_absolute; + SetAbsoluteMove(move_absolute); this->move = move_san; } @@ -21,7 +21,8 @@ HalfMove::~HalfMove() { } HalfMove::HalfMove(HalfMove *m){ - move_absolute=m->move_absolute; + src=m->src; + dst=m->dst; move=m->move; fen=m->fen; capture=m->capture; @@ -137,6 +138,11 @@ void HalfMove::SetAsMainline() { HalfMove *HalfMove::GetMainline() { return (mainline); } +void HalfMove::SetAbsoluteMove(const std::string &move_absolute){ + this->src=move_absolute.substr(0,2); + this->dst=move_absolute.substr(2,2); +} + HalfMove::HalfMove(pgnp::HalfMove *m) : capture(' ') { this->move = m->move; this->nag = m->NAG; @@ -151,6 +157,11 @@ HalfMove::HalfMove(pgnp::HalfMove *m) : capture(' ') { } } +void HalfMove::GetAbsoluteMove(std::string &src,std::string &dst){ + src=this->src; + dst=this->dst; +} + void HalfMove::SetFen(std::string fen) { this->fen = fen; } void HalfMove::Promote() { @@ -213,8 +224,9 @@ bool HalfMove::IsABlackMove() { return (IsBlack); } void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) { arbiter.Setup(fen); - m->move_absolute=arbiter.ParseSAN(m->move); - bool work = arbiter.Play(m->move_absolute,arbiter.ParseSANPromotion(m->move)); + std::string move_absolute=arbiter.ParseSAN(m->move); + m->SetAbsoluteMove(move_absolute); + bool work = arbiter.Play(move_absolute,arbiter.ParseSANPromotion(m->move)); if (!work) { wxLogDebug("Bug! %s", m->move); } diff --git a/src/game_tab/HalfMove.hpp b/src/game_tab/HalfMove.hpp index 08a190b..9775c3e 100644 --- a/src/game_tab/HalfMove.hpp +++ b/src/game_tab/HalfMove.hpp @@ -21,11 +21,9 @@ class HalfMove : public cgeditor::CGEHalfMove { std::string fen; char capture; void BuildAndVerify(HalfMove *m, std::string fen); - std::string move_absolute; + std::string src,dst; public: - - HalfMove(HalfMove *m); HalfMove(std::string move_absolute,std::string move_san); HalfMove(std::string move_absolute,std::string move_san, std::string fen); @@ -62,7 +60,8 @@ public: void SetFen(std::string fen); void SetCapture(char c); bool IsABlackMove(); - std::string GetAbsoluteMove(){return move_absolute;}; + void GetAbsoluteMove(std::string &src,std::string &dst); + void SetAbsoluteMove(const std::string &move_absolute); /** * @brief Build current move diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index fa97f6f..4aaddb4 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -72,34 +72,32 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { } void GameTabLeftPanel::Notify(bool skip_animation) { - wxLogDebug("Called!"); // Update fen and captures std::string fen = game->GetFen(); std::map captures; bool animate=false; HalfMove *m = game->GetCurrentMove(); std::string src,dst; - // Update capture and check if we should to animations during moves change: if (m){ captures = m->GetLineCaptures(); if(m->HasParent(last_move)){ - UNPACK_ABSOLUTE_MOVE(m->GetAbsoluteMove(),src,dst); + m->GetAbsoluteMove(src,dst); animate=true; }else if(m->HasChild(last_move)){ // Accessing last_move here is safe since it is still // in the tree of moves (since HasChild found it so not deleted) - UNPACK_ABSOLUTE_MOVE(last_move->GetAbsoluteMove(),dst,src); + last_move->GetAbsoluteMove(dst,src); animate=true; } } else if(game->GetNextMove()){ // First move animation HalfMove *next=game->GetNextMove(); if(next==last_move){ - UNPACK_ABSOLUTE_MOVE(game->GetNextMove()->GetAbsoluteMove(),dst,src); + game->GetNextMove()->GetAbsoluteMove(dst,src); animate=true; } } - + // Update board canvas: if(skip_animation || !animate){ board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board, -- cgit v1.2.3 From d1c1031332f47cf076d5da0a8a161dbb8210a0b6 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 2 Jan 2023 11:44:11 +0100 Subject: Debug --- src/game_tab/HalfMove.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/game_tab/HalfMove.cpp') diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp index ae63527..32924e1 100644 --- a/src/game_tab/HalfMove.cpp +++ b/src/game_tab/HalfMove.cpp @@ -193,6 +193,8 @@ bool HalfMove::HasParent(HalfMove*m){ } bool HalfMove::HasChild(HalfMove*m){ + if(m==nullptr) + return false; if(mainline==m){ return true; } -- cgit v1.2.3