mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-07-14 15:47:39 +00:00
Improve BaseTab implementation for PGN files
This commit is contained in:
parent
32a0b3e31f
commit
40c6df0e7c
4 changed files with 59 additions and 11 deletions
|
@ -1,5 +1,35 @@
|
|||
#include "PGNGameBase.hpp"
|
||||
|
||||
PGNGameBase::PGNGameBase(std::string pgn_file) {
|
||||
|
||||
}
|
||||
PGNGameBase::PGNGameBase(std::string pgn_file)
|
||||
: pgn(new pgnp::PGN()), hasNextGame(false) {
|
||||
pgn->FromFile(pgn_file);
|
||||
ParseNextGame();
|
||||
}
|
||||
|
||||
bool PGNGameBase::HasNextGame() { return (hasNextGame); }
|
||||
|
||||
void PGNGameBase::ParseNextGame() {
|
||||
try {
|
||||
pgn->ParseNextGame();
|
||||
hasNextGame = true;
|
||||
} catch (...) {
|
||||
hasNextGame = false;
|
||||
}
|
||||
}
|
||||
|
||||
Game *PGNGameBase::GetNextGame() {
|
||||
pgnp::HalfMove *pgnp_moves = new pgnp::HalfMove();
|
||||
pgn->GetMoves(pgnp_moves);
|
||||
std::string fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||
if (pgn->HasTag("FEN")) {
|
||||
fen = pgn->GetTagValue("FEN");
|
||||
}
|
||||
HalfMove *m = new HalfMove(pgnp_moves, fen);
|
||||
Game *g = new Game(m, fen);
|
||||
for (std::string &s : pgn->GetTagList()) {
|
||||
g->SetTag(s, pgn->GetTagValue(s));
|
||||
}
|
||||
|
||||
ParseNextGame();
|
||||
return (g);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
#include "GameBase.hpp"
|
||||
#include "pgnp.hpp"
|
||||
|
||||
class PGNGameBase : public GameBase {
|
||||
pgnp::PGN *pgn;
|
||||
bool hasNextGame;
|
||||
|
||||
void ParseNextGame();
|
||||
public:
|
||||
PGNGameBase(std::string pgn_file);
|
||||
|
||||
bool HasNextGame() { return (false); }
|
||||
bool HasNextGame();
|
||||
Game *GetGame(std::uint32_t id) { return (new Game()); };
|
||||
Game *GetNextGame() { return (new Game()); };
|
||||
Game *GetNextGame();
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue