From 807b1f049bcc4597400eea21228875efe098ebc5 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 10 Dec 2022 16:45:29 -0500 Subject: Added orange puzzles fixes #23 --- lingo.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 7 deletions(-) (limited to 'lingo.cpp') diff --git a/lingo.cpp b/lingo.cpp index c2f36af..12471d1 100644 --- a/lingo.cpp +++ b/lingo.cpp @@ -37,6 +37,7 @@ enum Colour { kBrown, kYellow, kGreen, + kOrange, kColourCount }; @@ -48,7 +49,8 @@ const std::string COLOUR_EMOJIS[kColourCount] = { "🟪", "🟫", "🟨", - "🟩" + "🟩", + "🟧", }; const std::string NONE_EMOTE = "<:xx:1047267830535557180>"; @@ -61,7 +63,8 @@ const std::string COLOUR_EMOTES[kColourCount] = { "<:pr:1047262146926489691>", "<:bn:1047262139187998790>", "<:yw:1047262152781737986>", - "<:gn:1047262141914304633>" + "<:gn:1047262141914304633>", + "<:or:1047262144934182983>", }; enum FilterDirection { @@ -272,6 +275,33 @@ verbly::filter makeHintFilter(verbly::filter subfilter, Height height, Colour co return {}; } +class wanderlust { +public: + explicit wanderlust(const std::string& filename) + { + std::ifstream file(filename); + std::string line; + while (std::getline(file, line)) + { + std::string line2; + if (!std::getline(file, line2)) + { + throw std::invalid_argument("Wanderlust file is malformed."); + } + + puzzles_.emplace_back(line, line2); + } + } + + std::tuple getPuzzle(std::mt19937& rng) const + { + return puzzles_.at(std::uniform_int_distribution(0, puzzles_.size()-1)(rng)); + } + +private: + std::vector> puzzles_; +}; + class lingo { public: lingo(std::mt19937& rng) : rng_(rng) {} @@ -380,6 +410,7 @@ public: database_ = std::make_unique(config["verbly_datafile"].as()); imagenet_ = std::make_unique(config["imagenet"].as()); + wanderlust_ = std::make_unique(config["wanderlust"].as()); scoreboard_endpoint_ = config["scoreboard_endpoint"].as(); scoreboard_secret_code_ = config["scoreboard_secret_code"].as(); @@ -407,6 +438,7 @@ private: {kMiddle, kBlue}, {kMiddle, kPurple}, {kMiddle, kGreen}, + {kMiddle, kOrange}, {kBottom, kWhite}, {kBottom, kBlack}, {kBottom, kRed}, @@ -447,6 +479,7 @@ private: int expensive_uses = 0; int moderate_uses = 0; int green_uses = 0; + int orange_uses = 0; std::array, kHeightCount> parts; for (int height = 0; height < static_cast(kHeightCount); height++) { if (std::bernoulli_distribution(0.5)(rng_)) { @@ -472,6 +505,10 @@ private: { green_uses++; } + if (colour == kOrange) + { + orange_uses++; + } std::cout << COLOUR_EMOJIS[colour]; } else { @@ -503,6 +540,13 @@ private: continue; } + std::string orange_clue; + std::string orange_solution; + if (orange_uses > 0) + { + std::tie(orange_clue, orange_solution) = wanderlust_->getPuzzle(rng_); + } + verbly::filter forwardFilter = cleanFilter && wordFilter; for (int i=0; i(kHeightCount); i++) { Height height = static_cast(i); @@ -510,7 +554,12 @@ private: if (!colour.has_value()) { continue; } - forwardFilter &= makeHintFilter(wordFilter, height, *colour, kTowardSolution); + if (*colour == kOrange) + { + forwardFilter &= (verbly::form::text == orange_solution); + } else { + forwardFilter &= makeHintFilter(wordFilter, height, *colour, kTowardSolution); + } } verbly::form solution = database_->forms(forwardFilter).first(); @@ -523,11 +572,17 @@ private: Height height = static_cast(i); std::optional& colour = parts[i]; if (colour.has_value()) { - verbly::filter questionFilter = makeHintFilter(solution, height, *colour, kTowardQuestion); - verbly::form questionPart = database_->forms(questionFilter && cleanFilter && wordFilter).first(); - msg_stream << COLOUR_EMOTES[*colour] << " " << questionPart.getText() << std::endl; + if (*colour == kOrange) + { + msg_stream << COLOUR_EMOTES[*colour] << " " << orange_clue << std::endl; + admissible &= (verbly::form::text == orange_solution); + } else { + verbly::filter questionFilter = makeHintFilter(solution, height, *colour, kTowardQuestion); + verbly::form questionPart = database_->forms(questionFilter && cleanFilter && wordFilter).first(); + msg_stream << COLOUR_EMOTES[*colour] << " " << questionPart.getText() << std::endl; - admissible &= makeHintFilter(questionPart, height, *colour, kTowardSolution); + admissible &= makeHintFilter(questionPart, height, *colour, kTowardSolution); + } } else { msg_stream << NONE_EMOTE << std::endl; } @@ -596,6 +651,7 @@ private: std::mutex answers_mutex_; std::string scoreboard_endpoint_; std::string scoreboard_secret_code_; + std::unique_ptr wanderlust_; }; int main(int argc, char** argv) -- cgit 1.4.1