summary refs log tree commit diff stats
path: root/generator/generator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'generator/generator.cpp')
-rw-r--r--generator/generator.cpp126
1 files changed, 126 insertions, 0 deletions
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
967size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) { 1040size_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
1241void 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}