Finalized
All checks were successful
ci/woodpecker/push/test Pipeline was successful

This commit is contained in:
dDogge 2025-01-03 16:44:41 +01:00
parent 06078006f6
commit 7cdf807337
3 changed files with 22 additions and 1 deletions

View file

@ -1,7 +1,10 @@
# Ordle: A Wordle Solver # Ordle: A Wordle Solver
## Douglas Fjällrud, Axel Blomén
## Design ## Design
The program is structured into three main components that work together to solve Wordle puzzles. The first part handles the loading and preparation of the word list. The *read\_candidates* function reads all words from a file and filters out those that are not exactly five letters long. At the same time, the words are converted to lowercase, and duplicates are removed. This ensures that the program starts with a clean list of potential solutions. The program is structured into three main components that work together to solve Wordle puzzles. The first part handles the loading and preparation of the word list. The *read\_candidates* function reads all words from a file and filters out those that are not exactly five letters long. At the same time, the words are converted to lowercase, and duplicates are removed. This ensures that the program starts with a clean list of potential solutions.
The *build_list* function processes user input to create mappings of letters to their respective indices. This function plays a crucial role in interpreting user-provided data about correct and misplaced letters, converting it into a format usable by the filtering logic. By breaking down input strings into index-letter pairs, *build_list* ensures the program can apply precise filtering conditions.
The second part of the program focuses on filtering words based on user input. Three functors are used to handle different types of requirements: The second part of the program focuses on filtering words based on user input. Three functors are used to handle different types of requirements:
- *wrong\_fn*: Filters out words that contain letters the user has marked as "incorrect". - *wrong\_fn*: Filters out words that contain letters the user has marked as "incorrect".
@ -12,10 +15,12 @@ These functors are applied in the *do\_filter* function, which filters the curre
The third component manages user interaction. The *prompt* function is used to gather input from the user, such as letters that do not appear in the word, green letters with their positions, and yellow letters with their incorrect positions. This input is then used to update the filtering process. The third component manages user interaction. The *prompt* function is used to gather input from the user, such as letters that do not appear in the word, green letters with their positions, and yellow letters with their incorrect positions. This input is then used to update the filtering process.
The program consists of three files: The program consists of three files:
- **main.cc**: Runs the program and uses logic from **ordle.cc**. - **main.cc**: Runs the program and uses logic from **ordle.cc**.
- **ordle.cc**: Implements the core logic. - **ordle.cc**: Implements the core logic.
- **ordle.h**: Contains the definitions for the functions and functors in *ordle.cc*. - **ordle.h**: Contains the definitions for the functions and functors in *ordle.cc*.
- **test.cc**: contains the unit tests
## Build Instructions ## Build Instructions
Common actions are defined in the provided Justfile and can be viewed with Common actions are defined in the provided Justfile and can be viewed with
@ -71,6 +76,7 @@ Common actions are defined in the provided Justfile and can be viewed with
| Lint Code | `make clang-tidy` | | Lint Code | `make clang-tidy` |
| Static Analysis | `make cppcheck` | | Static Analysis | `make cppcheck` |
| Format Code | `make format` | | Format Code | `make format` |
| Run the tests | `make test` |
| Watch and Rebuild | `just watch` | | Watch and Rebuild | `just watch` |
--- ---

View file

@ -39,8 +39,11 @@ bool correct_fn::operator()(const std::string &word) const {
}); });
} }
// TODO:Correct but ugly
bool misplaced_fn::operator()(const std::string &word) const { bool misplaced_fn::operator()(const std::string &word) const {
if (map.empty()) {
return true;
}
if (std::all_of(map.begin(), map.end(), [&word](const auto &pair) { if (std::all_of(map.begin(), map.end(), [&word](const auto &pair) {
return pair.first < word.size() && word[pair.first] == pair.second; return pair.first < word.size() && word[pair.first] == pair.second;
})) { })) {

View file

@ -114,6 +114,17 @@ void test_build_list() {
} }
} }
void test_misplaced_fn_empty() {
std::vector<std::string> candidates = {"apple", "ample", "angle"};
std::string wrong = "x";
IndexMap green{{1, 'p'}};
IndexMap yellow;
do_filter(candidates, wrong, green, yellow);
assert(candidates.size() == 1);
assert(candidates[0] == "apple");
std::cout << "test_misplaced_fn_empty passed.\n";
}
int main() { int main() {
test_read_candidates(); test_read_candidates();
test_contains_any_of(); test_contains_any_of();
@ -122,6 +133,7 @@ int main() {
test_wrong_fn(); test_wrong_fn();
test_correct_fn(); test_correct_fn();
test_misplaced_fn(); test_misplaced_fn();
test_misplaced_fn_empty();
test_do_filter(); test_do_filter();
test_build_list(); test_build_list();