diff options
-rw-r--r-- | data/profane.txt | 4 | ||||
-rw-r--r-- | generator/generator.cpp | 126 | ||||
-rw-r--r-- | generator/generator.h | 8 |
3 files changed, 137 insertions, 1 deletions
diff --git a/data/profane.txt b/data/profane.txt index b07b823..297b278 100644 --- a/data/profane.txt +++ b/data/profane.txt | |||
@@ -1160,4 +1160,6 @@ xxx | |||
1160 | yankee | 1160 | yankee |
1161 | yellowman | 1161 | yellowman |
1162 | zigabo | 1162 | zigabo |
1163 | zipperhead \ No newline at end of file | 1163 | zipperhead |
1164 | ass | ||
1165 | arouse \ No newline at end of file | ||
diff --git a/generator/generator.cpp b/generator/generator.cpp index 435a63b..0017b24 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp | |||
@@ -882,6 +882,27 @@ void generator::run() { | |||
882 | } | 882 | } |
883 | } | 883 | } |
884 | 884 | ||
885 | FindComboPuzzles("Generating purple middle red middle combo puzzles...", | ||
886 | kPurpleMiddle, kRedMiddle); | ||
887 | FindComboPuzzles("Generating purple top purple top combo puzzles...", | ||
888 | kPurpleTop, kPurpleTop); | ||
889 | FindComboPuzzles("Generating black middle black bottom combo puzzles...", | ||
890 | kBlackMiddle, kBlackBottom); | ||
891 | FindComboPuzzles("Generating white bottom purple middle combo puzzles...", | ||
892 | kWhiteBottom, kPurpleMiddle); | ||
893 | FindComboPuzzles("Generating black bottom white bottom combo puzzles...", | ||
894 | kBlackBottom, kWhiteBottom); | ||
895 | FindComboPuzzles("Generating blue middle red middle combo puzzles...", | ||
896 | kBlueMiddle, kRedMiddle); | ||
897 | FindComboPuzzles("Generating white bottom white bottom combo puzzles...", | ||
898 | kWhiteBottom, kWhiteBottom); | ||
899 | FindComboPuzzles("Generating blue middle yellow middle combo puzzles...", | ||
900 | kBlueMiddle, kYellowMiddle); | ||
901 | FindComboPuzzles("Generating black bottom blue middle combo puzzles...", | ||
902 | kBlackBottom, kBlueMiddle); | ||
903 | FindComboPuzzles("Generating yellow top yellow middle combo puzzles...", | ||
904 | kYellowTop, kYellowMiddle); | ||
905 | |||
885 | // Count up all of the generated puzzles. | 906 | // Count up all of the generated puzzles. |
886 | int total_puzzles = 0; | 907 | int total_puzzles = 0; |
887 | int reusable_words = 0; | 908 | int reusable_words = 0; |
@@ -916,6 +937,26 @@ void generator::run() { | |||
916 | std::cout << "Purple tops: " << per_puzzle_type[kPurpleTop] << std::endl; | 937 | std::cout << "Purple tops: " << per_puzzle_type[kPurpleTop] << std::endl; |
917 | std::cout << "Purple middles: " << per_puzzle_type[kPurpleMiddle] | 938 | std::cout << "Purple middles: " << per_puzzle_type[kPurpleMiddle] |
918 | << std::endl; | 939 | << std::endl; |
940 | std::cout << "Purple middle red middle combos: " | ||
941 | << combos_[kPurpleMiddle][kRedMiddle].size() << std::endl; | ||
942 | std::cout << "Purple top purple top combos: " | ||
943 | << combos_[kPurpleTop][kPurpleTop].size() << std::endl; | ||
944 | std::cout << "Black middle black bottom combos: " | ||
945 | << combos_[kBlackMiddle][kBlackBottom].size() << std::endl; | ||
946 | std::cout << "White bottom purple middle combos: " | ||
947 | << combos_[kWhiteBottom][kPurpleMiddle].size() << std::endl; | ||
948 | std::cout << "Black bottom white bottom combos: " | ||
949 | << combos_[kBlackBottom][kWhiteBottom].size() << std::endl; | ||
950 | std::cout << "Blue middle red middle combos: " | ||
951 | << combos_[kBlueMiddle][kRedMiddle].size() << std::endl; | ||
952 | std::cout << "White bottom white bottom combos: " | ||
953 | << combos_[kWhiteBottom][kWhiteBottom].size() << std::endl; | ||
954 | std::cout << "Blue middle yellow middle combos: " | ||
955 | << combos_[kBlueMiddle][kYellowMiddle].size() << std::endl; | ||
956 | std::cout << "Black bottom blue middle combos: " | ||
957 | << combos_[kBlackBottom][kBlueMiddle].size() << std::endl; | ||
958 | std::cout << "Yellow top yellow middle combos: " | ||
959 | << combos_[kYellowTop][kYellowMiddle].size() << std::endl; | ||
919 | 960 | ||
920 | std::vector<std::string> form_entry; | 961 | std::vector<std::string> form_entry; |
921 | form_entry.reserve(forms_.size()); | 962 | form_entry.reserve(forms_.size()); |
@@ -962,6 +1003,38 @@ void generator::run() { | |||
962 | << "]" << std::endl; | 1003 | << "]" << std::endl; |
963 | output_file << "var addition = [" << hatkirby::implode(orange_addition, ",") | 1004 | output_file << "var addition = [" << hatkirby::implode(orange_addition, ",") |
964 | << "]" << std::endl; | 1005 | << "]" << std::endl; |
1006 | |||
1007 | std::vector<std::string> walls_entries; | ||
1008 | { | ||
1009 | std::list<std::string> walls(readFile(datadirPath_ / "walls.txt")); | ||
1010 | for (const std::string& line : walls) { | ||
1011 | auto parts = hatkirby::split<std::vector<std::string>>(line, ","); | ||
1012 | walls_entries.push_back( | ||
1013 | fmt::format("[\"{}\",\"{}\"]", parts[0], parts[1])); | ||
1014 | } | ||
1015 | } | ||
1016 | output_file << "var walls_puzzles = [" | ||
1017 | << hatkirby::implode(walls_entries, ",") << "]" << std::endl; | ||
1018 | |||
1019 | std::vector<std::string> combo_entries; | ||
1020 | for (const auto& [left_type, left_join] : combos_) { | ||
1021 | std::vector<std::string> left_entries; | ||
1022 | for (const auto& [right_type, choices] : left_join) { | ||
1023 | std::vector<std::string> choice_entries; | ||
1024 | for (const auto& [hint1, hint2, answer] : choices) { | ||
1025 | choice_entries.push_back( | ||
1026 | fmt::format("[{},{},{}]", hint1, hint2, answer)); | ||
1027 | } | ||
1028 | left_entries.push_back( | ||
1029 | fmt::format("{}:[{}]", static_cast<int>(right_type), | ||
1030 | hatkirby::implode(choice_entries, ","))); | ||
1031 | } | ||
1032 | combo_entries.push_back(fmt::format("{}:{{{}}}]", | ||
1033 | static_cast<int>(left_type), | ||
1034 | hatkirby::implode(left_entries, ","))); | ||
1035 | } | ||
1036 | output_file << "var combos = {" << hatkirby::implode(combo_entries, ",") | ||
1037 | << "}" << std::endl; | ||
965 | } | 1038 | } |
966 | 1039 | ||
967 | size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) { | 1040 | size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) { |
@@ -1111,6 +1184,7 @@ size_t generator::LookupOrCreateWord(const std::string& word) { | |||
1111 | size_t form_id = LookupOrCreateForm(word); | 1184 | size_t form_id = LookupOrCreateForm(word); |
1112 | words_.push_back({.id = word_id, .base_form_id = form_id}); | 1185 | words_.push_back({.id = word_id, .base_form_id = form_id}); |
1113 | AddFormToWord(form_id, word_id); | 1186 | AddFormToWord(form_id, word_id); |
1187 | forms_[form_id].is_base_form = true; | ||
1114 | return word_id; | 1188 | return word_id; |
1115 | } | 1189 | } |
1116 | 1190 | ||
@@ -1163,3 +1237,55 @@ void generator::AddPronunciationToAnaphoneSet( | |||
1163 | pronunciations_[pronunciation_id].anaphone_set_id = anaphone_set_id; | 1237 | pronunciations_[pronunciation_id].anaphone_set_id = anaphone_set_id; |
1164 | } | 1238 | } |
1165 | } | 1239 | } |
1240 | |||
1241 | void generator::FindComboPuzzles(std::string text, PuzzleType left_type, | ||
1242 | PuzzleType right_type) { | ||
1243 | hatkirby::progress ppgs(text, forms_.size()); | ||
1244 | |||
1245 | for (Form& left_form : forms_) { | ||
1246 | ppgs.update(); | ||
1247 | |||
1248 | if (left_form.text.size() < 3 || !left_form.puzzles.count(left_type)) | ||
1249 | continue; | ||
1250 | if (left_type == kWhiteBottom && left_form.puzzles[left_type].size() > 3) | ||
1251 | continue; | ||
1252 | |||
1253 | for (Form& right_form : forms_) { | ||
1254 | if (right_type == kWhiteBottom && | ||
1255 | right_form.puzzles[right_type].size() > 3) | ||
1256 | continue; | ||
1257 | if (right_form.text.size() >= 3 && right_form.puzzles.count(right_type) && | ||
1258 | form_by_text_.count(left_form.text + right_form.text)) { | ||
1259 | for (size_t left_hint_id : left_form.puzzles[left_type]) { | ||
1260 | Form& left_hint = forms_[left_hint_id]; | ||
1261 | for (size_t right_hint_id : right_form.puzzles[right_type]) { | ||
1262 | Form& right_hint = forms_[right_hint_id]; | ||
1263 | |||
1264 | if (left_hint.text.size() + right_hint.text.size() > 15) continue; | ||
1265 | |||
1266 | if (left_type == kPurpleMiddle && | ||
1267 | left_hint.text.size() != left_form.text.size()) | ||
1268 | continue; | ||
1269 | if (right_type == kPurpleMiddle && | ||
1270 | right_hint.text.size() != right_form.text.size()) | ||
1271 | continue; | ||
1272 | if (right_type == kRedMiddle && | ||
1273 | right_hint.text.size() - right_form.text.size() > 3) | ||
1274 | continue; | ||
1275 | |||
1276 | if (form_by_text_.count(left_hint.text + right_hint.text)) { | ||
1277 | combos_[left_type][right_type].emplace_back( | ||
1278 | form_by_text_[left_hint.text + right_hint.text], -1, | ||
1279 | form_by_text_[left_form.text + right_form.text]); | ||
1280 | } else if (left_hint.is_base_form && right_hint.is_base_form && | ||
1281 | !(left_type == kPurpleTop && right_type == kPurpleTop)) { | ||
1282 | combos_[left_type][right_type].emplace_back( | ||
1283 | left_hint_id, right_hint_id, | ||
1284 | form_by_text_[left_form.text + right_form.text]); | ||
1285 | } | ||
1286 | } | ||
1287 | } | ||
1288 | } | ||
1289 | } | ||
1290 | } | ||
1291 | } | ||
diff --git a/generator/generator.h b/generator/generator.h index ea30bd9..cf304ea 100644 --- a/generator/generator.h +++ b/generator/generator.h | |||
@@ -61,6 +61,9 @@ class generator { | |||
61 | void AddPronunciationToAnaphoneSet(size_t pronunciation_id, | 61 | void AddPronunciationToAnaphoneSet(size_t pronunciation_id, |
62 | const std::string& sorted_phonemes); | 62 | const std::string& sorted_phonemes); |
63 | 63 | ||
64 | void FindComboPuzzles(std::string text, PuzzleType left_type, | ||
65 | PuzzleType right_type); | ||
66 | |||
64 | // Input | 67 | // Input |
65 | 68 | ||
66 | std::string agidPath_; | 69 | std::string agidPath_; |
@@ -88,6 +91,7 @@ class generator { | |||
88 | struct Form { | 91 | struct Form { |
89 | size_t id; | 92 | size_t id; |
90 | std::string text; | 93 | std::string text; |
94 | bool is_base_form = false; | ||
91 | std::vector<size_t> word_ids; | 95 | std::vector<size_t> word_ids; |
92 | std::vector<size_t> pronunciation_ids; | 96 | std::vector<size_t> pronunciation_ids; |
93 | std::optional<size_t> anagram_set_id; | 97 | std::optional<size_t> anagram_set_id; |
@@ -127,6 +131,10 @@ class generator { | |||
127 | std::unordered_map<int, size_t> synset_by_wnid_; | 131 | std::unordered_map<int, size_t> synset_by_wnid_; |
128 | 132 | ||
129 | std::map<int, size_t> wanderlust_; | 133 | std::map<int, size_t> wanderlust_; |
134 | |||
135 | std::map<PuzzleType, | ||
136 | std::map<PuzzleType, std::vector<std::tuple<int, int, int>>>> | ||
137 | combos_; | ||
130 | }; | 138 | }; |
131 | 139 | ||
132 | #endif /* end of include guard: GENERATOR_H_D5C6A724 */ \ No newline at end of file | 140 | #endif /* end of include guard: GENERATOR_H_D5C6A724 */ \ No newline at end of file |