mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Move PGN export to the right place
This commit is contained in:
parent
9cba705e66
commit
cb4f5ada5c
6 changed files with 61 additions and 54 deletions
|
@ -81,7 +81,7 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
|
||||||
several = true;
|
several = true;
|
||||||
}
|
}
|
||||||
std::shared_ptr<Game> g = GetCurrentGame();
|
std::shared_ptr<Game> g = GetCurrentGame();
|
||||||
new_pgn.Write(g->GetPGN());
|
new_pgn.Write(GetPGN(g));
|
||||||
}
|
}
|
||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
|
||||||
several = true;
|
several = true;
|
||||||
}
|
}
|
||||||
std::shared_ptr<Game> g = current->GetCurrentGame();
|
std::shared_ptr<Game> g = current->GetCurrentGame();
|
||||||
new_pgn.Write(g->GetPGN());
|
new_pgn.Write(GetPGN(g));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
|
||||||
} else {
|
} else {
|
||||||
several = true;
|
several = true;
|
||||||
}
|
}
|
||||||
new_pgn.Write(g->GetPGN());
|
new_pgn.Write(GetPGN(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
new_pgn.Close();
|
new_pgn.Close();
|
||||||
|
@ -126,8 +126,56 @@ void PGNGameBase::Export(std::shared_ptr<GameBase> base) {
|
||||||
several = true;
|
several = true;
|
||||||
}
|
}
|
||||||
std::shared_ptr<Game> g = base->GetCurrentGame();
|
std::shared_ptr<Game> g = base->GetCurrentGame();
|
||||||
new_pgn.Write(g->GetPGN());
|
new_pgn.Write(GetPGN(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
new_pgn.Close();
|
new_pgn.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string PGNGameBase::GetPGN(std::shared_ptr<Game> g) {
|
||||||
|
std::string pgn;
|
||||||
|
HalfMove *m=g->GetMoves();
|
||||||
|
|
||||||
|
for (auto const &element : g->ListTags()) {
|
||||||
|
pgn += '[' + element + " \"" + g->GetTag(element) + "\"]\n";
|
||||||
|
}
|
||||||
|
pgn += GetMovesPGN(m,m->IsABlackMove());
|
||||||
|
|
||||||
|
pgn += " " + g->GetResult();
|
||||||
|
return (pgn);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PGNGameBase::GetMovesPGN(HalfMove *m, bool needDots) {
|
||||||
|
std::string part;
|
||||||
|
bool newNeedDots = false;
|
||||||
|
|
||||||
|
if (!m->IsABlackMove() || needDots) {
|
||||||
|
part += std::to_string(m->Number) + ".";
|
||||||
|
if (needDots) {
|
||||||
|
part += "..";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
part += m->move;
|
||||||
|
|
||||||
|
if (m->GetNbLineComment() > 0) {
|
||||||
|
part += " {";
|
||||||
|
part += m->GetComment();
|
||||||
|
part += "}";
|
||||||
|
newNeedDots = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m->GetVariations().size() > 0) {
|
||||||
|
newNeedDots = true;
|
||||||
|
for (HalfMove *v : m->GetVariations()) {
|
||||||
|
part += " (";
|
||||||
|
part += GetMovesPGN(v, m->IsABlackMove());
|
||||||
|
part += ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m->GetMainline() != NULL) {
|
||||||
|
part += " " + GetMovesPGN(m->GetMainline(), !m->IsABlackMove() && newNeedDots);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (part);
|
||||||
|
}
|
|
@ -18,4 +18,6 @@ public:
|
||||||
std::vector<std::shared_ptr<Game>> new_games);
|
std::vector<std::shared_ptr<Game>> new_games);
|
||||||
void Reset();
|
void Reset();
|
||||||
void Export(std::shared_ptr<GameBase> base);
|
void Export(std::shared_ptr<GameBase> base);
|
||||||
|
static std::string GetMovesPGN(HalfMove *m, bool needDots);
|
||||||
|
static std::string GetPGN(std::shared_ptr<Game> g);
|
||||||
};
|
};
|
|
@ -99,7 +99,6 @@ bool Game::Play(std::string move) {
|
||||||
if (moves == NULL) {
|
if (moves == NULL) {
|
||||||
moves = m;
|
moves = m;
|
||||||
}
|
}
|
||||||
wxLogDebug("%s", GetPGN());
|
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
return (false);
|
return (false);
|
||||||
|
@ -139,17 +138,7 @@ std::string Game::GetFen() {
|
||||||
return (current->GetFen());
|
return (current->GetFen());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Game::GetPGN() {
|
std::string Game::GetResult() { return (result); }
|
||||||
std::string pgn;
|
|
||||||
if (moves != NULL) {
|
|
||||||
for (auto const &element : tags) {
|
|
||||||
pgn += '[' + element.first + " \"" + element.second + "\"]\n";
|
|
||||||
}
|
|
||||||
pgn += moves->GetPGN();
|
|
||||||
}
|
|
||||||
pgn += " " + result;
|
|
||||||
return (pgn);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::SetResult(std::string result) { this->result = result; }
|
void Game::SetResult(std::string result) { this->result = result; }
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
HalfMove *GetCurrentMove();
|
HalfMove *GetCurrentMove();
|
||||||
HalfMove *GetMoves();
|
HalfMove *GetMoves();
|
||||||
std::string GetFen();
|
std::string GetFen();
|
||||||
|
std::string GetResult();
|
||||||
bool Play(std::string move);
|
bool Play(std::string move);
|
||||||
bool IsBlackToPlay();
|
bool IsBlackToPlay();
|
||||||
void Previous();
|
void Previous();
|
||||||
|
@ -35,7 +36,6 @@ public:
|
||||||
void SetMoveAsMainline(HalfMove *m);
|
void SetMoveAsMainline(HalfMove *m);
|
||||||
void SetCurrent(HalfMove *m);
|
void SetCurrent(HalfMove *m);
|
||||||
std::vector<std::string> ListTags();
|
std::vector<std::string> ListTags();
|
||||||
std::string GetPGN();
|
|
||||||
void SetResult(std::string result);
|
void SetResult(std::string result);
|
||||||
/**
|
/**
|
||||||
* @brief Build current game
|
* @brief Build current game
|
||||||
|
|
|
@ -172,42 +172,9 @@ bool HalfMove::IsVariation() {
|
||||||
|
|
||||||
std::string HalfMove::GetFen() { return (fen); }
|
std::string HalfMove::GetFen() { return (fen); }
|
||||||
|
|
||||||
std::string HalfMove::GetPGN() { return (GetPGN(IsBlack)); }
|
std::vector<HalfMove *> HalfMove::GetVariations() { return (variations); }
|
||||||
|
|
||||||
std::string HalfMove::GetPGN(bool needDots) {
|
bool HalfMove::IsABlackMove() { return (IsBlack); }
|
||||||
std::string part;
|
|
||||||
bool newNeedDots = false;
|
|
||||||
|
|
||||||
if (!IsBlack || needDots) {
|
|
||||||
part += std::to_string(Number) + ".";
|
|
||||||
if (needDots) {
|
|
||||||
part += "..";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
part += move;
|
|
||||||
|
|
||||||
if (GetNbLineComment() > 0) {
|
|
||||||
part += " {";
|
|
||||||
part += GetComment();
|
|
||||||
part += "}";
|
|
||||||
newNeedDots = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (variations.size() > 0) {
|
|
||||||
newNeedDots = true;
|
|
||||||
for (HalfMove *v : variations) {
|
|
||||||
part += " (";
|
|
||||||
part += v->GetPGN(IsBlack);
|
|
||||||
part += ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mainline != NULL) {
|
|
||||||
part += " " + mainline->GetPGN(!IsBlack && newNeedDots);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (part);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) {
|
void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) {
|
||||||
arbiter.Setup(fen);
|
arbiter.Setup(fen);
|
||||||
|
|
|
@ -20,7 +20,6 @@ class HalfMove : public cgeditor::CGEHalfMove {
|
||||||
std::vector<HalfMove *> variations;
|
std::vector<HalfMove *> variations;
|
||||||
std::string fen;
|
std::string fen;
|
||||||
char capture;
|
char capture;
|
||||||
std::string GetPGN(bool needDots);
|
|
||||||
void BuildAndVerify(HalfMove *m, std::string fen);
|
void BuildAndVerify(HalfMove *m, std::string fen);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -47,6 +46,8 @@ public:
|
||||||
/// @brief Get parent of the current move
|
/// @brief Get parent of the current move
|
||||||
HalfMove *GetParent();
|
HalfMove *GetParent();
|
||||||
HalfMove *GetMainline();
|
HalfMove *GetMainline();
|
||||||
|
std::vector<HalfMove *> GetVariations();
|
||||||
|
|
||||||
std::map<char, std::uint8_t> GetLineCaptures();
|
std::map<char, std::uint8_t> GetLineCaptures();
|
||||||
|
|
||||||
/// @brief Set parent of the current move
|
/// @brief Set parent of the current move
|
||||||
|
@ -54,7 +55,7 @@ public:
|
||||||
std::string GetFen();
|
std::string GetFen();
|
||||||
void SetFen(std::string fen);
|
void SetFen(std::string fen);
|
||||||
void SetCapture(char c);
|
void SetCapture(char c);
|
||||||
std::string GetPGN();
|
bool IsABlackMove();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Build current move
|
* @brief Build current move
|
||||||
|
|
Loading…
Add table
Reference in a new issue