mirror of
https://gitlab.com/manzerbredes/pgnp.git
synced 2025-04-05 17:46:25 +02:00
Improve NAG parsing
This commit is contained in:
parent
2ac42558f2
commit
da88575493
5 changed files with 30 additions and 27 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ==
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue