MCPcopy Create free account
hub / github.com/dhbloo/rapfi / parseDBKey

Function parseDBKey

Rapfi/command/database.cpp:122–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122DBKey parseDBKey(std::string keyStr)
123{
124 auto keyParts = split(keyStr, "-", true);
125 if (keyParts.size() != 6)
126 throw std::invalid_argument("key must have 6 parts");
127
128 Rule rule;
129 if (keyParts[0] == "f")
130 rule = FREESTYLE;
131 else if (keyParts[0] == "s")
132 rule = STANDARD;
133 else if (keyParts[0] == "r")
134 rule = RENJU;
135 else
136 throw std::invalid_argument("invalid rule " + std::string(keyParts[0]));
137
138 int boardWidth = std::atoi(keyParts[1].data());
139 int boardHeight = std::atoi(keyParts[2].data());
140
141 std::vector<Pos> blackStones =
142 Command::parsePositionString(keyParts[3], boardWidth, boardHeight);
143 std::vector<Pos> whiteStones =
144 Command::parsePositionString(keyParts[4], boardWidth, boardHeight);
145
146 Color sideToMove;
147 if (keyParts[5] == "b")
148 sideToMove = BLACK;
149 else if (keyParts[5] == "w")
150 sideToMove = WHITE;
151 else
152 throw std::invalid_argument("invalid sideToMove " + std::string(keyParts[5]));
153
154 return {rule, boardWidth, boardHeight, sideToMove, blackStones, whiteStones};
155}
156
157DBRecord parseDBRecord(std::istream &is, const DBRecord &defaultRecordValue)
158{

Callers 1

databaseMethod · 0.85

Calls 2

splitFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected