diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2022-01-24 18:32:05 +0100 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2022-01-24 18:32:05 +0100 |
| commit | 5d4a7d66cba27b946ac155983d8b1710b353aaae (patch) | |
| tree | 59fabec41c90c061695f6f8925cfdef470053d47 /src/pgnp.cpp | |
| parent | af333f9ff1c5e7e31d69f58e4559a14cdcfa4f9d (diff) | |
Cleaning tests
Diffstat (limited to 'src/pgnp.cpp')
| -rw-r--r-- | src/pgnp.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/pgnp.cpp b/src/pgnp.cpp index 5336cd6..7f9c450 100644 --- a/src/pgnp.cpp +++ b/src/pgnp.cpp @@ -1,6 +1,7 @@ #include "pgnp.hpp" #include <iostream> +#include <string> #define IS_BLANK(c) (c == ' ' || c == '\n' || c == '\t') #define IS_DIGIT(c) \ @@ -59,6 +60,8 @@ PGN::~PGN() { delete moves; } +std::string PGN::GetResult() { return (result); } + void PGN::FromFile(std::string filepath) { std::ifstream file(filepath); @@ -84,6 +87,9 @@ void PGN::FromString(std::string pgn_content) { } loc++; } + if (result.size() <= 0) { + throw InvalidGameResult(); + } } void PGN::STRCheck() { @@ -124,7 +130,18 @@ int PGN::ParseLine(int loc, HalfMove *hm) { // Check if we reach score entry (* or 1-0 or 0-1 or 1/2-1/2) if (!IS_EOF(loc + 1)) { char nc = pgn_content[loc + 1]; // Next c - if ((IS_DIGIT(c) && nc == '-') or (IS_DIGIT(c) && nc == '/')) { + if ((IS_DIGIT(c) && nc == '-') or (IS_DIGIT(c) && nc == '/') or c == '*') { + if (c == '*') { + result = "*"; + } else if (nc == '-') { + if (c == '1') { + result = "1-0"; + } else { + result = "0-1"; + } + } else { + result = "1/2-1/2"; + } return (loc); } } |
