home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.magick      Meh.. another magic/spellcasting forum      90,437 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 90,213 of 90,437   
   Street to All   
   Memory Magick (2/3)   
   10 Jul 25 23:25:15   
   
   [continued from previous message]   
      
               else {   
                   int foundLine = findNearestSection(answers, fileLineIndex,   
   searchTerm);   
                   if (foundLine != -1) {   
                       for (int i = 0; i < questionIndices.size(); ++i) {   
                           if (questionIndices[i] >= foundLine) {   
                               questionNumber = i;   
                               fileLineIndex = questionIndices[i];   
                               break;   
                           }   
                       }   
                       std::cout << "\n\033[36m" << answers[foundLine] <<   
   "\033[37m\n\n";   
                       planetNumber = 0;   
                   }   
                   else {   
                       std::cout << "\n\033[37mNo matching section found.   
   Restarting from beginning.\n\n";   
                       questionNumber = 0;   
                       fileLineIndex = questionIndices[0];   
                       planetNumber = 0;   
                   }   
               }   
           }   
       }   
      
       return false;   
   }   
      
   const int NUM_CARDS = 52;   
      
   bool loadCardsFromFile(const std::string& filename, std::vector&   
   cards) {   
       std::ifstream file(filename);   
       if (!file) {   
           std::cerr << "\033[37mError: Could not open file '" << filename <<   
   "'\n";   
           return false;   
       }   
      
       std::string line;   
       while (std::getline(file, line)) {   
           size_t firstNonSpace = line.find_first_not_of(" \t");   
           if (firstNonSpace == std::string::npos) continue;   
           if (line[firstNonSpace] == '#') continue;   
      
           size_t lastNonSpace = line.find_last_not_of(" \t");   
           std::string trimmed = line.substr(firstNonSpace, lastNonSpace -   
   firstNonSpace + 1);   
           if (!trimmed.empty()) cards.push_back(trimmed);   
       }   
      
       return cards.size() == NUM_CARDS;   
   }   
      
   bool runCardMemoryQuiz(const std::string& filename) {   
       std::vector cards;   
       if (!loadCardsFromFile(filename, cards)) {   
           std::cerr << "\033[37mError: Invalid card file.\n";   
           return false;   
       }   
      
       std::srand(static_cast(std::time(nullptr)));   
      
       std::vector startPositions(NUM_CARDS);   
       for (int i = 0; i < NUM_CARDS; ++i) startPositions[i] = i;   
       std::random_shuffle(startPositions.begin(), startPositions.end());   
      
       int currentRound = 0;   
       int previewCount = 0;   
       bool askPreviewCount = true;   
      
       while (true) {   
           if (askPreviewCount) {   
               std::cout << "\033[37mType shuffle to mix the cards\n";   
               std::cout << "\nNumber of Hints:\n\n>> ";   
               std::string input;   
               std::getline(std::cin, input);   
      
               if (checkForMenuOrQuit(input)) return true;   
      
               if (input == "shuffle") {   
                   cards.clear();   
                   if (!loadCardsFromFile(filename, cards)) {   
                       std::cerr << "\033[37mError: Invalid card file.\n";   
                       return false;   
                   }   
                   for (int i = 0; i < NUM_CARDS; ++i) startPositions[i] = i;   
                   std::random_shuffle(startPositions.begin(), star   
   Positions.end());   
      
                   currentRound = 0;   
                   askPreviewCount = true;   
                   clearScreen();   
                   std::cout << "\033[37mCards shuffled!\n\n";   
                   continue;   
               }   
      
               try {   
                   previewCount = std::stoi(input);   
               }   
               catch (...) {   
                   previewCount = 1;   
               }   
      
               if (previewCount < 1) previewCount = 1;   
               if (previewCount > NUM_CARDS - 1) previewCount = NUM_CARDS - 1;    
   // Leave room for the target card   
               clearScreen();   
               askPreviewCount = false;   
           }   
      
           if (currentRound >= NUM_CARDS) {   
               std::cout << "\033[37mCongratulations! You have completed all 52   
   rounds.\n";   
               return false;   
           }   
      
           int currentIndex = startPositions[currentRound];   
      
           std::cout << "\n\033[37mCard " << (currentRound + 1) << " of " <<   
   NUM_CARDS << ":\n\n";   
      
           // Show previous cards as history (not including the target card)   
           for (int i = previewCount; i >= 1; --i) {   
               int historyIndex = (currentIndex - i + NUM_CARDS) % NUM_CARDS;   
               std::cout << cards[historyIndex];   
               if (i > 1) std::cout << ", ";   
           }   
      
           std::cout << "\n\nWhat comes next?\n\n>> ";   
           std::string userAnswer;   
           std::getline(std::cin, userAnswer);   
      
           if (checkForMenuOrQuit(userAnswer)) return true;   
      
           if (userAnswer == "shuffle") {   
               cards.clear();   
               if (!loadCardsFromFile(filename, cards)) {   
                   std::cerr << "\033[37mError: Invalid card file.\n";   
                   return false;   
               }   
               for (int i = 0; i < NUM_CARDS; ++i) startPositions[i] = i;   
               std::random_shuffle(startPositions.begin(), startPositions.end());   
      
               currentRound = 0;   
               askPreviewCount = true;   
               clearScreen();   
               std::cout << "\033[37mCards shuffled!\n";   
               continue;   
           }   
      
           std::string correctAnswer = cards[currentIndex];   
      
           if (toLower(userAnswer) == toLower(correctAnswer)) {   
               std::cout << "\n\033[32mCorrect!\n\n\033[37m";   
               currentRound++;   
           }   
           else {   
               std::cout << "\n\033[31mIncorrect. Correct answer: " <<   
   correctAnswer << "\n\n\033[37m";   
               std::cout << "\n\033[37mPress enter to continue...";   
               std::getline(std::cin, userAnswer);   
               if (checkForMenuOrQuit(userAnswer)) return true;   
               clearScreen();   
               currentRound = 0;   
               askPreviewCount = true;   
           }   
       }   
      
       return false;   
   }   
      
   void listAllCards(const std::string& filename) {   
       std::vector cards;   
       if (!loadCardsFromFile(filename, cards)) {   
           std::cerr << "\033[37mError: Could not load cards.\n";   
           return;   
       }   
      
       clearScreen();   
       std::cout << "\033[37mAll Cards:\n\n";   
       for (size_t i = 0; i < cards.size(); ++i) {   
           std::cout << (i + 1) << ". " << cards[i] << "\n";   
       }   
      
       std::cout << "\nType \"menu\" to return, \"quit\" to exit, or \"shuffle\"   
   to reshuffle anytime.\n";   
       std::cout << "\nStarting quiz...\n";   
      
       std::vector indices(cards.size());   
       for (int i = 0; i < cards.size(); ++i) indices[i] = i;   
       std::random_shuffle(indices.begin(), indices.end());   
      
       int currentIndex = 0;   
      
       while (true) {   
           if (currentIndex >= indices.size()) {   
               clearScreen();   
               std::cout << "\n\033[37mAll cards completed! Returning to   
   menu...\n";   
               return;   
           }   
      
           int cardIndex = indices[currentIndex];   
      
      
           std::cout << "\n\033[37mWhat is card number " << (cardIndex + 1) <<   
   "?\n\n> ";   
           std::string userAnswer;   
           std::getline(std::cin, userAnswer);   
      
           if (checkForMenuOrQuit(userAnswer)) return;   
      
           if (toLower(userAnswer) == "shuffle") {   
               std::random_shuffle(indices.begin(), indices.end());   
               currentIndex = 0;   
               clearScreen();   
               std::cout << "\033[37mCards reshuffled!\n";   
               continue;   
           }   
      
           std::string correctAnswer = cards[cardIndex];   
      
           if (toLower(userAnswer) == toLower(correctAnswer)) {   
               std::cout << "\n\033[32mCorrect! Card " << (cardIndex + 1) << " is   
   " << correctAnswer << ".\n";   
               currentIndex++;  // move forward   
           }   
           else {   
      
   [continued in next message]   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca