summary refs log tree commit diff stats
path: root/generator
diff options
context:
space:
mode:
Diffstat (limited to 'generator')
-rw-r--r--generator/generator.cpp94
-rw-r--r--generator/generator.h3
2 files changed, 96 insertions, 1 deletions
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() {
857 } 857 }
858 } 858 }
859 859
860 // Orange addition
861 std::vector<std::string> orange_addition;
862 {
863 hatkirby::progress ppgs("Generating orange addition puzzles...",
864 wanderlust_.size());
865
866 for (const auto& [cipher, form_id] : wanderlust_) {
867 for (const auto& [cipher2, form_id2] : wanderlust_) {
868 if (cipher2 >= cipher) {
869 break;
870 }
871 if (wanderlust_.count(cipher - cipher2)) {
872 orange_addition.push_back(fmt::format(
873 "[{},{},{}]", form_id2, wanderlust_[cipher - cipher2], form_id));
874 }
875 }
876 }
877 }
878
860 // Count up all of the generated puzzles. 879 // Count up all of the generated puzzles.
861 int total_puzzles = 0; 880 int total_puzzles = 0;
862 int reusable_words = 0; 881 int reusable_words = 0;
@@ -916,6 +935,27 @@ void generator::run() {
916 std::ofstream output_file(outputPath_); 935 std::ofstream output_file(outputPath_);
917 output_file << "extends Node\n\nvar forms = [" 936 output_file << "extends Node\n\nvar forms = ["
918 << hatkirby::implode(form_entry, ",") << "]" << std::endl; 937 << hatkirby::implode(form_entry, ",") << "]" << std::endl;
938
939 std::vector<std::string> painting_entries;
940 {
941 std::list<std::string> paintings(readFile(datadirPath_ / "paintings.txt"));
942 for (const std::string& line : paintings) {
943 auto parts = hatkirby::split<std::vector<std::string>>(line, ",");
944 painting_entries.push_back(
945 fmt::format("[\"{}\",\"{}\"]", parts[0], parts[1]));
946 }
947 }
948 output_file << "var paintings = [" << hatkirby::implode(painting_entries, ",")
949 << "]" << std::endl;
950
951 std::vector<std::string> cipher_lines;
952 for (const auto& [cipher, form_id] : wanderlust_) {
953 cipher_lines.push_back(std::to_string(form_id));
954 }
955 output_file << "var wanderlust = [" << hatkirby::implode(cipher_lines, ",")
956 << "]" << std::endl;
957 output_file << "var addition = [" << hatkirby::implode(orange_addition, ",")
958 << "]" << std::endl;
919} 959}
920 960
921size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) { 961size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) {
@@ -996,7 +1036,59 @@ size_t generator::LookupOrCreateForm(const std::string& word) {
996 } else { 1036 } else {
997 size_t form_id = forms_.size(); 1037 size_t form_id = forms_.size();
998 form_by_text_[word] = form_id; 1038 form_by_text_[word] = form_id;
999 forms_.push_back({.id = form_id, .text = word}); 1039 std::optional<int> ciphered;
1040 if (std::all_of(word.begin(), word.end(), [](char ch) {
1041 return ch == 'w' || ch == 'a' || ch == 'n' || ch == 'd' ||
1042 ch == 'e' || ch == 'r' || ch == 'l' || ch == 'u' ||
1043 ch == 's' || ch == 't';
1044 })) {
1045 ciphered = 0;
1046 std::string to_cipher = word;
1047 while (!to_cipher.empty()) {
1048 *ciphered *= 10;
1049 switch (to_cipher.back()) {
1050 case 'w': {
1051 *ciphered += 1;
1052 break;
1053 }
1054 case 'a': {
1055 *ciphered += 2;
1056 break;
1057 }
1058 case 'n': {
1059 *ciphered += 3;
1060 break;
1061 }
1062 case 'd': {
1063 *ciphered += 4;
1064 break;
1065 }
1066 case 'e': {
1067 *ciphered += 5;
1068 break;
1069 }
1070 case 'r': {
1071 *ciphered += 6;
1072 break;
1073 }
1074 case 'l': {
1075 *ciphered += 7;
1076 break;
1077 }
1078 case 'u': {
1079 *ciphered += 8;
1080 break;
1081 }
1082 case 's': {
1083 *ciphered += 9;
1084 break;
1085 }
1086 }
1087 to_cipher.pop_back();
1088 }
1089 wanderlust_[*ciphered] = form_id;
1090 }
1091 forms_.push_back({.id = form_id, .text = word, .ciphered = ciphered});
1000 1092
1001 std::string sortedText = word; 1093 std::string sortedText = word;
1002 std::sort(sortedText.begin(), sortedText.end()); 1094 std::sort(sortedText.begin(), sortedText.end());
diff --git a/generator/generator.h b/generator/generator.h index f89bab9..ea30bd9 100644 --- a/generator/generator.h +++ b/generator/generator.h
@@ -92,6 +92,7 @@ class generator {
92 std::vector<size_t> pronunciation_ids; 92 std::vector<size_t> pronunciation_ids;
93 std::optional<size_t> anagram_set_id; 93 std::optional<size_t> anagram_set_id;
94 std::optional<size_t> reverse_form_id; 94 std::optional<size_t> reverse_form_id;
95 std::optional<int> ciphered;
95 96
96 std::unordered_map<PuzzleType, std::set<size_t>> puzzles; 97 std::unordered_map<PuzzleType, std::set<size_t>> puzzles;
97 }; 98 };
@@ -124,6 +125,8 @@ class generator {
124 125
125 std::vector<std::vector<size_t>> synsets_; 126 std::vector<std::vector<size_t>> synsets_;
126 std::unordered_map<int, size_t> synset_by_wnid_; 127 std::unordered_map<int, size_t> synset_by_wnid_;
128
129 std::map<int, size_t> wanderlust_;
127}; 130};
128 131
129#endif /* end of include guard: GENERATOR_H_D5C6A724 */ \ No newline at end of file 132#endif /* end of include guard: GENERATOR_H_D5C6A724 */ \ No newline at end of file