From 907917c5c9ec43ea9a7d4c3ae07ab2d7e48acc29 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 30 Nov 2022 18:23:03 -0500 Subject: Initial commit --- lingo.cpp | 273 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 lingo.cpp (limited to 'lingo.cpp') diff --git a/lingo.cpp b/lingo.cpp new file mode 100644 index 0000000..e13bb53 --- /dev/null +++ b/lingo.cpp @@ -0,0 +1,273 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum Height { + kTop, + kMiddle, + kBottom, + kHeightCount +}; + +enum Colour { + kWhite, + kBlack, + kRed, + kBlue, + kPurple, + kBrown, + kColourCount +}; + +const std::string COLOUR_EMOJIS[kColourCount] = { + "⬜️", + "⬛️", + "🟥", + "🟦", + "🟪", + "🟫" +}; + +int main(int argc, char** argv) +{ + std::random_device randomDevice; + std::mt19937 rng{randomDevice()}; + + if (argc != 2) + { + std::cout << "usage: lingo [configfile]" << std::endl; + return -1; + } + + std::string configfile(argv[1]); + YAML::Node config = YAML::LoadFile(configfile); + + verbly::database database(config["verbly_datafile"].as()); + + /*mastodonpp::Instance instance{ + config["mastodon_instance"].as(), + config["mastodon_token"].as()}; + mastodonpp::Connection connection{instance};*/ + + std::set> filters = { + {kBottom, kWhite}, + {kBottom, kBlack}, + {kTop, kPurple}, + {kTop, kWhite}, + {kBottom, kRed}, + {kBottom, kBlue}, + }; + + verbly::filter cleanFilter = + !(verbly::word::usageDomains %= (verbly::notion::wnid == 106718862)) // ethnic slurs + && !(verbly::notion::wnid == 110630093); // "spastic" + + for (;;) + { + bool puzzleEmpty = true; + std::array, kHeightCount> parts; + for (int height = 0; height < static_cast(kHeightCount); height++) { + if (std::bernoulli_distribution(0.4)(rng)) { + int colour = std::uniform_int_distribution(0, static_cast(kColourCount)-1)(rng); + if (filters.count({static_cast(height), static_cast(colour)})) { + parts[static_cast(height)] = static_cast(colour); + puzzleEmpty = false; + } + } + } + + if (puzzleEmpty) { + continue; + } + + verbly::filter forwardFilter = cleanFilter && (verbly::form::proper == false); + for (int i=0; i(kHeightCount); i++) { + Height height = static_cast(i); + std::optional& colour = parts[i]; + if (!colour.has_value()) { + continue; + } + switch (*colour) { + case kWhite: { + switch (height) { + case kBottom: { + forwardFilter &= (verbly::word::synonyms); + break; + } + case kTop: { + forwardFilter &= (verbly::form::pronunciations %= + verbly::filter("homophones", false, + (verbly::pronunciation::forms %= verbly::filter( + verbly::form::id, + verbly::filter::comparison::field_does_not_equal, + verbly::form::id)))); + break; + } + default: break; // Not supposed yet. + } + break; + } + case kBlack: { + switch (height) { + case kBottom: { + forwardFilter &= (verbly::word::antonyms); + break; + } + default: break; // Not supposed yet. + } + break; + } + case kBrown: { + switch (height) { + case kBottom: { + forwardFilter &= (verbly::notion::causes); + break; + } + default: break; // Not supposed yet. + } + break; + } + case kRed: { + switch (height) { + case kBottom: { + forwardFilter &= (verbly::notion::partMeronyms); + break; + } + default: break; // Not supposed yet. + } + break; + } + case kBlue: { + switch (height) { + case kBottom: { + forwardFilter &= (verbly::notion::partHolonyms); + break; + } + default: break; // Not supposed yet. + } + break; + } + case kPurple: { + switch (height) { + case kTop: { + forwardFilter &= (verbly::pronunciation::rhymes); + break; + } + default: break; // Not supposed yet. + } + break; + } + default: break; // Not supposed yet. + } + } + + verbly::word solution = database.words(forwardFilter).first(); + + for (int i=0; i(kHeightCount); i++) { + Height height = static_cast(i); + std::optional& colour = parts[i]; + if (colour.has_value()) { + verbly::filter questionFilter; + switch (*colour) { + case kWhite: { + switch (height) { + case kBottom: { + questionFilter = (verbly::word::synonyms %= solution); + break; + } + case kTop: { + questionFilter = (verbly::form::pronunciations %= + verbly::filter("homophones", false, + (verbly::pronunciation::forms %= ((verbly::filter)solution && verbly::filter( + verbly::form::id, + verbly::filter::comparison::field_does_not_equal, + verbly::form::id))))); + break; + } + default: break; // Not supposed yet. + } + break; + } + case kBlack: { + switch (height) { + case kBottom: { + questionFilter = (verbly::word::antonyms %= solution); + break; + } + default: break; // Not supposed yet. + } + break; + } + case kBrown: { + switch (height) { + case kBottom: { + questionFilter = (verbly::notion::effects %= solution); + break; + } + default: break; // Not supposed yet. + } + break; + } + case kBlue: { + switch (height) { + case kBottom: { + /*questionFilter = ((verbly::notion::fullMemberHolonyms %= solution) + || (verbly::notion::fullPartHolonyms %= solution) + || (verbly::notion::fullSubstanceHolonyms %= solution));*/ + //questionFilter &= !(verbly::notion::words %= solution); + questionFilter = (verbly::notion::partMeronyms %= solution); + break; + } + default: break; // Not supposed yet. + } + break; + } + case kRed: { + switch (height) { + case kBottom: { + /*questionFilter = ((verbly::notion::fullMemberMeronyms %= solution) + || (verbly::notion::fullPartMeronyms %= solution) + || (verbly::notion::fullSubstanceMeronyms %= solution));*/ + questionFilter = (verbly::notion::partHolonyms %= solution); + //questionFilter &= !(verbly::notion::words %= solution); + break; + } + default: break; // Not supposed yet. + } + break; + } + case kPurple: { + switch (height) { + case kTop: { + questionFilter = (verbly::pronunciation::rhymes %= solution); + break; + } + default: break; // Not supposed yet. + } + break; + } + default: break; // Not supposed yet. + } + verbly::word questionPart = database.words(questionFilter && cleanFilter && (verbly::form::proper == false)).first(); + std::cout << COLOUR_EMOJIS[*colour] << " " << questionPart.getBaseForm().getText() << std::endl; + } else { + std::cout << "▪️" << std::endl; + } + } + std::cout << "(" << solution.getBaseForm().getText().size() << ")" << std::endl << std::endl << solution.getBaseForm().getText() << std::endl; + + + // We can poll the timeline at most once every five minutes. + std::this_thread::sleep_for(std::chrono::hours(3)); + } +} -- cgit 1.4.1