diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-02-15 11:43:32 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-02-15 11:43:32 -0500 |
commit | 9a2ce8a4b91511bc99558e99956cccc6e0e38bc0 (patch) | |
tree | a604e3afef5155b29445b78b5c839235969a334d /lingo.cpp | |
parent | 8c311162beb090bf09f8d0bc220646ed8697690a (diff) | |
download | lingo-9a2ce8a4b91511bc99558e99956cccc6e0e38bc0.tar.gz lingo-9a2ce8a4b91511bc99558e99956cccc6e0e38bc0.tar.bz2 lingo-9a2ce8a4b91511bc99558e99956cccc6e0e38bc0.zip |
Added profane filter
Diffstat (limited to 'lingo.cpp')
-rw-r--r-- | lingo.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lingo.cpp b/lingo.cpp index b461ad8..c4d9b6c 100644 --- a/lingo.cpp +++ b/lingo.cpp | |||
@@ -428,6 +428,15 @@ public: | |||
428 | scoreboard_endpoint_ = config["scoreboard_endpoint"].as<std::string>(); | 428 | scoreboard_endpoint_ = config["scoreboard_endpoint"].as<std::string>(); |
429 | scoreboard_secret_code_ = config["scoreboard_secret_code"].as<std::string>(); | 429 | scoreboard_secret_code_ = config["scoreboard_secret_code"].as<std::string>(); |
430 | 430 | ||
431 | std::string profaneFilename = config["profane"].as<std::string>(); | ||
432 | { | ||
433 | std::ifstream profaneFile(profaneFilename); | ||
434 | std::string line; | ||
435 | while (std::getline(profaneFile, line)) { | ||
436 | profane_.insert(line); | ||
437 | } | ||
438 | } | ||
439 | |||
431 | for (;;) | 440 | for (;;) |
432 | { | 441 | { |
433 | sendPuzzle(channel); | 442 | sendPuzzle(channel); |
@@ -479,6 +488,20 @@ private: | |||
479 | return false; | 488 | return false; |
480 | } | 489 | } |
481 | 490 | ||
491 | bool isProfane(const verbly::form& clue) const { | ||
492 | if (clue.getComplexity() == 1) { | ||
493 | return profane_.count(clue.getText()); | ||
494 | } else { | ||
495 | auto words = hatkirby::split<std::vector<std::string>>(clue.getText(), " "); | ||
496 | for (const std::string& word : words) { | ||
497 | if (profane_.count(word)) { | ||
498 | return true; | ||
499 | } | ||
500 | } | ||
501 | return false; | ||
502 | } | ||
503 | } | ||
504 | |||
482 | void generatePuzzle() | 505 | void generatePuzzle() |
483 | { | 506 | { |
484 | std::cout << "Generating puzzle..." << std::endl; | 507 | std::cout << "Generating puzzle..." << std::endl; |
@@ -637,6 +660,11 @@ private: | |||
637 | 660 | ||
638 | std::cout << "Solution decided: " << solution.getText() << std::endl; | 661 | std::cout << "Solution decided: " << solution.getText() << std::endl; |
639 | 662 | ||
663 | if (isProfane(solution)) { | ||
664 | std::cout << "Solution is profane" << std::endl; | ||
665 | continue; | ||
666 | } | ||
667 | |||
640 | std::array<std::optional<std::string>, kHeightCount> chosenHints; | 668 | std::array<std::optional<std::string>, kHeightCount> chosenHints; |
641 | 669 | ||
642 | bool made_puzzle = false; | 670 | bool made_puzzle = false; |
@@ -645,6 +673,7 @@ private: | |||
645 | verbly::filter admissible = cleanFilter && (verbly::form::proper == false) && (verbly::form::length == static_cast<int>(solution.getText().size())); | 673 | verbly::filter admissible = cleanFilter && (verbly::form::proper == false) && (verbly::form::length == static_cast<int>(solution.getText().size())); |
646 | std::ostringstream msg_stream; | 674 | std::ostringstream msg_stream; |
647 | bool trivial = false; | 675 | bool trivial = false; |
676 | bool profane = false; | ||
648 | for (int i=0; i<static_cast<int>(kHeightCount); i++) { | 677 | for (int i=0; i<static_cast<int>(kHeightCount); i++) { |
649 | Height height = static_cast<Height>(i); | 678 | Height height = static_cast<Height>(i); |
650 | std::optional<Colour>& colour = parts[i]; | 679 | std::optional<Colour>& colour = parts[i]; |
@@ -663,6 +692,9 @@ private: | |||
663 | trivial = true; | 692 | trivial = true; |
664 | break; | 693 | break; |
665 | } | 694 | } |
695 | if (isProfane(questionPart)) { | ||
696 | profane = true; | ||
697 | } | ||
666 | 698 | ||
667 | admissible &= makeHintFilter(questionPart, height, *colour, kTowardSolution); | 699 | admissible &= makeHintFilter(questionPart, height, *colour, kTowardSolution); |
668 | } | 700 | } |
@@ -674,6 +706,11 @@ private: | |||
674 | std::cout << "Puzzle is trivial." << std::endl; | 706 | std::cout << "Puzzle is trivial." << std::endl; |
675 | continue; | 707 | continue; |
676 | } | 708 | } |
709 | if (profane) | ||
710 | { | ||
711 | std::cout << "Puzzle is profane." << std::endl; | ||
712 | continue; | ||
713 | } | ||
677 | 714 | ||
678 | if (parts[static_cast<int>(kTop)].has_value() | 715 | if (parts[static_cast<int>(kTop)].has_value() |
679 | && !parts[static_cast<int>(kMiddle)].has_value() | 716 | && !parts[static_cast<int>(kMiddle)].has_value() |
@@ -933,6 +970,7 @@ private: | |||
933 | std::string scoreboard_secret_code_; | 970 | std::string scoreboard_secret_code_; |
934 | std::unique_ptr<wanderlust> wanderlust_; | 971 | std::unique_ptr<wanderlust> wanderlust_; |
935 | std::string fontpath_; | 972 | std::string fontpath_; |
973 | std::set<std::string> profane_; | ||
936 | 974 | ||
937 | std::map<uint64_t, std::string> answer_by_message_; | 975 | std::map<uint64_t, std::string> answer_by_message_; |
938 | std::set<uint64_t> solved_puzzles_; | 976 | std::set<uint64_t> solved_puzzles_; |