From 33f602fd7edfa6f3d53a16e99027e3c81f6d8c9c Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 2 Dec 2023 21:38:12 -0500 Subject: Output, and puzzle reduction --- generator/generator.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 13 deletions(-) (limited to 'generator/generator.cpp') diff --git a/generator/generator.cpp b/generator/generator.cpp index 9bef720..49018c8 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -1,5 +1,6 @@ #include "generator.h" +#include #include #include @@ -572,8 +573,25 @@ void generator::run() { 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); + bool word_overlap = false; + for (size_t holo_word_id : holo_form.word_ids) { + for (size_t mero_word_id : mero_form.word_ids) { + if (holo_word_id == mero_word_id) { + word_overlap = true; + break; + } + } + if (word_overlap) { + break; + } + } + + if (!word_overlap) { + if (holo_form.text.size() <= mero_form.text.size() + 5) { + holo_form.puzzles[kBlueTop].insert(mero_form_id); + } + mero_form.puzzles[kRedTop].insert(holo_form_id); + } } } } @@ -609,15 +627,32 @@ void generator::run() { Form& merograph = forms_.at(form_by_text_.at(substr)); - holograph.puzzles[kBlueMiddle].insert(merograph.id); - merograph.puzzles[kRedMiddle].insert(form_id); + bool word_overlap = false; + for (size_t holo_word_id : holograph.word_ids) { + for (size_t mero_word_id : merograph.word_ids) { + if (holo_word_id == mero_word_id) { + word_overlap = true; + break; + } + } + if (word_overlap) { + break; + } + } - 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); + if (!word_overlap) { + if (holograph.text.size() <= merograph.text.size() + 4) { + holograph.puzzles[kBlueMiddle].insert(merograph.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); + } + } + merograph.puzzles[kRedMiddle].insert(form_id); } } } @@ -636,9 +671,15 @@ void generator::run() { Form& holograph = forms_.at(holograph_id); for (size_t merograph_id : merograph_ids) { + const Form& merograph = forms_.at(merograph_id); for (size_t other_id : left_longer_by_shorter[merograph_id]) { if (other_id != holograph_id) { - holograph.puzzles[kPurpleMiddle].insert(other_id); + const Form& other_form = forms_.at(other_id); + + if (holograph.text[merograph.text.size()] != + other_form.text[merograph.text.size()]) { + holograph.puzzles[kPurpleMiddle].insert(other_id); + } } } } @@ -649,9 +690,17 @@ void generator::run() { Form& holograph = forms_.at(holograph_id); for (size_t merograph_id : merograph_ids) { + const Form& merograph = forms_.at(merograph_id); for (size_t other_id : right_longer_by_shorter[merograph_id]) { if (other_id != holograph_id) { - holograph.puzzles[kPurpleMiddle].insert(other_id); + const Form& other_form = forms_.at(other_id); + + if (holograph + .text[holograph.text.size() - merograph.text.size() - 1] != + other_form + .text[other_form.text.size() - merograph.text.size() - 1]) { + holograph.puzzles[kPurpleMiddle].insert(other_id); + } } } } @@ -780,7 +829,12 @@ void generator::run() { for (size_t f_id2 : p2.form_ids) { if (f_id1 != f_id2) { Form& form1 = forms_.at(f_id1); - form1.puzzles[kPurpleTop].insert(f_id2); + const Form& form2 = forms_.at(f_id2); + + if (std::abs(static_cast(form1.text.size()) - + static_cast(form2.text.size())) <= 4) { + form1.puzzles[kPurpleTop].insert(f_id2); + } } } } @@ -824,6 +878,31 @@ void generator::run() { std::cout << "Purple tops: " << per_puzzle_type[kPurpleTop] << std::endl; std::cout << "Purple middles: " << per_puzzle_type[kPurpleMiddle] << std::endl; + + std::vector form_entry; + form_entry.reserve(forms_.size()); + for (const Form& form : forms_) { + if (form.puzzles.empty()) { + form_entry.push_back(fmt::format("\"{}\"", form.text)); + } else { + std::vector entry_per_type; + for (const auto& [puzzle_type, puzzles] : form.puzzles) { + std::vector entry_per_puzzle; + for (size_t puzzle : puzzles) { + entry_per_puzzle.push_back(std::to_string(puzzle)); + } + entry_per_type.push_back( + fmt::format("{}:[{}]", static_cast(puzzle_type), + hatkirby::implode(entry_per_puzzle, ","))); + } + form_entry.push_back(fmt::format("[\"{}\",{{{}}}]", form.text, + hatkirby::implode(entry_per_type, ","))); + } + } + + std::ofstream output_file(outputPath_); + output_file << "extends Node\n\nvar forms = [" + << hatkirby::implode(form_entry, ",") << "]" << std::endl; } size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) { -- cgit 1.4.1