aboutsummaryrefslogtreecommitdiff
path: root/src/base_tab/gamebase/PGNGameBase.cpp
blob: 39775d1a0d33f9264d5dd859f64ff230a87eb072 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "PGNGameBase.hpp"

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);
}