From e45e0674f3c7406b98e1dbeeea688fe0567f6523 Mon Sep 17 00:00:00 2001 From: dDogge Date: Sat, 4 Jan 2025 14:05:14 +0100 Subject: [PATCH] Final product, sent for evaluation --- Makefile | 2 ++ ordle.cc | 25 +++++++++++++++++-------- test/test.cc | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c9fa133..958dc79 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ CXXFLAGS = -Wall -Wextra -Wpedantic -Wshadow -Wnon-virtual-dtor \ -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wconversion \ -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -std=c++17 +CXXFLAGS += -Wno-conversion + CXXFLAGS += -I. ifeq ($(RELEASE),) diff --git a/ordle.cc b/ordle.cc index fbcf53d..2b5edc6 100644 --- a/ordle.cc +++ b/ordle.cc @@ -30,29 +30,38 @@ std::vector read_candidates(std::istream &input) { } bool wrong_fn::operator()(const std::string &word) const { - return contains_any_of(word, letter_set); + std::string lowercase_word = word; + std::transform(lowercase_word.begin(), lowercase_word.end(), lowercase_word.begin(), ::tolower); + std::string lowercase_set = letter_set; + std::transform(lowercase_set.begin(), lowercase_set.end(), lowercase_set.begin(), ::tolower); + return contains_any_of(lowercase_word, lowercase_set); } bool correct_fn::operator()(const std::string &word) const { - return std::all_of(map.begin(), map.end(), [&word](const auto &pair) { - return contains_at(word, pair.second, pair.first); + std::string lowercase_word = word; + std::transform(lowercase_word.begin(), lowercase_word.end(), lowercase_word.begin(), ::tolower); + return std::all_of(map.begin(), map.end(), [&lowercase_word](const auto &pair) { + return contains_at(lowercase_word, std::tolower(pair.second), pair.first); }); } bool misplaced_fn::operator()(const std::string &word) const { + std::string lowercase_word = word; + std::transform(lowercase_word.begin(), lowercase_word.end(), lowercase_word.begin(), ::tolower); + if (map.empty()) { return true; } - if (std::all_of(map.begin(), map.end(), [&word](const auto &pair) { - return pair.first < word.size() && word[pair.first] == pair.second; + if (std::all_of(map.begin(), map.end(), [&lowercase_word](const auto &pair) { + return pair.first < lowercase_word.size() && lowercase_word[pair.first] == std::tolower(pair.second); })) { return false; } - if (std::any_of(map.begin(), map.end(), [&word](const auto &pair) { - return std::find(word.begin(), word.end(), pair.second) != - word.end(); + if (std::any_of(map.begin(), map.end(), [&lowercase_word](const auto &pair) { + return std::find(lowercase_word.begin(), lowercase_word.end(), std::tolower(pair.second)) != + lowercase_word.end(); })) { return true; } diff --git a/test/test.cc b/test/test.cc index a906a7f..2d13b5c 100644 --- a/test/test.cc +++ b/test/test.cc @@ -114,6 +114,7 @@ void test_build_list() { } } +//Added to check a bug mainly void test_misplaced_fn_empty() { std::vector candidates = {"apple", "ample", "angle"}; std::string wrong = "x";