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 --- generate_orange.rb | 56 +++++++++++++++++++++++++++++++++++++++++++ lingo.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 generate_orange.rb diff --git a/generate_orange.rb b/generate_orange.rb new file mode 100644 index 0000000..310f823 --- /dev/null +++ b/generate_orange.rb @@ -0,0 +1,56 @@ +require 'sqlite3' + +db = SQLite3::Database.open ARGV[0] +form_rows = db.query "SELECT form FROM forms WHERE proper = 0" + +wanderlust = {} +wanderlust["w"] = "1" +wanderlust["a"] = "2" +wanderlust["n"] = "3" +wanderlust["d"] = "4" +wanderlust["e"] = "5" +wanderlust["r"] = "6" +wanderlust["l"] = "7" +wanderlust["u"] = "8" +wanderlust["s"] = "9" +wanderlust["t"] = "0" + +forms = form_rows.map {|row| row[0].downcase} +orange_forms = forms.reject {|form| /^[wanderlust]*$/.match(form).nil?}.select {|form| form.length >= 3} +words = orange_forms.map do |form| + oranged = form.chars.map {|letter| wanderlust[letter]}.join + [form, oranged, oranged.to_i] + end +words.sort_by! {|word| word[2]} + +puts words.length +puts words[10] +puts words.sample +puts "" + +oranges_by_num = {} +puzzles = [] +words.each do |vals| + oranges_by_num.each do |num, form| + opposite = (vals[2] - num.to_i).to_s + if oranges_by_num.include? opposite + puzzles << ["#{form} + #{oranges_by_num[opposite]}", vals[0]] + puzzles << ["#{oranges_by_num[opposite]} + #{form}", vals[0]] + end + opposite = "0" + opposite + if oranges_by_num.include? opposite + puzzles << ["#{form} + #{oranges_by_num[opposite]}", vals[0]] + puzzles << ["#{oranges_by_num[opposite]} + #{form}", vals[0]] + end + end + oranges_by_num[vals[1]] = vals[0] +end + +puts puzzles.length +puts puzzles.sample + +File.open("wanderlust.txt", "w") do |f| + puzzles.each do |puzzle| + f.write("#{puzzle[0]}\n#{puzzle[1]}\n") + end +end 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