7 #include <boost/algorithm/string/trim.hpp>
15 boost::algorithm::trim(line);
17 if (line.empty() || line.at(0) ==
'*')
21 std::string date_str(line.substr(10));
23 const static std::string spaces[] = {
" ",
K_SPACE};
24 for (
const auto& space: spaces) {
25 const std::string::size_type pos_space = date_str.find(space);
26 if (pos_space != std::string::npos)
27 date_str = date_str.substr(0, pos_space);
36 const std::string player_name(line.substr(6));
42 const std::string player_name(line.substr(6));
57 for (
size_t i = 0; ; ) {
58 if (i < line.size() &&
59 (line.at(i) ==
' ' || line.at(i) ==
'\t'))
74 const Move move = kmove.
strToMove(move_str, state, last_move);
76 if (move_str.find(
K_RESIGN) != move_str.npos)
84 if (i+1 >= line.size())
86 move_str.append(line.substr(i,2));
95 std::ifstream is(filename);
98 const std::string msg =
"Ki2File::Ki2File file cannot read ";
99 std::cerr << msg << filename <<
"\n";
108 while (std::getline(is, line))
118 const std::string msg =
"ERROR: Komaochi (handicapped game) records are not available: ";
119 std::cerr << msg <<
"\n";
124 const std::string msg =
"ERROR: An illegal move found in a record.";
135 using namespace record;
138 const int x = position.
x(), y = position.
y();
139 return StandardCharacters::suji[x] + StandardCharacters::dan[y];
144 using namespace record;
152 return StandardCharacters().kanji(ptype);
187 while (pieces.any()) {
189 if (p.
ptype() == ptype)
199 const int count = pieces.countBit();
202 int my_x = 0, my_y = 0;
203 while (pieces.any()) {
206 if (p.
ptype() != ptype)
208 int index_x = 1, index_y = 1;
210 index_x = ((p.
square().
x() - to.x()) *
sign(player) > 0)
213 index_y = ((p.
square().
y() - to.y()) *
sign(player) > 0)
216 my_x = index_x, my_y = index_y;
220 if (y_count[my_y] == 1) {
221 if (from.
y() == to.y())
223 else if ((to.y() - from.
y())*
sign(player) > 0)
228 else if (x_count[my_x] == 1) {
229 if (from.
x() == to.x()) {
241 else if ((to.x() - from.
x())*
sign(player) > 0)
246 else if (from.
x() == to.x()) {
247 if ((to.y() - from.
y())*
sign(player) > 0)
253 if ((to.x() - from.
x())*
sign(player) > 0)
257 if ((to.y() - from.
y())*
sign(player) > 0)
265 || to.canPromote(player) || from.
canPromote(player)) {
273 const char *threatmate_first,
const char *threatmate_last,
279 std::string ret =
show(*first, state, prev);
280 if (threatmate_first != threatmate_last
281 && *threatmate_first++)
283 for (; first+1 != last; ++first) {
287 ret +=
show(*(first+1), state, *first);
288 if (threatmate_first != threatmate_last
289 && *threatmate_first++)
298 std::vector<char> threatmate(last-first,
false);
299 return show(first, last, &*threatmate.begin(), &*threatmate.end(), initial, prev);