ordle/main.cc

85 lines
2.6 KiB
C++
Raw Normal View History

2024-12-14 14:14:19 +01:00
#include "ordle.h"
2024-12-26 16:00:53 +01:00
#include <fstream>
#include <iostream>
2024-12-14 14:02:21 +01:00
2024-12-14 14:14:19 +01:00
int main(int argc, char *argv[]) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <wordlist file>\n";
return 1;
}
std::ifstream file(argv[1]);
if (!file) {
std::cerr << "Could not open file: " << argv[1] << "\n";
return 1;
}
2024-12-14 15:34:19 +01:00
while (true) {
auto candidates = read_candidates(file);
2024-12-26 16:00:53 +01:00
std::cout << "File (" << argv[1] << ") loaded. " << candidates.size()
<< " candidates available.\n";
2024-12-14 15:34:19 +01:00
std::string wrong;
2024-12-26 16:00:53 +01:00
IndexMap green, yellow;
2024-12-14 14:14:19 +01:00
2024-12-14 15:34:19 +01:00
while (!candidates.empty()) {
std::cout << "Enter wrong letters:\n";
std::getline(std::cin, wrong);
2024-12-14 14:14:19 +01:00
2024-12-14 15:34:19 +01:00
std::cout << "Enter correct letters (letter index)*:\n";
std::string correct_input;
std::getline(std::cin, correct_input);
green = build_list(correct_input);
2024-12-14 14:14:19 +01:00
2024-12-14 15:34:19 +01:00
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";
2024-12-26 16:00:53 +01:00
if (candidates.size() <= 1)
break;
2024-12-14 14:44:34 +01:00
}
2024-12-14 15:34:19 +01:00
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 (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";
}
}
2024-12-14 14:14:19 +01:00
2024-12-14 15:34:19 +01:00
// Reset file stream to reload word list
file.clear();
file.seekg(0, std::ios::beg);
2024-12-14 14:14:19 +01:00
}
return 0;
}