diff --git a/src/HalfMove.cpp b/src/HalfMove.cpp index 8038acb..81d9a67 100644 --- a/src/HalfMove.cpp +++ b/src/HalfMove.cpp @@ -2,7 +2,7 @@ namespace pgnp { -HalfMove::HalfMove() : count(-1), isBlack(false), MainLine(NULL) {} +HalfMove::HalfMove() : count(-1), isBlack(false), MainLine(NULL), NAG(0) {} HalfMove::~HalfMove() { delete MainLine; diff --git a/src/HalfMove.hpp b/src/HalfMove.hpp index 47caf05..45eb96c 100644 --- a/src/HalfMove.hpp +++ b/src/HalfMove.hpp @@ -24,7 +24,7 @@ public: std::string move; /// @brief Comment associated to the move std::string comment; - std::string NAG; + std::uint8_t NAG; /// @brief Next HalfMove link to this line HalfMove *MainLine; /// @brief Next HalfMove links to variation of this line diff --git a/src/PGN.cpp b/src/PGN.cpp index c0c80e3..831de6e 100644 --- a/src/PGN.cpp +++ b/src/PGN.cpp @@ -260,16 +260,19 @@ loctype PGN::ParseHalfMove(loctype loc, HalfMove *hm) { EOF_CHECK(loc); c = pgn_content[loc]; if (c == '$') { - hm->NAG += c; + //hm->NAG += c; + std::string NAG; loc++; EOF_CHECK(loc); c = pgn_content[loc]; while (IS_DIGIT(c)) { - hm->NAG += c; + NAG += c; loc++; EOF_CHECK(loc); c = pgn_content[loc]; } + if(NAG.size()>0) + hm->NAG=std::stoi(NAG); } } else if (c == '(') { // Check for variations diff --git a/tests/combined.cpp b/tests/combined.cpp index a4b2089..137257c 100644 --- a/tests/combined.cpp +++ b/tests/combined.cpp @@ -50,7 +50,7 @@ TEST_CASE("Hartwig PGN", "[combined/hartwig]") { "just loses thanks to the interpolation of 11. c3 fxe4:"); HalfMove *m20w = (m->GetHalfMoveAt(38)); // move 20 white => m20w - CHECK(m20w->NAG == "$1"); + CHECK(m20w->NAG == 1); HalfMove *m21b = (m->GetHalfMoveAt(42)); // move 21 black => m21b CHECK(m21b->comment == diff --git a/tests/valid.cpp b/tests/valid.cpp index 3183114..2cf6102 100644 --- a/tests/valid.cpp +++ b/tests/valid.cpp @@ -148,34 +148,34 @@ TEST_CASE("Valid PGN", "[valid/pgn3]") { } SECTION("NAGs") { - REQUIRE(m->GetHalfMoveAt(2)->NAG == "$1"); - REQUIRE(m->GetHalfMoveAt(8)->NAG == "$5"); - REQUIRE(m->GetHalfMoveAt(8)->variations[0]->NAG == "$14"); - REQUIRE(m->GetHalfMoveAt(19)->NAG == "$2"); - REQUIRE(m->GetHalfMoveAt(22)->NAG == "$1"); - REQUIRE(m->GetHalfMoveAt(23)->variations[0]->NAG == "$4"); - REQUIRE(m->GetHalfMoveAt(23)->variations[0]->GetHalfMoveAt(3)->NAG == "$1"); + REQUIRE(m->GetHalfMoveAt(2)->NAG == 1); + REQUIRE(m->GetHalfMoveAt(8)->NAG == 5); + REQUIRE(m->GetHalfMoveAt(8)->variations[0]->NAG == 14); + REQUIRE(m->GetHalfMoveAt(19)->NAG == 2); + REQUIRE(m->GetHalfMoveAt(22)->NAG == 1); + REQUIRE(m->GetHalfMoveAt(23)->variations[0]->NAG == 4); + REQUIRE(m->GetHalfMoveAt(23)->variations[0]->GetHalfMoveAt(3)->NAG == 1); REQUIRE(m->GetHalfMoveAt(23)->variations[0]->GetHalfMoveAt(9)->NAG == - "$18"); - REQUIRE(m->GetHalfMoveAt(24)->NAG == "$1"); + 18); + REQUIRE(m->GetHalfMoveAt(24)->NAG == 1); REQUIRE(m->GetHalfMoveAt(24)->variations[0]->GetHalfMoveAt(5)->NAG == - "$13"); - REQUIRE(m->GetHalfMoveAt(30)->NAG == "$1"); - REQUIRE(m->GetHalfMoveAt(31)->variations[0]->NAG == "$2"); + 13); + REQUIRE(m->GetHalfMoveAt(30)->NAG == 1); + REQUIRE(m->GetHalfMoveAt(31)->variations[0]->NAG == 2); REQUIRE(m->GetHalfMoveAt(31)->variations[0]->GetHalfMoveAt(3)->NAG == - "$18"); - REQUIRE(m->GetHalfMoveAt(32)->NAG == "$1"); + 18); + REQUIRE(m->GetHalfMoveAt(32)->NAG == 1); REQUIRE(m->GetHalfMoveAt(37)->variations[0]->GetHalfMoveAt(3)->NAG == - "$18"); - REQUIRE(m->GetHalfMoveAt(38)->NAG == "$1"); + 18); + REQUIRE(m->GetHalfMoveAt(38)->NAG == 1); REQUIRE(m->GetHalfMoveAt(41)->variations[0]->GetHalfMoveAt(1)->NAG == - "$18"); - REQUIRE(m->GetHalfMoveAt(44)->NAG == "$1"); - REQUIRE(m->GetHalfMoveAt(44)->variations[0]->NAG == "$4"); - REQUIRE(m->GetHalfMoveAt(44)->variations[0]->MainLine->NAG == "$13"); + 18); + REQUIRE(m->GetHalfMoveAt(44)->NAG == 1); + REQUIRE(m->GetHalfMoveAt(44)->variations[0]->NAG == 4); + REQUIRE(m->GetHalfMoveAt(44)->variations[0]->MainLine->NAG == 13); REQUIRE(m->GetHalfMoveAt(45)->variations[0]->GetHalfMoveAt(3)->NAG == - "$18"); - REQUIRE(m->GetHalfMoveAt(52)->variations[0]->MainLine->variations[0]->MainLine->NAG == "$18"); + 18); + REQUIRE(m->GetHalfMoveAt(52)->variations[0]->MainLine->variations[0]->MainLine->NAG == 18); } }