示例#1
0
int main (int argc, char* argv[]) {

  BaseBogglePlayer * p = new BogglePlayer();
  set<string> lex;
  string wordA("a");
  string wordX("x");
  lex.insert(wordA);
  lex.insert("z");
  string row0[] = {"D","C"};
  string row1[] = {"b","A"};
  string* board[] = {row0,row1};
  set<string> words;
  vector<int> locations;

  p->buildLexicon(lex);

  p->setBoard(2,2,board);

  if(p->isInLexicon(wordX)) {
    std::cerr << "Apparent problem with isInLexicon #1." << std::endl;
    return -1;
  }
  if(!p->isInLexicon(wordA)) {
    std::cerr << "Apparent problem with isInLexicon #2." << std::endl;
    return -1;
  }

  if(p->isOnBoard(wordX).size() > 0) {
    std::cerr << "Apparent problem with isOnBoard #1." << std::endl;
    return -1;
  }


  locations.clear();
  locations = p->isOnBoard(wordA);
  if(locations.size() != 1 || locations[0] != 3) {
    std::cerr << "Apparent problem with isOnBoard #2." << std::endl;
    return -1;
  }
  
  
  if(!p->getAllValidWords(0,&words)) {
    std::cerr << "Apparent problem with getAllValidWords #1." << std::endl;
    return -1;
  };
  if(words.size() != 1 || words.count(wordA) != 1) {
    std::cerr << "Apparent problem with getAllValidWords #2." << std::endl;
    return -1;
  }

  cout << "ALL PASSED" << endl;

  delete p;
  return 0;

}
示例#2
0
int main (int argc, char* argv[]) {

  BaseBogglePlayer * p = new BogglePlayer();
  set<string> lex;
  string wordA("boy");
  string wordX("xwer");
  lex.insert(wordA);
  lex.insert("cat");
  string row0[] = {"D","C"};
  string row1[] = {"b","A"};
  string row3[] = {"oy","at"};
  string* board[] = {row0,row1,row3};
  set<string> words;
  vector<int> locations;

  p->buildLexicon(lex);

  p->setBoard(3,2,board);

  if(p->isInLexicon(wordX)) {
    std::cerr << "Apparent problem with isInLexicon #1." << std::endl;
    return -1;
  }
  if(!p->isInLexicon(wordA)) {
    std::cerr << "Apparent problem with isInLexicon #2." << std::endl;
    return -1;
  }

  if(p->isOnBoard(wordX).size() > 0) {
    std::cerr << "Apparent problem with isOnBoard #1." << std::endl;
    return -1;
  }
  locations.clear();
  locations = p->isOnBoard("DC");
  if(locations.size() != 2 || locations[0] != 0) {
    std::cerr << "Apparent problem with isOnBoard #2." << std::endl;
    return -1;
  }

  locations.clear();
  locations = p->isOnBoard("d");
  if(locations.size() != 1 || locations[0] != 0) {
    std::cerr << "Apparent problem with isOnBoard #3." << std::endl;
    return -1;
  }

  locations.clear();
  locations = p->isOnBoard("bA");
  if(locations.size() != 2 || locations[0] != 2) {
    std::cerr << "Apparent problem with isOnBoard #4." << std::endl;
    return -1;
  }

  locations.clear();
  locations = p->isOnBoard(wordA);
  cout << "locations size: " << locations.size() << "locations[0]: "<< locations[0] <<endl;
  if( locations.size() != 2 || locations[0] != 2 ) {
    std::cerr << "Apparent problem with isOnBoard #5." << std::endl;
    return -1;
  }
  
  
  if(!p->getAllValidWords(0,&words)) {
    std::cerr << "Apparent problem with getAllValidWords #1." << std::endl;
    return -1;
  };
  cout<<"Word size: " << words.size()<<endl;
  for (auto it1 = words.cbegin(); it1 != words.cend(); ++it1){
    std::cout << "Valid Words: " << *it1 << std::endl;
  }
  if(words.size() != 1 || words.count(wordA) != 1) {
    std::cerr << "Apparent problem with getAllValidWords #2." << std::endl;
    return -1;
  }

  delete p;
  return 0;

}
示例#3
0
int main (int argc, char* argv[]) {

  if (argc != 2) {
      std::cout << "Usage: ./boggle min_length" << std::endl;
      return -1;
  }

  BaseBogglePlayer * p = new BogglePlayer();
  set<string> lex;

  string buffer;
  string input[4][4];
  int n;

  for (int i = 0; i < 4; ++i) {
    std::getline(std::cin, buffer);
    if (buffer.size() == 0) return 0;
    n = -1;
    for (int j = 0; j < 4; ++j) {
      n++;
      while (buffer.at(n) != ' ') {
          input[i][j] += buffer.at(n);
          ++n;
          if (n == buffer.size()) break;
      }
    }
  }

  string* board2[] = {input[0], input[1], input[2], input[3]};

  /*for (int i = 0; i < 4; ++i) {
      for (int j = 0; j < 4; ++j) {
          std::cout << board2[i][j];
      }
      std::cout << std::endl;
  }*/

  set<string> words;
  vector<int> locations;

  std::ifstream infile;
  infile.open("boglex.txt");
  if (!infile.is_open()) {
      std::cout << "error opening file" << std::endl;
      exit(-1);
  }
  std::string word;
  int i = 0;
  while (infile.is_open() && infile.good()) {
      std::getline(infile, word);
      if (word.size() < 1) continue;
      std::transform(word.begin(), word.end(), word.begin(), ::tolower);
      lex.insert(word);
      i++;
  }
  //std::cout << "read: " << lex.size() << std:: endl;
  infile.close();

  p->buildLexicon(lex);

  p->setBoard(4,4,board2);

  p->getAllValidWords(atoi(argv[1]), &words);

  /*
  //sort by len
  set<string, strlencmp> sorted;
  std::set<string>::iterator it;
  for (it = words.begin(); it != words.end(); ++it) {
      sorted.insert(*it);
  }*/

  set<ruzWord, ruzWordCmp> sorted;
  std::set<string>::iterator it;
  dict d = getWeights();
  for (it = words.begin(); it != words.end(); ++it) {
      sorted.insert(ruzWord(*it, getValue(*it, d)));
  }

  int count = 0;
  std::cout << "Found words: " << std::endl;
  //std::set<string, strlencmp>::iterator itt;
  std::set<ruzWord, ruzWordCmp>::iterator itt;
  for (itt = sorted.begin(); itt != sorted.end(); ++itt) {
      //std::cout << *itt << std::endl;
      std::cout << (*itt).first << " " << (*itt).second << std::endl;
      count++;
  }

  std::cout << "Found " << count << " words." << std::endl;

  delete p;
  return 0;
}
示例#4
0
int main (int argc, char* argv[]) {
    BaseBogglePlayer* p = new BogglePlayer();
    
    ifstream infile;
    infile.open("lex.txt");

    if(!infile.is_open()) {
        cout << "Could not open lexicon file - exiting." << endl;
        exit(-1);
    }
  
    cout<< "Reading lexicon..." << endl;
    
    set<string> lex;
    string word;
    int lexSize = 0;
    
    while(infile.is_open() && infile.good()) {
        getline(infile,word);
        
        if(word.size() < 1) continue;
        
        transform(word.begin(), word.end(), word.begin(), ::tolower);
        lex.insert(word);
        ++lexSize;
    }

    infile.close();
    cout << lexSize << " words in the lexicon" << endl;

    infile.open("brd.txt");
    
    if(!infile.is_open()) {
        cout << "Could not open board file - exiting." << endl;
        exit(-1);
    }

    cout << "Reading board..." << endl;
    
    getline(infile, word);
    int rows = atoi(word.c_str());

    getline(infile, word);
    int cols = atoi(word.c_str());

    unsigned int *a = new unsigned int;
    *a = 20;
    unsigned int *b = new unsigned int;
    *b = 23;

    string ** board;
    p->getCustomBoard(board, a, b);

    int x = 0;
    int y = 0;
    while(infile.is_open() && infile.good()) {
        getline(infile,word);
        
        if(word.size() < 1) continue;
        
        transform(word.begin(), word.end(), word.begin(), ::tolower);
        board[x][y % cols] = word;
        
        ++y;

        if(y % cols == 0) {
            ++x;
        }
    }

    infile.close();
    cout << "Board loaded with " << rows << " rows and " << cols << " cols" << endl;

    set<string> words;
    vector<int> locations;

    p->buildLexicon(lex);

    p->setBoard(20,23,board);

    cout << "Getting all valid words..." << endl;
    
    clock_t begin = clock();

    p->getAllValidWords(2, &words);

    clock_t end = clock();

    double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;

    stringstream secs;
    secs << elapsed_secs;

    if(words.size() != 5450) {
        cerr << "Error with getAllValidWords" << endl;
        return -1;
    }

    cout << words.size() << " valid words on the board found in " + secs.str() + " seconds" << endl;

    delete p;
    return 0;
}
示例#5
0
int main (int argc, char* argv[]) {
    set<string> words;
    vector<int> locations;
    BaseBogglePlayer * p = new BogglePlayer();
    set<string> lex;
    std::ifstream in("/Users/m2/Desktop/pa4/pa4/brd.txt");
    string n, m;
    getline(in, n);
    getline(in, m);
    int r = std::atoi(n.c_str());
    int c = std::atoi(m.c_str());
    string **board = new string*[c];
    for (int i = 0; i < r; i++)
        board[i] = new string[c];
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            getline(in, board[i][j]);
            //cout << board[i][j] << " ";
        }
        //cout << "\n";
    }
    in.close();
    in.open("/Users/m2/Desktop/pa4/pa4/lex.txt");
    string line;
    while (in.good()) {
        getline(in, line);
        if (in.good()) lex.insert(line);
    }
  /*string wordA("nod");
  string wordB("where");
  string wordC("do");
  string wordD("we");
  string wordE("go");
  string wordX("fvrst");
  lex.insert(wordA);
  lex.insert(wordC);
  lex.insert(wordD);
  lex.insert(wordE);
  lex.insert(wordB);
  string row0[] = {"a","a","a","fv","a","a","a","a"};
  string row1[] = {"e","f","g","h","rst","a","i","v"};
  string row2[] = {"i","j","k", "l","r","a","i","v"};
  string row3[] = {"r","a","i","v","a","c","d","f"};
  string* board[] = {row0,row1,row2,row3};*/


  p->buildLexicon(lex);

  p->setBoard(r,c,board);

  /*if(p->isInLexicon(wordX)) {
    std::cerr << "Apparent problem with isInLexicon #1." << std::endl;
    return -1;
  }
  if(!p->isInLexicon(wordA) || !p->isInLexicon(wordB)) {
    std::cerr << "Apparent problem with isInLexicon #2." << std::endl;
    return -1;
  }
    locations = p->isOnBoard(wordX);
  if(p->isOnBoard(wordX).size() > 0) {
      for (int i = 0; i < locations.size(); i++) std::cout << locations[i] << " " << board[(locations[i]-locations[i]%8)/8][locations[i]%8] << "\n";
    std::cerr << "Apparent problem with isOnBoard #1." << std::endl;
    return -1;
  }
  locations.clear();
  locations = p->isOnBoard(wordA);
  if(locations.size() != 3 || locations[0] != 3) {
    std::cerr << "Apparent problem with isOnBoard #2." << std::endl;
    return -1;
  }*/
  if(!p->getAllValidWords(2,&words)) {
    std::cerr << "Apparent problem with getAllValidWords #1." << std::endl;
    return -1;
  };
 /*if(words.size() != 2 || words.count(wordA) != 1) {
      std::set<string>::iterator it;
      for (it = words.begin(); it != words.end(); ++it)
          std::cout << *it << "\n";
    std::cerr << "Apparent problem with getAllValidWords #2." << std::endl;
    return -1;
  }*/
  delete p;
  return 0;

}