7 : m_Game(
"Chinese Chess"),
10 m_Date(time(nullptr)),
19std::string CPGN::GetTag(
const std::string &szTag)
21 const auto iter = m_Tags.find(szTag);
22 if (iter != m_Tags.end())
39 if (szTag ==
"Result")
50int CPGN::SetTag(
const std::string &szTag,
const std::string &szValue)
53 SetEvent(szValue.c_str());
54 else if (szTag ==
"Site")
55 SetSite(szValue.c_str());
56 else if (szTag ==
"Date")
58 else if (szTag ==
"Round")
59 SetRound(szValue.c_str());
60 else if (szTag ==
"Red")
61 SetRed(szValue.c_str());
62 else if (szTag ==
"Black")
63 SetBlack(szValue.c_str());
64 else if (szTag ==
"Result")
65 SetResult(szValue.c_str());
66 else if(szTag ==
"Fen")
67 SetFen(szValue.c_str());
68 else if(szTag ==
"Format")
69 SetFormat(szValue.c_str());
71 m_Tags[szTag] = szValue;
79 pgn =
"[Game \"" + m_Game +
"\"]\n"
81 +
"[Site \"" +
GetSite() +
"\"]\n";
87 pgn +=
"[Round \"" +
GetRound() +
"\"]\n"
88 +
"[Red \"" +
GetRed() +
"\"]\n"
91 +
"[Fen \"" + GetFen() +
"\"]\n"
92 +
"[Format \"" + GetFormat() +
"\"]\n";
93 for(
const auto& item : m_Tags)
95 pgn +=
"[" + item.first +
" \"" + item.second +
"\"]\n";
98 pgn += m_pSteps->toString();
113int CPGN::SetEvent(
const char *pEvent)
124int CPGN::SetSite(
const char *pSite)
135int CPGN::parseDate(
const std::string &dateText)
139 memset(&tm, 0,
sizeof (
struct tm));
140 sscanf(dateText.c_str(),
"%d.%d.%d" ,
146 m_Date = mktime(&tm);
150std::string CPGN::dateToString(
const time_t &t)
const
152 struct tm* t1 = localtime(&t);
154 strftime(buf, 30,
"%Y.%m.%d", t1);
158int CPGN::SetDate(
const time_t &t)
169int CPGN::SetRound(
const char *pRound)
180int CPGN::SetRed(
const char *pRed)
194int CPGN::SetBlack(
const char *pBlack)
196 if(
nullptr == pBlack)
208int CPGN::SetResult(
const char *pResult)
214const std::string& CPGN::GetFen()
const
219int CPGN::SetFen(
const char *pFen)
225const std::string& CPGN::GetFormat()
const
230int CPGN::SetFormat(
const char *pFormat)
232 if(
nullptr == pFormat)
233 m_Format =
"Chinese";
239int CPGN::SetSteps(std::shared_ptr<CChessSteps> steps)
std::string toString() const
Gets the game as PGN string.
const std::string & GetRed() const
Get the player(s) of the white pieces.
const std::string & GetRound() const
Get the playing round ordinal of the game.
const std::string & GetBlack() const
Get the player(s) of the black pieces.
const time_t & GetDate() const
Gets the date of the event.
int ParseString(const std::string szPgn)
解析 PGN
const std::string & GetResult() const
Gets the result of the game, if any.
const std::string & GetSite() const
Gets the location of the event.
const std::string & GetEvent() const
Gets the name of the tournament or match event.