From c6f648cfb49372508fc4f2c6281d7752074397d7 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Fri, 25 Feb 2022 11:42:46 +0100 Subject: Improve pgn save performance --- src/game_tab/HalfMove.cpp | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'src/game_tab/HalfMove.cpp') diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp index 2b84382..f43b7f2 100644 --- a/src/game_tab/HalfMove.cpp +++ b/src/game_tab/HalfMove.cpp @@ -115,27 +115,16 @@ void HalfMove::SetAsMainline() { HalfMove *HalfMove::GetMainline() { return (mainline); } -HalfMove::HalfMove(pgnp::HalfMove *m, std::string initial_fen) : capture(' ') { - chessarbiter::ChessArbiter arbiter; - arbiter.Setup(initial_fen); - bool work = arbiter.Play(arbiter.ParseSAN(m->move)); - if (!work) { - wxLogDebug("Bug! %s", m->move); - } - char capture = arbiter.GetCapture(); - if (capture != ' ') { - this->capture = capture; - } - this->fen = arbiter.GetFEN(); +HalfMove::HalfMove(pgnp::HalfMove *m) : capture(' ') { this->move = m->move; this->IsBlack = m->isBlack; this->SetComment(m->comment); this->Number = m->count; if (m->MainLine != NULL) { - this->SetMainline(new HalfMove(m->MainLine, arbiter.GetFEN())); + this->SetMainline(new HalfMove(m->MainLine)); } for (pgnp::HalfMove *v : m->variations) { - this->AddVariation(new HalfMove(v, initial_fen)); + this->AddVariation(new HalfMove(v)); } } @@ -216,3 +205,25 @@ std::string HalfMove::GetPGN(bool needDots) { return (part); } + +void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) { + arbiter.Setup(fen); + bool work = arbiter.Play(arbiter.ParseSAN(m->move)); + if (!work) { + wxLogDebug("Bug! %s", m->move); + } + char capture = arbiter.GetCapture(); + if (capture != ' ') { + m->capture = capture; + } + m->fen = arbiter.GetFEN(); + if (m->mainline != NULL) { + BuildAndVerify(m->mainline, arbiter.GetFEN()); + } + for (HalfMove *v : m->variations) { + BuildAndVerify(v,fen); + } +} +void HalfMove::BuildAndVerify(std::string initial_fen) { + BuildAndVerify(this, initial_fen); +} \ No newline at end of file -- cgit v1.2.3