diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-12-02 21:38:12 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-12-02 21:38:12 -0500 |
commit | 33f602fd7edfa6f3d53a16e99027e3c81f6d8c9c (patch) | |
tree | 34fcd0ca17341fe8e4bf9e5d244a564af8ca1672 /generator | |
parent | 266f374ae4357acd2c23cd0d7aff4d2c25406f80 (diff) | |
download | lingo-randomizer-33f602fd7edfa6f3d53a16e99027e3c81f6d8c9c.tar.gz lingo-randomizer-33f602fd7edfa6f3d53a16e99027e3c81f6d8c9c.tar.bz2 lingo-randomizer-33f602fd7edfa6f3d53a16e99027e3c81f6d8c9c.zip |
Output, and puzzle reduction
Diffstat (limited to 'generator')
-rw-r--r-- | generator/CMakeLists.txt | 6 | ||||
-rw-r--r-- | generator/generator.cpp | 105 | ||||
m--------- | generator/vendor/fmt | 0 |
3 files changed, 96 insertions, 15 deletions
diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 343e5cb..3b66720 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt | |||
@@ -1,9 +1,11 @@ | |||
1 | cmake_minimum_required (VERSION 3.1) | 1 | cmake_minimum_required (VERSION 3.1) |
2 | project (generator) | 2 | project (generator) |
3 | 3 | ||
4 | include_directories(../vendor/hkutil) | 4 | add_subdirectory(vendor/fmt) |
5 | |||
6 | include_directories(../vendor/hkutil vendor/fmt/include) | ||
5 | 7 | ||
6 | add_executable(generator generator.cpp main.cpp) | 8 | add_executable(generator generator.cpp main.cpp) |
7 | set_property(TARGET generator PROPERTY CXX_STANDARD 17) | 9 | set_property(TARGET generator PROPERTY CXX_STANDARD 17) |
8 | set_property(TARGET generator PROPERTY CXX_STANDARD_REQUIRED ON) | 10 | set_property(TARGET generator PROPERTY CXX_STANDARD_REQUIRED ON) |
9 | #target_link_libraries(generator ${sqlite3_LIBRARIES} ${LIBXML2_LIBRARIES}) | 11 | target_link_libraries(generator fmt) |
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 @@ | |||
1 | #include "generator.h" | 1 | #include "generator.h" |
2 | 2 | ||
3 | #include <fmt/core.h> | ||
3 | #include <hkutil/progress.h> | 4 | #include <hkutil/progress.h> |
4 | #include <hkutil/string.h> | 5 | #include <hkutil/string.h> |
5 | 6 | ||
@@ -572,8 +573,25 @@ void generator::run() { | |||
572 | for (size_t mero_form_id : merophone.form_ids) { | 573 | for (size_t mero_form_id : merophone.form_ids) { |
573 | Form& mero_form = forms_.at(mero_form_id); | 574 | Form& mero_form = forms_.at(mero_form_id); |
574 | 575 | ||
575 | holo_form.puzzles[kBlueTop].insert(mero_form_id); | 576 | bool word_overlap = false; |
576 | mero_form.puzzles[kRedTop].insert(holo_form_id); | 577 | for (size_t holo_word_id : holo_form.word_ids) { |
578 | for (size_t mero_word_id : mero_form.word_ids) { | ||
579 | if (holo_word_id == mero_word_id) { | ||
580 | word_overlap = true; | ||
581 | break; | ||
582 | } | ||
583 | } | ||
584 | if (word_overlap) { | ||
585 | break; | ||
586 | } | ||
587 | } | ||
588 | |||
589 | if (!word_overlap) { | ||
590 | if (holo_form.text.size() <= mero_form.text.size() + 5) { | ||
591 | holo_form.puzzles[kBlueTop].insert(mero_form_id); | ||
592 | } | ||
593 | mero_form.puzzles[kRedTop].insert(holo_form_id); | ||
594 | } | ||
577 | } | 595 | } |
578 | } | 596 | } |
579 | } | 597 | } |
@@ -609,15 +627,32 @@ void generator::run() { | |||
609 | 627 | ||
610 | Form& merograph = forms_.at(form_by_text_.at(substr)); | 628 | Form& merograph = forms_.at(form_by_text_.at(substr)); |
611 | 629 | ||
612 | holograph.puzzles[kBlueMiddle].insert(merograph.id); | 630 | bool word_overlap = false; |
613 | merograph.puzzles[kRedMiddle].insert(form_id); | 631 | for (size_t holo_word_id : holograph.word_ids) { |
632 | for (size_t mero_word_id : merograph.word_ids) { | ||
633 | if (holo_word_id == mero_word_id) { | ||
634 | word_overlap = true; | ||
635 | break; | ||
636 | } | ||
637 | } | ||
638 | if (word_overlap) { | ||
639 | break; | ||
640 | } | ||
641 | } | ||
614 | 642 | ||
615 | if (i == 0) { | 643 | if (!word_overlap) { |
616 | left_shorter_by_longer[form_id].insert(merograph.id); | 644 | if (holograph.text.size() <= merograph.text.size() + 4) { |
617 | left_longer_by_shorter[merograph.id].insert(form_id); | 645 | holograph.puzzles[kBlueMiddle].insert(merograph.id); |
618 | } else if (i + l == text.size()) { | 646 | |
619 | right_shorter_by_longer[form_id].insert(merograph.id); | 647 | if (i == 0) { |
620 | right_longer_by_shorter[merograph.id].insert(form_id); | 648 | left_shorter_by_longer[form_id].insert(merograph.id); |
649 | left_longer_by_shorter[merograph.id].insert(form_id); | ||
650 | } else if (i + l == text.size()) { | ||
651 | right_shorter_by_longer[form_id].insert(merograph.id); | ||
652 | right_longer_by_shorter[merograph.id].insert(form_id); | ||
653 | } | ||
654 | } | ||
655 | merograph.puzzles[kRedMiddle].insert(form_id); | ||
621 | } | 656 | } |
622 | } | 657 | } |
623 | } | 658 | } |
@@ -636,9 +671,15 @@ void generator::run() { | |||
636 | 671 | ||
637 | Form& holograph = forms_.at(holograph_id); | 672 | Form& holograph = forms_.at(holograph_id); |
638 | for (size_t merograph_id : merograph_ids) { | 673 | for (size_t merograph_id : merograph_ids) { |
674 | const Form& merograph = forms_.at(merograph_id); | ||
639 | for (size_t other_id : left_longer_by_shorter[merograph_id]) { | 675 | for (size_t other_id : left_longer_by_shorter[merograph_id]) { |
640 | if (other_id != holograph_id) { | 676 | if (other_id != holograph_id) { |
641 | holograph.puzzles[kPurpleMiddle].insert(other_id); | 677 | const Form& other_form = forms_.at(other_id); |
678 | |||
679 | if (holograph.text[merograph.text.size()] != | ||
680 | other_form.text[merograph.text.size()]) { | ||
681 | holograph.puzzles[kPurpleMiddle].insert(other_id); | ||
682 | } | ||
642 | } | 683 | } |
643 | } | 684 | } |
644 | } | 685 | } |
@@ -649,9 +690,17 @@ void generator::run() { | |||
649 | 690 | ||
650 | Form& holograph = forms_.at(holograph_id); | 691 | Form& holograph = forms_.at(holograph_id); |
651 | for (size_t merograph_id : merograph_ids) { | 692 | for (size_t merograph_id : merograph_ids) { |
693 | const Form& merograph = forms_.at(merograph_id); | ||
652 | for (size_t other_id : right_longer_by_shorter[merograph_id]) { | 694 | for (size_t other_id : right_longer_by_shorter[merograph_id]) { |
653 | if (other_id != holograph_id) { | 695 | if (other_id != holograph_id) { |
654 | holograph.puzzles[kPurpleMiddle].insert(other_id); | 696 | const Form& other_form = forms_.at(other_id); |
697 | |||
698 | if (holograph | ||
699 | .text[holograph.text.size() - merograph.text.size() - 1] != | ||
700 | other_form | ||
701 | .text[other_form.text.size() - merograph.text.size() - 1]) { | ||
702 | holograph.puzzles[kPurpleMiddle].insert(other_id); | ||
703 | } | ||
655 | } | 704 | } |
656 | } | 705 | } |
657 | } | 706 | } |
@@ -780,7 +829,12 @@ void generator::run() { | |||
780 | for (size_t f_id2 : p2.form_ids) { | 829 | for (size_t f_id2 : p2.form_ids) { |
781 | if (f_id1 != f_id2) { | 830 | if (f_id1 != f_id2) { |
782 | Form& form1 = forms_.at(f_id1); | 831 | Form& form1 = forms_.at(f_id1); |
783 | form1.puzzles[kPurpleTop].insert(f_id2); | 832 | const Form& form2 = forms_.at(f_id2); |
833 | |||
834 | if (std::abs(static_cast<int>(form1.text.size()) - | ||
835 | static_cast<int>(form2.text.size())) <= 4) { | ||
836 | form1.puzzles[kPurpleTop].insert(f_id2); | ||
837 | } | ||
784 | } | 838 | } |
785 | } | 839 | } |
786 | } | 840 | } |
@@ -824,6 +878,31 @@ void generator::run() { | |||
824 | std::cout << "Purple tops: " << per_puzzle_type[kPurpleTop] << std::endl; | 878 | std::cout << "Purple tops: " << per_puzzle_type[kPurpleTop] << std::endl; |
825 | std::cout << "Purple middles: " << per_puzzle_type[kPurpleMiddle] | 879 | std::cout << "Purple middles: " << per_puzzle_type[kPurpleMiddle] |
826 | << std::endl; | 880 | << std::endl; |
881 | |||
882 | std::vector<std::string> form_entry; | ||
883 | form_entry.reserve(forms_.size()); | ||
884 | for (const Form& form : forms_) { | ||
885 | if (form.puzzles.empty()) { | ||
886 | form_entry.push_back(fmt::format("\"{}\"", form.text)); | ||
887 | } else { | ||
888 | std::vector<std::string> entry_per_type; | ||
889 | for (const auto& [puzzle_type, puzzles] : form.puzzles) { | ||
890 | std::vector<std::string> entry_per_puzzle; | ||
891 | for (size_t puzzle : puzzles) { | ||
892 | entry_per_puzzle.push_back(std::to_string(puzzle)); | ||
893 | } | ||
894 | entry_per_type.push_back( | ||
895 | fmt::format("{}:[{}]", static_cast<int>(puzzle_type), | ||
896 | hatkirby::implode(entry_per_puzzle, ","))); | ||
897 | } | ||
898 | form_entry.push_back(fmt::format("[\"{}\",{{{}}}]", form.text, | ||
899 | hatkirby::implode(entry_per_type, ","))); | ||
900 | } | ||
901 | } | ||
902 | |||
903 | std::ofstream output_file(outputPath_); | ||
904 | output_file << "extends Node\n\nvar forms = [" | ||
905 | << hatkirby::implode(form_entry, ",") << "]" << std::endl; | ||
827 | } | 906 | } |
828 | 907 | ||
829 | size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) { | 908 | size_t generator::LookupOrCreatePronunciation(const std::string& phonemes) { |
diff --git a/generator/vendor/fmt b/generator/vendor/fmt new file mode 160000 | |||
Subproject f5750892436a667fe622e5ecc8a02c15a5d9bc8 | |||