7 #include <boost/foreach.hpp> 
    8 #include <boost/algorithm/string/trim.hpp> 
   25       ParseResult ki2ParseLine(RecordVisitor& rv, 
 
   29         boost::algorithm::trim(line);
 
   31         if (line.empty() || line.at(0) == 
'*')
 
   35           Record *record = rv.getRecord();
 
   36           std::string date_str(line.substr(10)); 
 
   38           const static std::string spaces[] = {
" ", 
K_SPACE};
 
   39           BOOST_FOREACH(
const std::string& space, spaces) {
 
   40             const std::string::size_type pos_space = date_str.find(space);
 
   41             if (pos_space != std::string::npos)
 
   42               date_str = date_str.substr(0, pos_space);
 
   44           record->setDate(date_str);
 
   51           Record *record = rv.getRecord();
 
   52           const std::string player_name(line.substr(6));
 
   58           Record *record = rv.getRecord();
 
   59           const std::string player_name(line.substr(6));
 
   65           Record *record = rv.getRecord();
 
   66           record->setTounamentName(line.substr(6));
 
   75         for (
size_t i = 0; ; )
 
   77           if (i < line.size() && 
 
   78               (line.at(i) == 
' ' || line.at(i) == 
'\t'))
 
   92               last_move = rv.getLastMove()->getMove();
 
   93             const NumEffectState state(*rv.getState());
 
   94             const Move move = kmove.
strToMove(move_str, state, last_move);
 
   95             if (!move.isValid()) {
 
   96               if (move_str.find(
K_RESIGN) != move_str.npos)
 
  100             rv.addMoveAndAdvance(move);
 
  103           if (i+1 >= line.size())
 
  105           move_str.append(line.substr(i,2));
 
  117   : is(is), state(SimpleState(
HIRATE))
 
  121     std::cerr << 
"InputStream::InputStream cannot read \n";
 
  136   while (std::getline(is, line)) 
 
  139     const ParseResult 
result = ki2ParseLine(rv, line, kmove);
 
  146         const std::string msg = 
"ERROR: Komaochi (handicapped game) records are not available: ";
 
  147         std::cerr << msg << 
"\n";
 
  152         const std::string msg = 
"ERROR: An illegal move found in a record.";
 
  165   std::ifstream ifs(fileName.c_str());
 
  168     const std::string msg = 
"Ki2File::Ki2File file cannot read ";
 
  169     std::cerr << msg << fileName << 
"\n";
 
  185   return rec.getInitialState();
 
  192   const int x = position.
x(), y = position.
y();
 
  231   mask_t pieces = state.allEffectAt(player, ptype, to);
 
  232   const mask_t promoted = state.promotedPieces().getMask(
Ptype_Table.getIndex(ptype));
 
  240     while (pieces.any()) {
 
  241       const Piece p = state.pieceOf(pieces.takeOneBit());
 
  242       if (p.
ptype() == ptype)
 
  252   const int count = pieces.countBit();
 
  254     CArray<int,3> x_count = {{ 0 }}, y_count = {{ 0 }};
 
  255     int my_x = 0, my_y = 0;
 
  256     while (pieces.any()) {
 
  257       const int n = pieces.takeOneBit() + 
Ptype_Table.getIndex(ptype)*32;
 
  258       const Piece p = state.pieceOf(n);
 
  259       if (p.
ptype() != ptype)
 
  261       int index_x = 1, index_y = 1;
 
  269         my_x = index_x, my_y = index_y;
 
  273     if (y_count[my_y] == 1) {
 
  274       if (from.
y() == to.y()) 
 
  281     else if (x_count[my_x] == 1) {
 
  282       if (from.
x() == to.x()) {
 
  284           const Piece l = state.pieceAt
 
  299     else if (from.
x() == to.x()) {
 
  318         || to.canPromote(player) || from.
canPromote(player)) {
 
  326           const char *threatmate_first, 
const char *threatmate_last,
 
  327           const NumEffectState& initial, 
Move prev)
 
  331   NumEffectState state(initial);
 
  332   std::string ret = 
show(*first, state, prev);
 
  333   if (threatmate_first != threatmate_last
 
  334       && *threatmate_first++)
 
  336   for (; first+1 != last; ++first) {
 
  339     state.makeMove(*first);
 
  340     ret += 
show(*(first+1), state, *first);
 
  341     if (threatmate_first != threatmate_last
 
  342         && *threatmate_first++)
 
  351   vector<char> threatmate(last-first, 
false);
 
  352   return show(first, last, &*threatmate.begin(), &*threatmate.end(), initial, prev);