From 1cf317067d40fd64219b18e19c0772748affd726 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 18 Feb 2023 09:30:20 -0500 Subject: Some better triviality checks If a hint is identical to the solution, it is trivial. If a multi-word hint contains a single word solution, or vice versa, it is trivial. --- lingo.cpp | 55 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 14 deletions(-) (limited to 'lingo.cpp') diff --git a/lingo.cpp b/lingo.cpp index ea4697d..4c95fcf 100644 --- a/lingo.cpp +++ b/lingo.cpp @@ -465,6 +465,33 @@ private: bool isClueTrivial(Height height, Colour colour, const verbly::form& clue, const verbly::form& solution) const { + if (height == kMiddle && colour == kWhite) { + // Triviality is checked elsewhere. + return false; + } + + if (clue.getText() == solution.getText()) { + return true; + } + + if (clue.getComplexity() > 1 && solution.getComplexity() == 1) { + auto words = hatkirby::split>(clue.getText(), " "); + for (const auto& word : words) { + if (word == solution.getText()) { + return true; + } + } + } + + if (clue.getComplexity() == 1 && solution.getComplexity() > 1) { + auto words = hatkirby::split>(solution.getText(), " "); + for (const auto& word : words) { + if (word == clue.getText()) { + return true; + } + } + } + if (height == kTop && colour == kWhite) { return !database_->forms((verbly::filter)clue && (verbly::word::synonyms %= solution)).all().empty(); @@ -481,17 +508,8 @@ private: } else if (height == kTop && colour == kPurple) { return clue.getId() == solution.getId(); - } else if (height == kMiddle && colour == kRed) { - if (clue.getComplexity() == 2 && solution.getComplexity() == 1) { - auto words = hatkirby::split>(clue.getText(), " "); - for (const auto& word : words) { - if (word == solution.getText()) { - return true; - } - } - } } else if (height == kMiddle && colour == kYellow) { - if (clue.getComplexity() == solution.getComplexity()) { + if (clue.getComplexity() > 1 && clue.getComplexity() == solution.getComplexity()) { auto clueWords = hatkirby::split>(clue.getText(), " "); auto solutionWords = hatkirby::split>(solution.getText(), " "); std::sort(clueWords.begin(), clueWords.end()); @@ -709,6 +727,7 @@ private: std::ostringstream msg_stream; bool trivial = false; bool profane = false; + std::string bad_hint; for (int i=0; i(kHeightCount); i++) { Height height = static_cast(i); std::optional& colour = parts[i]; @@ -736,6 +755,12 @@ private: } chosenHints[i] = question; + + if (chosenHints[i] == questionPart.getText()) { + trivial = true; + bad_hint = questionPart.getText(); + break; + } } else { chosenHints[i] = questionPart.getText(); } @@ -743,10 +768,13 @@ private: if (isClueTrivial(height, *colour, questionPart, solution)) { trivial = true; + bad_hint = questionPart.getText(); break; } if (isProfane(questionPart)) { profane = true; + bad_hint = questionPart.getText(); + break; } admissible &= makeHintFilter(questionPart, height, *colour, kTowardSolution); @@ -756,12 +784,12 @@ private: if (trivial) { - std::cout << "Puzzle is trivial." << std::endl; + std::cout << "Puzzle is trivial (" << bad_hint << ")." << std::endl; continue; } if (profane) { - std::cout << "Puzzle is profane." << std::endl; + std::cout << "Puzzle is profane (" << bad_hint << ")." << std::endl; continue; } @@ -848,8 +876,7 @@ private: std::cout << ex.what() << std::endl; } - std::cout << "Waiting five seconds then trying again..." << std::endl; - std::this_thread::sleep_for(std::chrono::seconds(5)); + std::cout << "Trying again..." << std::endl; } // generatePuzzle is only called when there is no cached puzzle and there -- cgit 1.4.1