From 266f374ae4357acd2c23cd0d7aff4d2c25406f80 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 2 Dec 2023 19:02:47 -0500 Subject: Red/blue top and middle, purple middle --- generator/generator.cpp | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) (limited to 'generator/generator.cpp') diff --git a/generator/generator.cpp b/generator/generator.cpp index aaf546c..9bef720 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -530,6 +530,134 @@ void generator::run() { } } + // Red/Blue Top + { + std::map, std::vector> tokenized; + for (const auto& [phonemes, pronunciations] : + pronunciations_by_blank_phonemes_) { + tokenized[hatkirby::split>(phonemes, " ")] = + pronunciations; + } + + hatkirby::progress ppgs("Generating top red/blue puzzles...", + tokenized.size()); + for (const auto& [phonemes, pronunciations] : tokenized) { + ppgs.update(); + + std::set> visited; + for (int i = 0; i < phonemes.size(); i++) { + for (int l = 2; l <= phonemes.size() - i; l++) { + if (i == 0 && l == phonemes.size()) { + continue; + } + + std::list sublist; + for (auto j = std::next(phonemes.begin(), i); + j != std::next(phonemes.begin(), i + l); j++) { + sublist.push_back(*j); + } + + if (tokenized.count(sublist) && !visited.count(sublist)) { + visited.insert(sublist); + + for (size_t holophone_id : pronunciations) { + for (size_t merophone_id : tokenized[sublist]) { + const Pronunciation& holophone = + pronunciations_.at(holophone_id); + const Pronunciation& merophone = + pronunciations_.at(merophone_id); + + for (size_t holo_form_id : holophone.form_ids) { + Form& holo_form = forms_.at(holo_form_id); + for (size_t mero_form_id : merophone.form_ids) { + Form& mero_form = forms_.at(mero_form_id); + + holo_form.puzzles[kBlueTop].insert(mero_form_id); + mero_form.puzzles[kRedTop].insert(holo_form_id); + } + } + } + } + } + } + } + } + } + + // Red/Blue Middle + std::unordered_map> left_shorter_by_longer; + std::unordered_map> left_longer_by_shorter; + std::unordered_map> right_shorter_by_longer; + std::unordered_map> right_longer_by_shorter; + { + hatkirby::progress ppgs("Generating red/blue middle puzzles...", + form_by_text_.size()); + for (const auto& [text, form_id] : form_by_text_) { + ppgs.update(); + + Form& holograph = forms_.at(form_id); + std::unordered_set visited; + for (int i = 0; i < text.size(); i++) { + for (int l = 3; l <= text.size() - i; l++) { + if (i == 0 && l == text.size()) { + continue; + } + + std::string substr = text.substr(i, l); + if (form_by_text_.count(substr) && !visited.count(substr)) { + visited.insert(substr); + + Form& merograph = forms_.at(form_by_text_.at(substr)); + + holograph.puzzles[kBlueMiddle].insert(merograph.id); + merograph.puzzles[kRedMiddle].insert(form_id); + + if (i == 0) { + left_shorter_by_longer[form_id].insert(merograph.id); + left_longer_by_shorter[merograph.id].insert(form_id); + } else if (i + l == text.size()) { + right_shorter_by_longer[form_id].insert(merograph.id); + right_longer_by_shorter[merograph.id].insert(form_id); + } + } + } + } + } + } + + // Purple Middle + { + hatkirby::progress ppgs( + "Generating purple middle puzzles...", + left_shorter_by_longer.size() + right_shorter_by_longer.size()); + + for (const auto& [holograph_id, merograph_ids] : left_shorter_by_longer) { + ppgs.update(); + + Form& holograph = forms_.at(holograph_id); + for (size_t merograph_id : merograph_ids) { + for (size_t other_id : left_longer_by_shorter[merograph_id]) { + if (other_id != holograph_id) { + holograph.puzzles[kPurpleMiddle].insert(other_id); + } + } + } + } + + for (const auto& [holograph_id, merograph_ids] : right_shorter_by_longer) { + ppgs.update(); + + Form& holograph = forms_.at(holograph_id); + for (size_t merograph_id : merograph_ids) { + for (size_t other_id : right_longer_by_shorter[merograph_id]) { + if (other_id != holograph_id) { + holograph.puzzles[kPurpleMiddle].insert(other_id); + } + } + } + } + } + // Red/Blue Bottom std::unordered_map> meronyms_by_holonym; { @@ -687,9 +815,15 @@ void generator::run() { std::cout << "Black bottoms: " << per_puzzle_type[kBlackBottom] << std::endl; std::cout << "Black double bottoms: " << per_puzzle_type[kDoubleBlackBottom] << std::endl; + std::cout << "Red tops: " << per_puzzle_type[kRedTop] << std::endl; + std::cout << "Red middles: " << per_puzzle_type[kRedMiddle] << std::endl; std::cout << "Red bottoms: " << per_puzzle_type[kRedBottom] << std::endl; + std::cout << "Blue tops: " << per_puzzle_type[kBlueTop] << std::endl; + std::cout << "Blue middles: " << per_puzzle_type[kBlueMiddle] << std::endl; std::cout << "Blue bottoms: " << per_puzzle_type[kBlueBottom] << std::endl; std::cout << "Purple tops: " << per_puzzle_type[kPurpleTop] << std::endl; + std::cout << "Purple middles: " << per_puzzle_type[kPurpleMiddle] + << std::endl; } size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) { -- cgit 1.4.1