From bbf3282839eb9efe57b1451763ef0859198c33af Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 1 Jan 2023 19:05:15 +0100 Subject: [PATCH] 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(-) 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);