示例#1
0
文件: scrabble.cpp 项目: elowe/School
 // Method prints out the results for each set of input user tiles
 void printResults(const string l)
 {
   cout << setw(2) << highScore;
   cout << " " << l << ": ";
   for(Match::const_iterator itr = matching.begin(); itr != matching.end(); itr++)
     if(l == itr->first)
       cout << itr->second << " ";
     
   if(count == 0)
     cout << "No words found." << endl;
   else
     cout << endl;
   
   return;
 } // void printResults(const string l)
示例#2
0
文件: scrabble.cpp 项目: elowe/School
 // Method fills the map matching, which is a multimap of the highest
 // scoring words for a given line.  This is because one line may give
 // multiple same-scoring words that are all 'the best' word to play
 // for a move, such as how tiles 'abcdefg' give badge, cafe, and face,
 // which are each worth 9 points.  Method will continue to add new 
 // same-scoring words until a word of higher score is found, which resets
 // the map for the particular key.
 void fillMatching(const string &line, const string &s)
 {
   wordScore = myScored.find(s)->second; // set wordScore to score of word
   if(count == 0)
   {
     highScore = wordScore;// set highScore to score of word
     matching.insert(Match::value_type(line, s)); //insert into map
     setCount(); // increase count
   }//if(count == 0)
   else
   {
     for(Match::const_iterator itr = matching.begin(); itr != matching.end(); itr++)
       if(s == itr->second)
         return;
        
     if(wordScore > highScore)
     {
       matching.erase(line);
       count = 0;
       matching.insert(Match::value_type(line, s)); //insert into map
       highScore = wordScore;
       setCount();
     }// if(wordScore > highScore)
     else
     {
       if(wordScore == highScore)
       {
         matching.insert(Match::value_type(line, s)); //insert into map
         setCount(); //increment count
       } // if(wordScore == highScore)   
       else
         return; // wordScore < highScore, so ignore and leave
     }// else wordScore <= highScore
   }// else count > 0
   return;
 } // void fillMatching()