Update Game tab

This commit is contained in:
Loic Guegan 2023-01-01 19:05:15 +01:00
parent 4e85af5e08
commit bbf3282839
5 changed files with 8 additions and 22 deletions

View file

@ -5,6 +5,8 @@
#include "ochess.hpp" #include "ochess.hpp"
#include <unordered_map> #include <unordered_map>
#define UNPACK_ABSOLUTE_MOVE(MOVE,SRC,DST) {(SRC)=(MOVE).substr(0,2);(DST)=(MOVE).substr(2,2);}
class Game { class Game {
std::string board; std::string board;
std::string initial_fen; std::string initial_fen;

View file

@ -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() { bool HalfMove::IsVariation() {
HalfMove *m = this; HalfMove *m = this;
HalfMove *p = HalfMove::parent; HalfMove *p = HalfMove::parent;

View file

@ -45,8 +45,6 @@ public:
void Promote(); void Promote();
/// @brief Check if current half move is within a variation /// @brief Check if current half move is within a variation
bool IsVariation(); 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 /// @brief Get the root of a variation
HalfMove *GetRoot(); HalfMove *GetRoot();
/// @brief Get parent of the current move /// @brief Get parent of the current move

View file

@ -21,7 +21,6 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
// Configure FEN field // Configure FEN field
fen_text_field->SetFont(wxFont(*wxNORMAL_FONT).Bold().Larger()); fen_text_field->SetFont(wxFont(*wxNORMAL_FONT).Bold().Larger());
last_move=game->GetCurrentMove();
// Bind events: // Bind events:
Bind(PLAY_MOVE_EVENT, &GameTabLeftPanel::OnPlay, this, wxID_ANY); Bind(PLAY_MOVE_EVENT, &GameTabLeftPanel::OnPlay, this, wxID_ANY);
@ -68,6 +67,7 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
event.SetEventObject(this); event.SetEventObject(this);
ProcessEvent(event); ProcessEvent(event);
} }
Notify(true);
} }
void GameTabLeftPanel::Notify(bool skip_animation) { void GameTabLeftPanel::Notify(bool skip_animation) {
@ -78,12 +78,13 @@ void GameTabLeftPanel::Notify(bool skip_animation) {
bool animate=false; bool animate=false;
HalfMove *m = game->GetCurrentMove(); HalfMove *m = game->GetCurrentMove();
std::string src,dst; std::string src,dst;
if (m) if (m){
captures = m->GetLineCaptures(); captures = m->GetLineCaptures();
}
// Update board canvas: // Update board canvas:
if(!skip_animation || animate){ if(skip_animation || !animate){
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board, board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
game->IsBlackToPlay(), captures, game->IsBlackToPlay(), captures,
game->GetTag("White"),game->GetTag("Black")); game->GetTag("White"),game->GetTag("Black"));
@ -92,8 +93,6 @@ void GameTabLeftPanel::Notify(bool skip_animation) {
board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board, board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board,
game->IsBlackToPlay(), captures,src,dst,repeat); game->IsBlackToPlay(), captures,src,dst,repeat);
} }
// Update last move
last_move=m;
// Update fen field: // Update fen field:
fen_text_field->SetValue(game->GetFen()); fen_text_field->SetValue(game->GetFen());
} }

View file

@ -11,10 +11,9 @@ wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
class GameTabLeftPanel : public TabGameLeftPanel { class GameTabLeftPanel : public TabGameLeftPanel {
std::shared_ptr<Game> game; std::shared_ptr<Game> game;
BoardCanvas *board_canvas; BoardCanvas *board_canvas;
std::string last_absolute_move;
bool repeat; bool repeat;
HalfMove *last_move; std::string last_absolute_move;
public: public:
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game); GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
void Notify(bool skip_animation=false); void Notify(bool skip_animation=false);