예제 #1
0
파일: board.cpp 프로젝트: l8huang/freegemas
MultipleMatch Board::check() {
    //lDEBUG << "Checking board...";

    int k;

    MultipleMatch matches;

    // First, we check each row (horizontal)
    for(int y = 0; y < 8; ++y) {

        for(int x = 0; x < 6; ++x) {

            Match currentRow;
            currentRow.push_back(coord(x,y));

            for(k = x+1; k < 8; ++k) {
                if(squares[x][y] == squares[k][y] &&
                        squares[x][y] != sqEmpty) {
                    currentRow.push_back(coord(k,y));
                } else {
                    break;
                }
            }

            if(currentRow . size() > 2) {
                matches.push_back(currentRow);
            }

            x = k - 1;
        }
    }

    for(int x = 0; x < 8; ++x) {
        for(int y = 0; y < 6; ++y) {

            Match currentColumn;
            currentColumn.push_back(coord(x,y));

            for(k = y + 1; k < 8; ++k) {
                if(squares[x][y] == squares[x][k] &&
                        squares[x][y] != sqEmpty) {
                    currentColumn.push_back(coord(x,k));
                } else {
                    break;
                }
            }

            if(currentColumn.size() > 2) {
                matches.push_back(currentColumn);
            }

            y = k - 1;
        }
    }

    return matches;
}
예제 #2
0
bool Regex::search(const string &s, Match &m) const {
  try {
    if (!boost::regex_search(s, m.pri->m, pri->re, typeToMatchFlags(type)))
      return false;

  } catch (const boost::regex_error &e) {
    THROW("Search error: " << e.what());
  }

  for (unsigned i = 0; i < m.pri->m.size(); i++)
    m.push_back(string(m.pri->m[i].first, m.pri->m[i].second));

  return true;
}