Improve NAG parsing

This commit is contained in:
Loic Guegan 2023-01-18 18:42:13 +01:00
parent 2ac42558f2
commit da88575493
5 changed files with 30 additions and 27 deletions

View file

@ -2,7 +2,7 @@
namespace pgnp { namespace pgnp {
HalfMove::HalfMove() : count(-1), isBlack(false), MainLine(NULL) {} HalfMove::HalfMove() : count(-1), isBlack(false), MainLine(NULL), NAG(0) {}
HalfMove::~HalfMove() { HalfMove::~HalfMove() {
delete MainLine; delete MainLine;

View file

@ -24,7 +24,7 @@ public:
std::string move; std::string move;
/// @brief Comment associated to the move /// @brief Comment associated to the move
std::string comment; std::string comment;
std::string NAG; std::uint8_t NAG;
/// @brief Next HalfMove link to this line /// @brief Next HalfMove link to this line
HalfMove *MainLine; HalfMove *MainLine;
/// @brief Next HalfMove links to variation of this line /// @brief Next HalfMove links to variation of this line

View file

@ -260,16 +260,19 @@ loctype PGN::ParseHalfMove(loctype loc, HalfMove *hm) {
EOF_CHECK(loc); EOF_CHECK(loc);
c = pgn_content[loc]; c = pgn_content[loc];
if (c == '$') { if (c == '$') {
hm->NAG += c; //hm->NAG += c;
std::string NAG;
loc++; loc++;
EOF_CHECK(loc); EOF_CHECK(loc);
c = pgn_content[loc]; c = pgn_content[loc];
while (IS_DIGIT(c)) { while (IS_DIGIT(c)) {
hm->NAG += c; NAG += c;
loc++; loc++;
EOF_CHECK(loc); EOF_CHECK(loc);
c = pgn_content[loc]; c = pgn_content[loc];
} }
if(NAG.size()>0)
hm->NAG=std::stoi(NAG);
} }
} else if (c == '(') { } else if (c == '(') {
// Check for variations // Check for variations

View file

@ -50,7 +50,7 @@ TEST_CASE("Hartwig PGN", "[combined/hartwig]") {
"just loses thanks to the interpolation of 11. c3 fxe4:"); "just loses thanks to the interpolation of 11. c3 fxe4:");
HalfMove *m20w = (m->GetHalfMoveAt(38)); // move 20 white => m20w 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 HalfMove *m21b = (m->GetHalfMoveAt(42)); // move 21 black => m21b
CHECK(m21b->comment == CHECK(m21b->comment ==

View file

@ -148,34 +148,34 @@ TEST_CASE("Valid PGN", "[valid/pgn3]") {
} }
SECTION("NAGs") { SECTION("NAGs") {
REQUIRE(m->GetHalfMoveAt(2)->NAG == "$1"); REQUIRE(m->GetHalfMoveAt(2)->NAG == 1);
REQUIRE(m->GetHalfMoveAt(8)->NAG == "$5"); REQUIRE(m->GetHalfMoveAt(8)->NAG == 5);
REQUIRE(m->GetHalfMoveAt(8)->variations[0]->NAG == "$14"); REQUIRE(m->GetHalfMoveAt(8)->variations[0]->NAG == 14);
REQUIRE(m->GetHalfMoveAt(19)->NAG == "$2"); REQUIRE(m->GetHalfMoveAt(19)->NAG == 2);
REQUIRE(m->GetHalfMoveAt(22)->NAG == "$1"); REQUIRE(m->GetHalfMoveAt(22)->NAG == 1);
REQUIRE(m->GetHalfMoveAt(23)->variations[0]->NAG == "$4"); 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(3)->NAG == 1);
REQUIRE(m->GetHalfMoveAt(23)->variations[0]->GetHalfMoveAt(9)->NAG == REQUIRE(m->GetHalfMoveAt(23)->variations[0]->GetHalfMoveAt(9)->NAG ==
"$18"); 18);
REQUIRE(m->GetHalfMoveAt(24)->NAG == "$1"); REQUIRE(m->GetHalfMoveAt(24)->NAG == 1);
REQUIRE(m->GetHalfMoveAt(24)->variations[0]->GetHalfMoveAt(5)->NAG == REQUIRE(m->GetHalfMoveAt(24)->variations[0]->GetHalfMoveAt(5)->NAG ==
"$13"); 13);
REQUIRE(m->GetHalfMoveAt(30)->NAG == "$1"); REQUIRE(m->GetHalfMoveAt(30)->NAG == 1);
REQUIRE(m->GetHalfMoveAt(31)->variations[0]->NAG == "$2"); REQUIRE(m->GetHalfMoveAt(31)->variations[0]->NAG == 2);
REQUIRE(m->GetHalfMoveAt(31)->variations[0]->GetHalfMoveAt(3)->NAG == REQUIRE(m->GetHalfMoveAt(31)->variations[0]->GetHalfMoveAt(3)->NAG ==
"$18"); 18);
REQUIRE(m->GetHalfMoveAt(32)->NAG == "$1"); REQUIRE(m->GetHalfMoveAt(32)->NAG == 1);
REQUIRE(m->GetHalfMoveAt(37)->variations[0]->GetHalfMoveAt(3)->NAG == REQUIRE(m->GetHalfMoveAt(37)->variations[0]->GetHalfMoveAt(3)->NAG ==
"$18"); 18);
REQUIRE(m->GetHalfMoveAt(38)->NAG == "$1"); REQUIRE(m->GetHalfMoveAt(38)->NAG == 1);
REQUIRE(m->GetHalfMoveAt(41)->variations[0]->GetHalfMoveAt(1)->NAG == REQUIRE(m->GetHalfMoveAt(41)->variations[0]->GetHalfMoveAt(1)->NAG ==
"$18"); 18);
REQUIRE(m->GetHalfMoveAt(44)->NAG == "$1"); REQUIRE(m->GetHalfMoveAt(44)->NAG == 1);
REQUIRE(m->GetHalfMoveAt(44)->variations[0]->NAG == "$4"); REQUIRE(m->GetHalfMoveAt(44)->variations[0]->NAG == 4);
REQUIRE(m->GetHalfMoveAt(44)->variations[0]->MainLine->NAG == "$13"); REQUIRE(m->GetHalfMoveAt(44)->variations[0]->MainLine->NAG == 13);
REQUIRE(m->GetHalfMoveAt(45)->variations[0]->GetHalfMoveAt(3)->NAG == REQUIRE(m->GetHalfMoveAt(45)->variations[0]->GetHalfMoveAt(3)->NAG ==
"$18"); 18);
REQUIRE(m->GetHalfMoveAt(52)->variations[0]->MainLine->variations[0]->MainLine->NAG == "$18"); REQUIRE(m->GetHalfMoveAt(52)->variations[0]->MainLine->variations[0]->MainLine->NAG == 18);
} }
} }