summary refs log tree commit diff stats
path: root/generator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'generator.cpp')
-rw-r--r--generator.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/generator.cpp b/generator.cpp index c4dd76f..6b6c1be 100644 --- a/generator.cpp +++ b/generator.cpp
@@ -5,7 +5,7 @@
5#include <cctype> 5#include <cctype>
6#include <hkutil/string.h> 6#include <hkutil/string.h>
7 7
8verbly::filter Generator::MakeHintFilter(verbly::filter subfilter, Height height, Colour colour, FilterDirection filter_direction) 8verbly::filter Generator::MakeHintFilter(verbly::filter subfilter, Height height, Colour colour, FilterDirection filter_direction) const
9{ 9{
10 switch (colour) { 10 switch (colour) {
11 case kWhite: { 11 case kWhite: {
@@ -304,7 +304,7 @@ bool Generator::GenerateSinglePanelImpl(std::string name, Height height, Colour
304 if (questions.size() < 1) return false; 304 if (questions.size() < 1) return false;
305 verbly::form question = questions.front();// questions.at(std::uniform_int_distribution<int>(0, questions.size())(rng_)); 305 verbly::form question = questions.front();// questions.at(std::uniform_int_distribution<int>(0, questions.size())(rng_));
306 306
307 if (IsClueTrivial(height, colour, question, solution)) { 307 if (IsClueTrivial(height, colour, question, solution, options)) {
308 return false; 308 return false;
309 } 309 }
310 if (options.max_len_diff >= 0 && std::abs(static_cast<int>(question.getText().size() - solution.getText().size())) > options.max_len_diff) { 310 if (options.max_len_diff >= 0 && std::abs(static_cast<int>(question.getText().size() - solution.getText().size())) > options.max_len_diff) {
@@ -357,7 +357,7 @@ bool Generator::GenerateDoublePanelImpl(std::string name1, std::string name2, He
357 357
358 //std::shuffle(questions.begin(), questions.end(), rng_); 358 //std::shuffle(questions.begin(), questions.end(), rng_);
359 359
360 if (IsClueTrivial(height, colour, questions[0], solution) || IsClueTrivial(height, colour, questions[1], solution)) { 360 if (IsClueTrivial(height, colour, questions[0], solution, options) || IsClueTrivial(height, colour, questions[1], solution, options)) {
361 return false; 361 return false;
362 } 362 }
363 if (options.max_len_diff >= 0) { 363 if (options.max_len_diff >= 0) {
@@ -395,7 +395,8 @@ bool Generator::GenerateCohintedPanelsImpl(std::string name1, std::string name2,
395 395
396 //std::shuffle(questions.begin(), questions.end(), rng_); 396 //std::shuffle(questions.begin(), questions.end(), rng_);
397 397
398 if (IsClueTrivial(height, colour, question, solutions[0]) || IsClueTrivial(height, colour, question, solutions[1])) { 398 if (IsClueTrivial(height, colour, question, solutions[0], options)
399 || IsClueTrivial(height, colour, question, solutions[1], options)) {
399 return false; 400 return false;
400 } 401 }
401 if (options.max_len_diff >= 0) { 402 if (options.max_len_diff >= 0) {
@@ -428,7 +429,7 @@ bool Generator::GeneratePairedPanelsImpl(std::string name1, std::string name2, H
428 if (questions.size() < 1) return false; 429 if (questions.size() < 1) return false;
429 verbly::form question = questions.front();// questions.at(std::uniform_int_distribution<int>(0, questions.size())(rng_)); 430 verbly::form question = questions.front();// questions.at(std::uniform_int_distribution<int>(0, questions.size())(rng_));
430 431
431 if (IsClueTrivial(height, effectiveColour, question, solution)) { 432 if (IsClueTrivial(height, effectiveColour, question, solution, options)) {
432 return false; 433 return false;
433 } 434 }
434 435
@@ -506,7 +507,7 @@ bool Generator::GeneratePanelStackImpl(std::string top_name, Colour top_colour,
506 if (questions.empty()) return false; 507 if (questions.empty()) return false;
507 top_hint = questions.front().getText(); 508 top_hint = questions.front().getText();
508 509
509 if (IsClueTrivial(kTop, top_colour, questions.front(), solution)) { 510 if (IsClueTrivial(kTop, top_colour, questions.front(), solution, options)) {
510 return false; 511 return false;
511 } 512 }
512 } 513 }
@@ -517,7 +518,7 @@ bool Generator::GeneratePanelStackImpl(std::string top_name, Colour top_colour,
517 if (questions.empty()) return false; 518 if (questions.empty()) return false;
518 middle_hint = questions.front().getText(); 519 middle_hint = questions.front().getText();
519 520
520 if (IsClueTrivial(kMiddle, middle_colour, questions.front(), solution)) { 521 if (IsClueTrivial(kMiddle, middle_colour, questions.front(), solution, options)) {
521 return false; 522 return false;
522 } 523 }
523 } 524 }
@@ -528,7 +529,7 @@ bool Generator::GeneratePanelStackImpl(std::string top_name, Colour top_colour,
528 if (questions.empty()) return false; 529 if (questions.empty()) return false;
529 bottom_hint = questions.front().getText(); 530 bottom_hint = questions.front().getText();
530 531
531 if (IsClueTrivial(kBottom, bottom_colour, questions.front(), solution)) { 532 if (IsClueTrivial(kBottom, bottom_colour, questions.front(), solution, options)) {
532 return false; 533 return false;
533 } 534 }
534 } 535 }
@@ -708,6 +709,7 @@ verbly::filter Generator::GetWordFilter(FilterDirection dir, GenerateOptions opt
708 wordFilter &= (verbly::form::complexity == 2); 709 wordFilter &= (verbly::form::complexity == 2);
709 } else { 710 } else {
710 wordFilter &= (verbly::form::complexity == 1); 711 wordFilter &= (verbly::form::complexity == 1);
712 wordFilter &= (verbly::form::frequency > 2000000);
711 } 713 }
712 } else { 714 } else {
713 wordFilter &= ((verbly::form::complexity > 1) || (verbly::form::frequency > 2000000)); 715 wordFilter &= ((verbly::form::complexity > 1) || (verbly::form::frequency > 2000000));
@@ -720,8 +722,15 @@ bool isDigitWrapper(unsigned char ch) {
720 return std::isdigit(ch); 722 return std::isdigit(ch);
721} 723}
722 724
723bool Generator::IsClueTrivial(Height height, Colour colour, const verbly::form& clue, const verbly::form& solution) const 725bool Generator::IsClueTrivial(Height height, Colour colour, const verbly::form& clue, const verbly::form& solution, GenerateOptions options) const
724{ 726{
727 if (!options.allow_top_expansion && height == kTop) {
728 verbly::filter questionFilter = MakeHintFilter(solution, kMiddle, colour, kTowardQuestion) && clue;
729 if (!database_->forms(questionFilter).all().empty()) {
730 return true;
731 }
732 }
733
725 if (height == kTop && colour == kWhite) 734 if (height == kTop && colour == kWhite)
726 { 735 {
727 return !database_->forms((verbly::filter)clue && (verbly::word::synonyms %= solution)).all().empty(); 736 return !database_->forms((verbly::filter)clue && (verbly::word::synonyms %= solution)).all().empty();