From c7e2188850370689a2467d6241097250d325bd0f Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 12 Dec 2023 18:26:27 -0500 Subject: Generate wanderlust and paintings --- generator/generator.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) (limited to 'generator/generator.cpp') diff --git a/generator/generator.cpp b/generator/generator.cpp index 0639492..cd13051 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -857,6 +857,25 @@ void generator::run() { } } + // Orange addition + std::vector orange_addition; + { + hatkirby::progress ppgs("Generating orange addition puzzles...", + wanderlust_.size()); + + for (const auto& [cipher, form_id] : wanderlust_) { + for (const auto& [cipher2, form_id2] : wanderlust_) { + if (cipher2 >= cipher) { + break; + } + if (wanderlust_.count(cipher - cipher2)) { + orange_addition.push_back(fmt::format( + "[{},{},{}]", form_id2, wanderlust_[cipher - cipher2], form_id)); + } + } + } + } + // Count up all of the generated puzzles. int total_puzzles = 0; int reusable_words = 0; @@ -916,6 +935,27 @@ void generator::run() { std::ofstream output_file(outputPath_); output_file << "extends Node\n\nvar forms = [" << hatkirby::implode(form_entry, ",") << "]" << std::endl; + + std::vector painting_entries; + { + std::list paintings(readFile(datadirPath_ / "paintings.txt")); + for (const std::string& line : paintings) { + auto parts = hatkirby::split>(line, ","); + painting_entries.push_back( + fmt::format("[\"{}\",\"{}\"]", parts[0], parts[1])); + } + } + output_file << "var paintings = [" << hatkirby::implode(painting_entries, ",") + << "]" << std::endl; + + std::vector cipher_lines; + for (const auto& [cipher, form_id] : wanderlust_) { + cipher_lines.push_back(std::to_string(form_id)); + } + output_file << "var wanderlust = [" << hatkirby::implode(cipher_lines, ",") + << "]" << std::endl; + output_file << "var addition = [" << hatkirby::implode(orange_addition, ",") + << "]" << std::endl; } size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) { @@ -996,7 +1036,59 @@ size_t generator::LookupOrCreateForm(const std::string& word) { } else { size_t form_id = forms_.size(); form_by_text_[word] = form_id; - forms_.push_back({.id = form_id, .text = word}); + std::optional ciphered; + if (std::all_of(word.begin(), word.end(), [](char ch) { + return ch == 'w' || ch == 'a' || ch == 'n' || ch == 'd' || + ch == 'e' || ch == 'r' || ch == 'l' || ch == 'u' || + ch == 's' || ch == 't'; + })) { + ciphered = 0; + std::string to_cipher = word; + while (!to_cipher.empty()) { + *ciphered *= 10; + switch (to_cipher.back()) { + case 'w': { + *ciphered += 1; + break; + } + case 'a': { + *ciphered += 2; + break; + } + case 'n': { + *ciphered += 3; + break; + } + case 'd': { + *ciphered += 4; + break; + } + case 'e': { + *ciphered += 5; + break; + } + case 'r': { + *ciphered += 6; + break; + } + case 'l': { + *ciphered += 7; + break; + } + case 'u': { + *ciphered += 8; + break; + } + case 's': { + *ciphered += 9; + break; + } + } + to_cipher.pop_back(); + } + wanderlust_[*ciphered] = form_id; + } + forms_.push_back({.id = form_id, .text = word, .ciphered = ciphered}); std::string sortedText = word; std::sort(sortedText.begin(), sortedText.end()); -- cgit 1.4.1