diff --git a/main.cc b/main.cc index ba607b9..a0a13e2 100644 --- a/main.cc +++ b/main.cc @@ -14,33 +14,68 @@ int main(int argc, char *argv[]) { return 1; } - auto candidates = read_candidates(file); - std::cout << "File (" << argv[1] << ") loaded. " << candidates.size() << " candidates available.\n"; + while (true) { + auto candidates = read_candidates(file); + std::cout << "File (" << argv[1] << ") loaded. " << candidates.size() << " candidates available.\n"; - std::string wrong; - letters_and_indices green, yellow; + std::string wrong; + letters_and_indices green, yellow; - while (!candidates.empty()) { - auto [new_wrong, new_green, new_yellow] = prompt(); - wrong.append(new_wrong); - green.insert(new_green.begin(), new_green.end()); - yellow.insert(new_yellow.begin(), new_yellow.end()); + while (!candidates.empty()) { + std::cout << "Enter wrong letters:\n"; + std::getline(std::cin, wrong); - do_filter(candidates, wrong, green, yellow); + std::cout << "Enter correct letters (letter index)*:\n"; + std::string correct_input; + std::getline(std::cin, correct_input); + green = build_list(correct_input); - std::cout << "Remaining candidates: " << candidates.size() << "\n"; - for (const auto &word : candidates) { - std::cout << word << " "; + std::cout << "Enter misplaced letters (letter index)*:\n"; + std::string misplaced_input; + std::getline(std::cin, misplaced_input); + yellow = build_list(misplaced_input); + + do_filter(candidates, wrong, green, yellow); + + std::cout << "Remaining candidates: " << candidates.size() << "\n"; + for (const auto &word : candidates) { + std::cout << word << " "; + } + std::cout << "\n\n"; + + if (candidates.size() <= 1) break; } - std::cout << "\n\n"; - if (candidates.size() <= 1) break; - } + if (candidates.empty()) { + std::cout << "No solution found.\n"; + std::cout << "Do you want to solve another Wordle? (yes/no): "; + std::string response; + std::getline(std::cin, response); + if (response == "no") { + std::cout << "Thank you for playing!\n"; + break; + } + } else { + std::cout << "Solution: " << candidates.front() << "\n"; + std::cout << "Did you find the word? (yes/no): "; + std::string response; + std::getline(std::cin, response); - if (candidates.empty()) { - std::cout << "No solution found.\n"; - } else { - std::cout << "Solution: " << candidates.front() << "\n"; + if (response == "yes") { + std::cout << "Do you want to solve another Wordle? (yes/no): "; + std::getline(std::cin, response); + if (response == "no") { + std::cout << "Thank you for playing!\n"; + break; + } + } else { + std::cout << "Continuing with the current Wordle...\n"; + } + } + + // Reset file stream to reload word list + file.clear(); + file.seekg(0, std::ios::beg); } return 0;